From 81f35513dc34e4ce6a1b39213c5369be8f55cfbf Mon Sep 17 00:00:00 2001 From: justinsb Date: Tue, 18 Jul 2023 12:38:45 -0400 Subject: [PATCH] Add golden-output test for cacheFilePath Just so we can verify that the value looks as we expect it to. The actual value doesn't much matter, but it's still helpful for us to be able to see changes to the value in the PR workflow. --- pkg/commands/helpers/kubectl_auth_test.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/commands/helpers/kubectl_auth_test.go b/pkg/commands/helpers/kubectl_auth_test.go index 34950d0e22adc..f0ff8e06bfab2 100644 --- a/pkg/commands/helpers/kubectl_auth_test.go +++ b/pkg/commands/helpers/kubectl_auth_test.go @@ -25,6 +25,7 @@ func Test_cacheFilePath(t *testing.T) { inputs := []struct { kopsStateStore string clusterName string + wantFilename string }{ { kopsStateStore: "s3://abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk", @@ -32,13 +33,21 @@ func Test_cacheFilePath(t *testing.T) { "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) + } } }