sigs.k8s.io/prow@v0.0.0-20240503223140-c5e374dc7eb1/pkg/resultstore/uploader_test.go (about)

     1  /*
     2  Copyright 2024 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package resultstore
    18  
    19  import "testing"
    20  
    21  func TestTokenGenerator(t *testing.T) {
    22  
    23  	for _, tc := range []struct {
    24  		desc string
    25  		seed string
    26  		id   string
    27  		want string
    28  	}{
    29  		{
    30  			desc: "normal",
    31  			seed: "Test Seed",
    32  			id:   "2cf762a1-e2ff-4c09-a45c-96ace79c0080",
    33  			want: "a6ca96c8-5411-4767-8cde-2e886cea8fea",
    34  		},
    35  		{
    36  			desc: "empty id",
    37  			seed: "Test Seed",
    38  			id:   "",
    39  			want: "dd84c04e-5803-447b-b2dd-cc85c6d01281",
    40  		},
    41  		{
    42  			desc: "empty seed",
    43  			seed: "",
    44  			id:   "2cf762a1-e2ff-4c09-a45c-96ace79c0080",
    45  			want: "35f1d874-5264-4b2d-afd5-cbbcfd43be37",
    46  		},
    47  		{
    48  			desc: "non uuid ok",
    49  			seed: "Test Seed",
    50  			id:   "non-uuid-value",
    51  			want: "c89d28cc-0f73-43c1-ba3a-695570eb3546",
    52  		},
    53  	} {
    54  		t.Run(tc.desc, func(t *testing.T) {
    55  			tg := tokenGenerator{}
    56  			tg.Reseed(tc.seed)
    57  			if got, want := tg.From(tc.id), tc.want; got != want {
    58  				t.Errorf("From() got %q, want %q", got, want)
    59  			}
    60  			// Ensure repeatable values.
    61  			if got, want := tg.From(tc.id), tc.want; got != want {
    62  				t.Errorf("Second From() got %q, want %q", got, want)
    63  			}
    64  		})
    65  	}
    66  }