Skip to content

Commit

Permalink
Merge pull request #15664 from justinsb/auth_cache_tests
Browse files Browse the repository at this point in the history
Add golden-output test for cacheFilePath
  • Loading branch information
k8s-ci-robot committed Jul 19, 2023
2 parents c2f64a5 + 81f3551 commit 4b5519d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pkg/commands/helpers/kubectl_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,29 @@ func Test_cacheFilePath(t *testing.T) {
inputs := []struct {
kopsStateStore string
clusterName string
wantFilename string
}{
{
kopsStateStore: "s3://abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk",
clusterName: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcde." +
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk." +
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk." +
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com",
wantFilename: "abcdefghijklmnopqrstuvwxyzabcdef_2gdSmQxAE3nMLFrXXuEuCBoVaajWndsK8OMnUV",
},
}

output1 := cacheFilePath(inputs[0].kopsStateStore, inputs[0].clusterName)
_, file := path.Split(output1)
for _, input := range inputs {
output := cacheFilePath(input.kopsStateStore, input.clusterName)
_, file := path.Split(output)

if len(file) > 71 {
t.Errorf("cacheFilePath() got %v, too long(%v)", output1, len(file))
// Explicitly guard against overly long filenames - this is why we do truncation
if len(file) > 71 {
t.Errorf("cacheFilePath() got %v, too long(%v)", output, len(file))
}

if file != input.wantFilename {
t.Errorf("cacheFilePath(%q, %q) got %v, want %v", input.kopsStateStore, input.clusterName, file, input.wantFilename)
}
}
}

0 comments on commit 4b5519d

Please sign in to comment.