github.com/khulnasoft/cli@v0.0.0-20240402070845-01bcad7beefa/cli/trust/trust_test.go (about) 1 package trust 2 3 import ( 4 "testing" 5 6 "github.com/distribution/reference" 7 "github.com/opencontainers/go-digest" 8 "github.com/theupdateframework/notary/client" 9 "github.com/theupdateframework/notary/passphrase" 10 "github.com/theupdateframework/notary/trustpinning" 11 "gotest.tools/v3/assert" 12 is "gotest.tools/v3/assert/cmp" 13 ) 14 15 func TestGetTag(t *testing.T) { 16 ref, err := reference.ParseNormalizedNamed("ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2") 17 assert.NilError(t, err) 18 tag := getTag(ref) 19 assert.Check(t, is.Equal("", tag)) 20 21 ref, err = reference.ParseNormalizedNamed("alpine:latest") 22 assert.NilError(t, err) 23 tag = getTag(ref) 24 assert.Check(t, is.Equal(tag, "latest")) 25 26 ref, err = reference.ParseNormalizedNamed("alpine") 27 assert.NilError(t, err) 28 tag = getTag(ref) 29 assert.Check(t, is.Equal(tag, "")) 30 } 31 32 func TestGetDigest(t *testing.T) { 33 ref, err := reference.ParseNormalizedNamed("ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2") 34 assert.NilError(t, err) 35 d := getDigest(ref) 36 assert.Check(t, is.Equal(digest.Digest("sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2"), d)) 37 38 ref, err = reference.ParseNormalizedNamed("alpine:latest") 39 assert.NilError(t, err) 40 d = getDigest(ref) 41 assert.Check(t, is.Equal(digest.Digest(""), d)) 42 43 ref, err = reference.ParseNormalizedNamed("alpine") 44 assert.NilError(t, err) 45 d = getDigest(ref) 46 assert.Check(t, is.Equal(digest.Digest(""), d)) 47 } 48 49 func TestGetSignableRolesError(t *testing.T) { 50 notaryRepo, err := client.NewFileCachedRepository(t.TempDir(), "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{}) 51 assert.NilError(t, err) 52 target := client.Target{} 53 _, err = GetSignableRoles(notaryRepo, &target) 54 assert.Error(t, err, "client is offline") 55 }