From e6382db10e01e16d830dd8d999647635f9f92627 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 2 Mar 2025 11:58:18 +0100 Subject: [PATCH] cli/command/image: move trust unit-tests to trust package These tests were not testing functionality that was implemented in the image package. Move them to the trust package, where they belong. Signed-off-by: Sebastiaan van Stijn --- cli/command/image/trust_test.go | 44 --------------------------------- cli/trust/trust_test.go | 37 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 44 deletions(-) delete mode 100644 cli/command/image/trust_test.go diff --git a/cli/command/image/trust_test.go b/cli/command/image/trust_test.go deleted file mode 100644 index 1846ceba37..0000000000 --- a/cli/command/image/trust_test.go +++ /dev/null @@ -1,44 +0,0 @@ -package image - -import ( - "testing" - - "github.com/docker/cli/cli/trust" - registrytypes "github.com/docker/docker/api/types/registry" -) - -func TestENVTrustServer(t *testing.T) { - t.Setenv("DOCKER_CONTENT_TRUST_SERVER", "https://notary-test.example.com:5000") - indexInfo := ®istrytypes.IndexInfo{Name: "testserver"} - output, err := trust.Server(indexInfo) - expectedStr := "https://notary-test.example.com:5000" - if err != nil || output != expectedStr { - t.Fatalf("Expected server to be %s, got %s", expectedStr, output) - } -} - -func TestHTTPENVTrustServer(t *testing.T) { - t.Setenv("DOCKER_CONTENT_TRUST_SERVER", "http://notary-test.example.com:5000") - indexInfo := ®istrytypes.IndexInfo{Name: "testserver"} - _, err := trust.Server(indexInfo) - if err == nil { - t.Fatal("Expected error with invalid scheme") - } -} - -func TestOfficialTrustServer(t *testing.T) { - indexInfo := ®istrytypes.IndexInfo{Name: "testserver", Official: true} - output, err := trust.Server(indexInfo) - if err != nil || output != trust.NotaryServer { - t.Fatalf("Expected server to be %s, got %s", trust.NotaryServer, output) - } -} - -func TestNonOfficialTrustServer(t *testing.T) { - indexInfo := ®istrytypes.IndexInfo{Name: "testserver", Official: false} - output, err := trust.Server(indexInfo) - expectedStr := "https://" + indexInfo.Name - if err != nil || output != expectedStr { - t.Fatalf("Expected server to be %s, got %s", expectedStr, output) - } -} diff --git a/cli/trust/trust_test.go b/cli/trust/trust_test.go index 836ed3892f..336b66e0b8 100644 --- a/cli/trust/trust_test.go +++ b/cli/trust/trust_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/distribution/reference" + registrytypes "github.com/docker/docker/api/types/registry" "github.com/opencontainers/go-digest" "github.com/theupdateframework/notary/client" "github.com/theupdateframework/notary/trustpinning" @@ -52,3 +53,39 @@ func TestGetSignableRolesError(t *testing.T) { const expected = "client is offline" assert.Error(t, err, expected) } + +func TestENVTrustServer(t *testing.T) { + t.Setenv("DOCKER_CONTENT_TRUST_SERVER", "https://notary-test.example.com:5000") + indexInfo := ®istrytypes.IndexInfo{Name: "testserver"} + output, err := Server(indexInfo) + expectedStr := "https://notary-test.example.com:5000" + if err != nil || output != expectedStr { + t.Fatalf("Expected server to be %s, got %s", expectedStr, output) + } +} + +func TestHTTPENVTrustServer(t *testing.T) { + t.Setenv("DOCKER_CONTENT_TRUST_SERVER", "http://notary-test.example.com:5000") + indexInfo := ®istrytypes.IndexInfo{Name: "testserver"} + _, err := Server(indexInfo) + if err == nil { + t.Fatal("Expected error with invalid scheme") + } +} + +func TestOfficialTrustServer(t *testing.T) { + indexInfo := ®istrytypes.IndexInfo{Name: "testserver", Official: true} + output, err := Server(indexInfo) + if err != nil || output != NotaryServer { + t.Fatalf("Expected server to be %s, got %s", NotaryServer, output) + } +} + +func TestNonOfficialTrustServer(t *testing.T) { + indexInfo := ®istrytypes.IndexInfo{Name: "testserver", Official: false} + output, err := Server(indexInfo) + expectedStr := "https://" + indexInfo.Name + if err != nil || output != expectedStr { + t.Fatalf("Expected server to be %s, got %s", expectedStr, output) + } +}