From a7ff1c7d168260b646d20979d4d8ab04507ac2d5 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 27 May 2023 14:15:20 +0200 Subject: [PATCH] osxkeychain: don't use un-keyed literals in test-tables Also moving the comments into the test-tables. Signed-off-by: Sebastiaan van Stijn --- osxkeychain/osxkeychain_darwin_test.go | 74 +++++++++++++++++--------- 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/osxkeychain/osxkeychain_darwin_test.go b/osxkeychain/osxkeychain_darwin_test.go index 48792d6..f639496 100644 --- a/osxkeychain/osxkeychain_darwin_test.go +++ b/osxkeychain/osxkeychain_darwin_test.go @@ -60,17 +60,25 @@ func TestOSXKeychainHelper(t *testing.T) { // through variations on the URL func TestOSXKeychainHelperRetrieveAliases(t *testing.T) { tests := []struct { + doc string storeURL string readURL string }{ - // stored with port, retrieved without - {"https://foobar.docker.io:2376", "https://foobar.docker.io"}, - - // stored as https, retrieved without scheme - {"https://foobar.docker.io:2376", "foobar.docker.io"}, - - // stored with path, retrieved without - {"https://foobar.docker.io:1234/one/two", "https://foobar.docker.io:1234"}, + { + doc: "stored with port, retrieved without", + storeURL: "https://foobar.docker.io:2376", + readURL: "https://foobar.docker.io", + }, + { + doc: "stored as https, retrieved without scheme", + storeURL: "https://foobar.docker.io:2376", + readURL: "foobar.docker.io", + }, + { + doc: "stored with path, retrieved without", + storeURL: "https://foobar.docker.io:1234/one/two", + readURL: "https://foobar.docker.io:1234", + }, } helper := Osxkeychain{} @@ -102,26 +110,42 @@ func TestOSXKeychainHelperRetrieveAliases(t *testing.T) { // returned. func TestOSXKeychainHelperRetrieveStrict(t *testing.T) { tests := []struct { + doc string storeURL string readURL string }{ - // stored as https, retrieved using http - {"https://foobar.docker.io:2376", "http://foobar.docker.io:2376"}, - - // stored as http, retrieved using https - {"http://foobar.docker.io:2376", "https://foobar.docker.io:2376"}, - - // same: stored as http, retrieved without a scheme specified (hence, using the default https://) - {"http://foobar.docker.io", "foobar.docker.io:5678"}, - - // non-matching ports - {"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"}, - - // non-matching paths - {"https://foobar.docker.io:1234/one/two", "https://foobar.docker.io:1234/five/six"}, + { + doc: "stored as https, retrieved using http", + storeURL: "https://foobar.docker.io:2376", + readURL: "http://foobar.docker.io:2376", + }, + { + doc: "stored as http, retrieved using https", + storeURL: "http://foobar.docker.io:2376", + readURL: "https://foobar.docker.io:2376", + }, + { + // stored as http, retrieved without a scheme specified (hence, using the default https://) + doc: "stored as http, retrieved without scheme", + storeURL: "http://foobar.docker.io", + readURL: "foobar.docker.io:5678", + }, + { + doc: "non-matching ports", + storeURL: "https://foobar.docker.io:1234", + readURL: "https://foobar.docker.io:5678", + }, + // TODO: is this desired behavior? The other way round does work + // { + // doc: "non-matching ports (stored without port)", + // storeURL: "https://foobar.docker.io", + // readURL: "https://foobar.docker.io:5678", + // }, + { + doc: "non-matching paths", + storeURL: "https://foobar.docker.io:1234/one/two", + readURL: "https://foobar.docker.io:1234/five/six", + }, } helper := Osxkeychain{}