From d95385057fc577bbc46215aeef4e76b639014b99 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 2 Mar 2025 13:22:00 +0100 Subject: [PATCH] cli/command/trust: use gotest.tools in tests Signed-off-by: Sebastiaan van Stijn --- cli/trust/trust_test.go | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/cli/trust/trust_test.go b/cli/trust/trust_test.go index 336b66e0b..18531bf4c 100644 --- a/cli/trust/trust_test.go +++ b/cli/trust/trust_test.go @@ -58,34 +58,31 @@ 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) - } + const expected = "https://notary-test.example.com:5000" + assert.NilError(t, err) + assert.Equal(t, output, expected) } 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") - } + const expected = "valid https URL required for trust server" + assert.ErrorContains(t, err, expected, "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) - } + const expected = NotaryServer + assert.NilError(t, err) + assert.Equal(t, output, expected) } 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) - } + const expected = "https://testserver" + assert.NilError(t, err) + assert.Equal(t, output, expected) }