1
0
mirror of https://github.com/docker/docker-credential-helpers.git synced 2026-06-13 16:01:28 +05:30

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 <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2023-05-27 13:58:02 +02:00
parent f09e79d741
commit 810dcd4ed5
3 changed files with 74 additions and 74 deletions
+32 -32
View File
@@ -75,26 +75,26 @@ func TestOSXKeychainHelperRetrieveAliases(t *testing.T) {
helper := Osxkeychain{} helper := Osxkeychain{}
defer func() { defer func() {
for _, te := range tests { for _, tc := range tests {
helper.Delete(te.storeURL) helper.Delete(tc.storeURL)
} }
}() }()
// Clean store before testing. // Clean store before testing.
for _, te := range tests { for _, tc := range tests {
helper.Delete(te.storeURL) helper.Delete(tc.storeURL)
} }
for _, te := range tests { for _, tc := range tests {
c := &credentials.Credentials{ServerURL: te.storeURL, Username: "hello", Secret: "world"} c := &credentials.Credentials{ServerURL: tc.storeURL, Username: "hello", Secret: "world"}
if err := helper.Add(c); err != nil { 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 continue
} }
if _, _, err := helper.Get(te.readURL); err != nil { if _, _, err := helper.Get(tc.readURL); err != nil {
t.Errorf("Error: failed to read secret for URL %q using %q", te.storeURL, te.readURL) 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"}, {"https://foobar.docker.io:1234", "https://foobar.docker.io:5678"},
// non-matching ports TODO is this desired behavior? The other way round does work // 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 // non-matching paths
{"https://foobar.docker.io:1234/one/two", "https://foobar.docker.io:1234/five/six"}, {"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{} helper := Osxkeychain{}
defer func() { defer func() {
for _, te := range tests { for _, tc := range tests {
helper.Delete(te.storeURL) helper.Delete(tc.storeURL)
} }
}() }()
// Clean store before testing. // Clean store before testing.
for _, te := range tests { for _, tc := range tests {
helper.Delete(te.storeURL) helper.Delete(tc.storeURL)
} }
for _, te := range tests { for _, tc := range tests {
c := &credentials.Credentials{ServerURL: te.storeURL, Username: "hello", Secret: "world"} c := &credentials.Credentials{ServerURL: tc.storeURL, Username: "hello", Secret: "world"}
if err := helper.Add(c); err != nil { 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 continue
} }
if _, _, err := helper.Get(te.readURL); err == nil { 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", te.storeURL, te.readURL) 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{} helper := Osxkeychain{}
defer func() { defer func() {
for _, te := range tests { for _, tc := range tests {
helper.Delete(te.url) helper.Delete(tc.url)
} }
}() }()
// Clean store before testing. // Clean store before testing.
for _, te := range tests { for _, tc := range tests {
helper.Delete(te.url) helper.Delete(tc.url)
} }
// Note that we don't delete between individual tests here, to verify that // Note that we don't delete between individual tests here, to verify that
// subsequent stores/overwrites don't affect storing / retrieving secrets. // subsequent stores/overwrites don't affect storing / retrieving secrets.
for i, te := range tests { for i, tc := range tests {
c := &credentials.Credentials{ c := &credentials.Credentials{
ServerURL: te.url, ServerURL: tc.url,
Username: fmt.Sprintf("user-%d", i), Username: fmt.Sprintf("user-%d", i),
Secret: fmt.Sprintf("secret-%d", i), Secret: fmt.Sprintf("secret-%d", i),
} }
if err := helper.Add(c); err != nil { 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 continue
} }
user, secret, err := helper.Get(te.url) user, secret, err := helper.Get(tc.url)
if err != nil { 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 continue
} }
if user != c.Username { 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 { 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)
} }
} }
} }
+10 -10
View File
@@ -24,23 +24,23 @@ func TestHelperParseURL(t *testing.T) {
{url: "ftp://foobar.docker.io:2376", err: errors.New("unsupported scheme: ftp")}, {url: "ftp://foobar.docker.io:2376", err: errors.New("unsupported scheme: ftp")},
} }
for _, te := range tests { for _, tc := range tests {
u, err := Parse(te.url) u, err := Parse(tc.url)
if te.err == nil && err != nil { if tc.err == nil && err != nil {
t.Errorf("Error: failed to parse URL %q: %s", te.url, err) t.Errorf("Error: failed to parse URL %q: %s", tc.url, err)
continue continue
} }
if te.err != nil && err == nil { if tc.err != nil && err == nil {
t.Errorf("Error: expected error %q, got none when parsing URL %q", te.err, te.url) t.Errorf("Error: expected error %q, got none when parsing URL %q", tc.err, tc.url)
continue continue
} }
if te.err != nil && err.Error() != te.err.Error() { if tc.err != nil && err.Error() != tc.err.Error() {
t.Errorf("Error: expected error %q, got %q when parsing URL %q", te.err, err, te.url) t.Errorf("Error: expected error %q, got %q when parsing URL %q", tc.err, err, tc.url)
continue continue
} }
if u != nil && u.String() != te.expectedURL { if u != nil && u.String() != tc.expectedURL {
t.Errorf("Error: expected URL: %q, but got %q for URL: %q", te.expectedURL, u.String(), te.url) t.Errorf("Error: expected URL: %q, but got %q for URL: %q", tc.expectedURL, u.String(), tc.url)
} }
} }
} }
+32 -32
View File
@@ -106,26 +106,26 @@ func TestWinCredHelperRetrieveAliases(t *testing.T) {
helper := Wincred{} helper := Wincred{}
defer func() { defer func() {
for _, te := range tests { for _, tc := range tests {
helper.Delete(te.storeURL) helper.Delete(tc.storeURL)
} }
}() }()
// Clean store before testing. // Clean store before testing.
for _, te := range tests { for _, tc := range tests {
helper.Delete(te.storeURL) helper.Delete(tc.storeURL)
} }
for _, te := range tests { for _, tc := range tests {
c := &credentials.Credentials{ServerURL: te.storeURL, Username: "hello", Secret: "world"} c := &credentials.Credentials{ServerURL: tc.storeURL, Username: "hello", Secret: "world"}
if err := helper.Add(c); err != nil { 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 continue
} }
if _, _, err := helper.Get(te.readURL); err != nil { if _, _, err := helper.Get(tc.readURL); err != nil {
t.Errorf("Error: failed to read secret for URL %q using %q", te.storeURL, te.readURL) 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"}, {"https://foobar.docker.io:1234", "https://foobar.docker.io:5678"},
// non-matching ports TODO is this desired behavior? The other way round does work // 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 // non-matching paths
{"https://foobar.docker.io:1234/one/two", "https://foobar.docker.io:1234/five/six"}, {"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{} helper := Wincred{}
defer func() { defer func() {
for _, te := range tests { for _, tc := range tests {
helper.Delete(te.storeURL) helper.Delete(tc.storeURL)
} }
}() }()
// Clean store before testing. // Clean store before testing.
for _, te := range tests { for _, tc := range tests {
helper.Delete(te.storeURL) helper.Delete(tc.storeURL)
} }
for _, te := range tests { for _, tc := range tests {
c := &credentials.Credentials{ServerURL: te.storeURL, Username: "hello", Secret: "world"} c := &credentials.Credentials{ServerURL: tc.storeURL, Username: "hello", Secret: "world"}
if err := helper.Add(c); err != nil { 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 continue
} }
if _, _, err := helper.Get(te.readURL); err == nil { 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", te.storeURL, te.readURL) 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{} helper := Wincred{}
defer func() { defer func() {
for _, te := range tests { for _, tc := range tests {
helper.Delete(te.url) helper.Delete(tc.url)
} }
}() }()
// Clean store before testing. // Clean store before testing.
for _, te := range tests { for _, tc := range tests {
helper.Delete(te.url) helper.Delete(tc.url)
} }
// Note that we don't delete between individual tests here, to verify that // Note that we don't delete between individual tests here, to verify that
// subsequent stores/overwrites don't affect storing / retrieving secrets. // subsequent stores/overwrites don't affect storing / retrieving secrets.
for i, te := range tests { for i, tc := range tests {
c := &credentials.Credentials{ c := &credentials.Credentials{
ServerURL: te.url, ServerURL: tc.url,
Username: fmt.Sprintf("user-%d", i), Username: fmt.Sprintf("user-%d", i),
Secret: fmt.Sprintf("secret-%d", i), Secret: fmt.Sprintf("secret-%d", i),
} }
if err := helper.Add(c); err != nil { 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 continue
} }
user, secret, err := helper.Get(te.url) user, secret, err := helper.Get(tc.url)
if err != nil { 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 continue
} }
if user != c.Username { 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 { 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)
} }
} }
} }