From 810dcd4ed5e7803eb1ad0d314fbefb38dc2a31b4 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 27 May 2023 13:58:02 +0200 Subject: [PATCH] use "tc" for test-cases Mostly for my own sanity; just about every repository we have started to converge to using "tc" as variable name for this, so updating this repository as well to help reduce cognitive load. Signed-off-by: Sebastiaan van Stijn --- osxkeychain/osxkeychain_darwin_test.go | 64 +++++++++++++------------- registryurl/parse_test.go | 20 ++++---- wincred/wincred_windows_test.go | 64 +++++++++++++------------- 3 files changed, 74 insertions(+), 74 deletions(-) diff --git a/osxkeychain/osxkeychain_darwin_test.go b/osxkeychain/osxkeychain_darwin_test.go index b5098ef..48792d6 100644 --- a/osxkeychain/osxkeychain_darwin_test.go +++ b/osxkeychain/osxkeychain_darwin_test.go @@ -75,26 +75,26 @@ func TestOSXKeychainHelperRetrieveAliases(t *testing.T) { helper := Osxkeychain{} defer func() { - for _, te := range tests { - helper.Delete(te.storeURL) + for _, tc := range tests { + helper.Delete(tc.storeURL) } }() // Clean store before testing. - for _, te := range tests { - helper.Delete(te.storeURL) + for _, tc := range tests { + helper.Delete(tc.storeURL) } - for _, te := range tests { - c := &credentials.Credentials{ServerURL: te.storeURL, Username: "hello", Secret: "world"} + for _, tc := range tests { + c := &credentials.Credentials{ServerURL: tc.storeURL, Username: "hello", Secret: "world"} if err := helper.Add(c); err != nil { - t.Errorf("Error: failed to store secret for URL %q: %s", te.storeURL, err) + t.Errorf("Error: failed to store secret for URL %q: %s", tc.storeURL, err) continue } - if _, _, err := helper.Get(te.readURL); err != nil { - t.Errorf("Error: failed to read secret for URL %q using %q", te.storeURL, te.readURL) + if _, _, err := helper.Get(tc.readURL); err != nil { + t.Errorf("Error: failed to read secret for URL %q using %q", tc.storeURL, tc.readURL) } - helper.Delete(te.storeURL) + helper.Delete(tc.storeURL) } } @@ -118,7 +118,7 @@ func TestOSXKeychainHelperRetrieveStrict(t *testing.T) { {"https://foobar.docker.io:1234", "https://foobar.docker.io:5678"}, // non-matching ports TODO is this desired behavior? The other way round does work - //{"https://foobar.docker.io", "https://foobar.docker.io:5678"}, + // {"https://foobar.docker.io", "https://foobar.docker.io:5678"}, // non-matching paths {"https://foobar.docker.io:1234/one/two", "https://foobar.docker.io:1234/five/six"}, @@ -126,26 +126,26 @@ func TestOSXKeychainHelperRetrieveStrict(t *testing.T) { helper := Osxkeychain{} defer func() { - for _, te := range tests { - helper.Delete(te.storeURL) + for _, tc := range tests { + helper.Delete(tc.storeURL) } }() // Clean store before testing. - for _, te := range tests { - helper.Delete(te.storeURL) + for _, tc := range tests { + helper.Delete(tc.storeURL) } - for _, te := range tests { - c := &credentials.Credentials{ServerURL: te.storeURL, Username: "hello", Secret: "world"} + for _, tc := range tests { + c := &credentials.Credentials{ServerURL: tc.storeURL, Username: "hello", Secret: "world"} if err := helper.Add(c); err != nil { - t.Errorf("Error: failed to store secret for URL %q: %s", te.storeURL, err) + t.Errorf("Error: failed to store secret for URL %q: %s", tc.storeURL, err) continue } - if _, _, err := helper.Get(te.readURL); err == nil { - t.Errorf("Error: managed to read secret for URL %q using %q, but should not be able to", te.storeURL, te.readURL) + if _, _, err := helper.Get(tc.readURL); err == nil { + t.Errorf("Error: managed to read secret for URL %q using %q, but should not be able to", tc.storeURL, tc.readURL) } - helper.Delete(te.storeURL) + helper.Delete(tc.storeURL) } } @@ -167,39 +167,39 @@ func TestOSXKeychainHelperStoreRetrieve(t *testing.T) { helper := Osxkeychain{} defer func() { - for _, te := range tests { - helper.Delete(te.url) + for _, tc := range tests { + helper.Delete(tc.url) } }() // Clean store before testing. - for _, te := range tests { - helper.Delete(te.url) + for _, tc := range tests { + helper.Delete(tc.url) } // Note that we don't delete between individual tests here, to verify that // subsequent stores/overwrites don't affect storing / retrieving secrets. - for i, te := range tests { + for i, tc := range tests { c := &credentials.Credentials{ - ServerURL: te.url, + ServerURL: tc.url, Username: fmt.Sprintf("user-%d", i), Secret: fmt.Sprintf("secret-%d", i), } if err := helper.Add(c); err != nil { - t.Errorf("Error: failed to store secret for URL: %s: %s", te.url, err) + t.Errorf("Error: failed to store secret for URL: %s: %s", tc.url, err) continue } - user, secret, err := helper.Get(te.url) + user, secret, err := helper.Get(tc.url) if err != nil { - t.Errorf("Error: failed to read secret for URL %q: %s", te.url, err) + t.Errorf("Error: failed to read secret for URL %q: %s", tc.url, err) continue } if user != c.Username { - t.Errorf("Error: expected username %s, got username %s for URL: %s", c.Username, user, te.url) + t.Errorf("Error: expected username %s, got username %s for URL: %s", c.Username, user, tc.url) } if secret != c.Secret { - t.Errorf("Error: expected secret %s, got secret %s for URL: %s", c.Secret, secret, te.url) + t.Errorf("Error: expected secret %s, got secret %s for URL: %s", c.Secret, secret, tc.url) } } } diff --git a/registryurl/parse_test.go b/registryurl/parse_test.go index 89feaa7..03a0e03 100644 --- a/registryurl/parse_test.go +++ b/registryurl/parse_test.go @@ -24,23 +24,23 @@ func TestHelperParseURL(t *testing.T) { {url: "ftp://foobar.docker.io:2376", err: errors.New("unsupported scheme: ftp")}, } - for _, te := range tests { - u, err := Parse(te.url) + for _, tc := range tests { + u, err := Parse(tc.url) - if te.err == nil && err != nil { - t.Errorf("Error: failed to parse URL %q: %s", te.url, err) + if tc.err == nil && err != nil { + t.Errorf("Error: failed to parse URL %q: %s", tc.url, err) continue } - if te.err != nil && err == nil { - t.Errorf("Error: expected error %q, got none when parsing URL %q", te.err, te.url) + if tc.err != nil && err == nil { + t.Errorf("Error: expected error %q, got none when parsing URL %q", tc.err, tc.url) continue } - if te.err != nil && err.Error() != te.err.Error() { - t.Errorf("Error: expected error %q, got %q when parsing URL %q", te.err, err, te.url) + if tc.err != nil && err.Error() != tc.err.Error() { + t.Errorf("Error: expected error %q, got %q when parsing URL %q", tc.err, err, tc.url) continue } - if u != nil && u.String() != te.expectedURL { - t.Errorf("Error: expected URL: %q, but got %q for URL: %q", te.expectedURL, u.String(), te.url) + if u != nil && u.String() != tc.expectedURL { + t.Errorf("Error: expected URL: %q, but got %q for URL: %q", tc.expectedURL, u.String(), tc.url) } } } diff --git a/wincred/wincred_windows_test.go b/wincred/wincred_windows_test.go index 68d293a..074b29c 100644 --- a/wincred/wincred_windows_test.go +++ b/wincred/wincred_windows_test.go @@ -106,26 +106,26 @@ func TestWinCredHelperRetrieveAliases(t *testing.T) { helper := Wincred{} defer func() { - for _, te := range tests { - helper.Delete(te.storeURL) + for _, tc := range tests { + helper.Delete(tc.storeURL) } }() // Clean store before testing. - for _, te := range tests { - helper.Delete(te.storeURL) + for _, tc := range tests { + helper.Delete(tc.storeURL) } - for _, te := range tests { - c := &credentials.Credentials{ServerURL: te.storeURL, Username: "hello", Secret: "world"} + for _, tc := range tests { + c := &credentials.Credentials{ServerURL: tc.storeURL, Username: "hello", Secret: "world"} if err := helper.Add(c); err != nil { - t.Errorf("Error: failed to store secret for URL %q: %s", te.storeURL, err) + t.Errorf("Error: failed to store secret for URL %q: %s", tc.storeURL, err) continue } - if _, _, err := helper.Get(te.readURL); err != nil { - t.Errorf("Error: failed to read secret for URL %q using %q", te.storeURL, te.readURL) + if _, _, err := helper.Get(tc.readURL); err != nil { + t.Errorf("Error: failed to read secret for URL %q using %q", tc.storeURL, tc.readURL) } - helper.Delete(te.storeURL) + helper.Delete(tc.storeURL) } } @@ -149,7 +149,7 @@ func TestWinCredHelperRetrieveStrict(t *testing.T) { {"https://foobar.docker.io:1234", "https://foobar.docker.io:5678"}, // non-matching ports TODO is this desired behavior? The other way round does work - //{"https://foobar.docker.io", "https://foobar.docker.io:5678"}, + // {"https://foobar.docker.io", "https://foobar.docker.io:5678"}, // non-matching paths {"https://foobar.docker.io:1234/one/two", "https://foobar.docker.io:1234/five/six"}, @@ -157,26 +157,26 @@ func TestWinCredHelperRetrieveStrict(t *testing.T) { helper := Wincred{} defer func() { - for _, te := range tests { - helper.Delete(te.storeURL) + for _, tc := range tests { + helper.Delete(tc.storeURL) } }() // Clean store before testing. - for _, te := range tests { - helper.Delete(te.storeURL) + for _, tc := range tests { + helper.Delete(tc.storeURL) } - for _, te := range tests { - c := &credentials.Credentials{ServerURL: te.storeURL, Username: "hello", Secret: "world"} + for _, tc := range tests { + c := &credentials.Credentials{ServerURL: tc.storeURL, Username: "hello", Secret: "world"} if err := helper.Add(c); err != nil { - t.Errorf("Error: failed to store secret for URL %q: %s", te.storeURL, err) + t.Errorf("Error: failed to store secret for URL %q: %s", tc.storeURL, err) continue } - if _, _, err := helper.Get(te.readURL); err == nil { - t.Errorf("Error: managed to read secret for URL %q using %q, but should not be able to", te.storeURL, te.readURL) + if _, _, err := helper.Get(tc.readURL); err == nil { + t.Errorf("Error: managed to read secret for URL %q using %q, but should not be able to", tc.storeURL, tc.readURL) } - helper.Delete(te.storeURL) + helper.Delete(tc.storeURL) } } @@ -198,39 +198,39 @@ func TestWinCredHelperStoreRetrieve(t *testing.T) { helper := Wincred{} defer func() { - for _, te := range tests { - helper.Delete(te.url) + for _, tc := range tests { + helper.Delete(tc.url) } }() // Clean store before testing. - for _, te := range tests { - helper.Delete(te.url) + for _, tc := range tests { + helper.Delete(tc.url) } // Note that we don't delete between individual tests here, to verify that // subsequent stores/overwrites don't affect storing / retrieving secrets. - for i, te := range tests { + for i, tc := range tests { c := &credentials.Credentials{ - ServerURL: te.url, + ServerURL: tc.url, Username: fmt.Sprintf("user-%d", i), Secret: fmt.Sprintf("secret-%d", i), } if err := helper.Add(c); err != nil { - t.Errorf("Error: failed to store secret for URL: %s: %s", te.url, err) + t.Errorf("Error: failed to store secret for URL: %s: %s", tc.url, err) continue } - user, secret, err := helper.Get(te.url) + user, secret, err := helper.Get(tc.url) if err != nil { - t.Errorf("Error: failed to read secret for URL %q: %s", te.url, err) + t.Errorf("Error: failed to read secret for URL %q: %s", tc.url, err) continue } if user != c.Username { - t.Errorf("Error: expected username %s, got username %s for URL: %s", c.Username, user, te.url) + t.Errorf("Error: expected username %s, got username %s for URL: %s", c.Username, user, tc.url) } if secret != c.Secret { - t.Errorf("Error: expected secret %s, got secret %s for URL: %s", c.Secret, secret, te.url) + t.Errorf("Error: expected secret %s, got secret %s for URL: %s", c.Secret, secret, tc.url) } } }