github.com/koderover/helm@v2.17.0+incompatible/pkg/version/version_test.go (about) 1 /* 2 Copyright The Helm 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 version represents the current version of the project. 18 package version // import "k8s.io/helm/pkg/version" 19 20 import "testing" 21 import "k8s.io/helm/pkg/proto/hapi/version" 22 23 func TestGetVersionProto(t *testing.T) { 24 tests := []struct { 25 version string 26 buildMetadata string 27 gitCommit string 28 gitTreeState string 29 expected version.Version 30 }{ 31 {"", "", "", "", version.Version{SemVer: "", GitCommit: "", GitTreeState: ""}}, 32 {"v1.0.0", "", "", "", version.Version{SemVer: "v1.0.0", GitCommit: "", GitTreeState: ""}}, 33 {"v1.0.0", "79d5c5f7", "", "", version.Version{SemVer: "v1.0.0+79d5c5f7", GitCommit: "", GitTreeState: ""}}, 34 {"v1.0.0", "79d5c5f7", "0d399baec2acda578a217d1aec8d7d707c71e44d", "", version.Version{SemVer: "v1.0.0+79d5c5f7", GitCommit: "0d399baec2acda578a217d1aec8d7d707c71e44d", GitTreeState: ""}}, 35 {"v1.0.0", "79d5c5f7", "0d399baec2acda578a217d1aec8d7d707c71e44d", "clean", version.Version{SemVer: "v1.0.0+79d5c5f7", GitCommit: "0d399baec2acda578a217d1aec8d7d707c71e44d", GitTreeState: "clean"}}, 36 } 37 for _, tt := range tests { 38 Version = tt.version 39 BuildMetadata = tt.buildMetadata 40 GitCommit = tt.gitCommit 41 GitTreeState = tt.gitTreeState 42 if versionProto := GetVersionProto(); !versionEqual(*versionProto, tt.expected) { 43 t.Errorf("expected Semver(%s+%s), GitCommit(%s) and GitTreeState(%s) to be %v", tt.version, tt.buildMetadata, tt.gitCommit, tt.gitTreeState, *versionProto) 44 } 45 } 46 } 47 48 func versionEqual(v1 version.Version, v2 version.Version) bool { 49 if v1.SemVer != v2.SemVer || 50 v1.GitCommit != v2.GitCommit || 51 v1.GitTreeState != v2.GitTreeState { 52 return false 53 } 54 return true 55 }