MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / TestNewCredentials

Function TestNewCredentials

internal/ociauth/auth_test.go:24–58  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func TestNewCredentials(t *testing.T) {
25 testCases := []struct {
26 name string
27 repo string
28 username string
29 password string
30 wantErr bool
31 wantServer string
32 }{
33 // invalid
34 {"empty repo", "", "username", "password", true, ""},
35 {"empty username", "repo", "", "password", true, ""},
36 {"empty password", "repo", "username", "", true, ""},
37 {"explicit repo domain with schema", "https://chainloop.dev/oci-repo", "username", "password", true, ""},
38 {"repo with port", "chainloop.dev:port", "username", "password", true, ""},
39
40 // Valid
41 {"explicit repo domain", "chainloop.dev/oci-repo", "username", "password", false, "chainloop.dev"},
42 {"implicit repo domain", "repo", "username", "password", false, "index.docker.io"},
43 }
44
45 for _, tc := range testCases {
46 t.Run(tc.name, func(t *testing.T) {
47 c, err := NewCredentials(tc.repo, tc.username, tc.password)
48 if tc.wantErr {
49 assert.Error(t, err)
50 } else {
51 assert.NoError(t, err)
52 assert.Equal(t, tc.wantServer, c.(*Credentials).server)
53 assert.Equal(t, "username", c.(*Credentials).username)
54 assert.Equal(t, "password", c.(*Credentials).password)
55 }
56 })
57 }
58}

Callers

nothing calls this directly

Calls 3

NewCredentialsFunction · 0.85
ErrorMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected