test: unit tests for pure provider/config/auth packages
First increment toward 90% core-package coverage. Adds Docker-free unit tests taking these packages to full or near-full coverage: - provider/npm, provider/alpine, provider/puppet: 100% - provider/pypi: index generation via a fake FileStore, upload validation, name parsing, classification, rewrite - config: defaults, overrides, DSN, invalid port - auth: basic header with/without credentials Infra-backed packages (database, storage, cache, proxy engine, api handlers, server) still need the testcontainers batch to reach 90%.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"testing"
|
||||
|
||||
"git.unkin.net/unkin/artifactapi/pkg/models"
|
||||
)
|
||||
|
||||
func TestBasicHeaders(t *testing.T) {
|
||||
h := BasicHeaders(models.Remote{Username: "alice", Password: "secret"})
|
||||
got := h.Get("Authorization")
|
||||
want := "Basic " + base64.StdEncoding.EncodeToString([]byte("alice:secret"))
|
||||
if got != want {
|
||||
t.Errorf("Authorization = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBasicHeadersNoUser(t *testing.T) {
|
||||
if h := BasicHeaders(models.Remote{}); h.Get("Authorization") != "" {
|
||||
t.Error("expected no Authorization header without a username")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user