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

     1  /*
     2  Copyright 2020 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  // version holds variables that identify a Prow binary's name and version
    18  package version
    19  
    20  import "testing"
    21  
    22  func TestVersionTimestamp(t *testing.T) {
    23  	tests := []struct {
    24  		name    string
    25  		version string
    26  		wantV   int64
    27  		wantErr bool
    28  	}{
    29  		{
    30  			"base case",
    31  			"v20200102-a1b2c3",
    32  			1577923200,
    33  			false,
    34  		},
    35  		{
    36  			"invalid version",
    37  			"v20200102a-a1b2c3",
    38  			0,
    39  			true,
    40  		},
    41  	}
    42  	for _, tc := range tests {
    43  		t.Run(tc.name, func(t *testing.T) {
    44  			Version = tc.version
    45  			got, gotErr := VersionTimestamp()
    46  			if got != tc.wantV {
    47  				t.Fatalf("version mismatch, want: %d, got: %d", tc.wantV, got)
    48  			}
    49  			if ((gotErr != nil) && tc.wantErr) != ((gotErr != nil) || tc.wantErr) {
    50  				t.Fatalf("error mismatch, want: %v, got: %v", tc.wantErr, gotErr)
    51  			}
    52  		})
    53  	}
    54  }