|
| 1 | +/* |
| 2 | +Copyright 2017 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 cmd |
| 18 | + |
| 19 | +import ( |
| 20 | + "encoding/json" |
| 21 | + "testing" |
| 22 | + |
| 23 | + "github.com/stretchr/testify/assert" |
| 24 | +) |
| 25 | + |
| 26 | +func TestVersionStringIncludesExpectedFields(t *testing.T) { |
| 27 | + output := versionString() |
| 28 | + |
| 29 | + assert.Contains(t, output, "KubeBuilder Version:") |
| 30 | + assert.Contains(t, output, "Kubernetes Vendor:") |
| 31 | + assert.Contains(t, output, "Git Commit:") |
| 32 | + assert.Contains(t, output, "Build Date:") |
| 33 | + assert.Contains(t, output, "Go OS/Arch:") |
| 34 | +} |
| 35 | + |
| 36 | +func TestVersionJSONFormatAndKeys(t *testing.T) { |
| 37 | + jsonStr := versionJSON() |
| 38 | + |
| 39 | + var result map[string]string |
| 40 | + err := json.Unmarshal([]byte(jsonStr), &result) |
| 41 | + assert.NoError(t, err) |
| 42 | + |
| 43 | + assert.Contains(t, result, "kubeBuilderVersion") |
| 44 | + assert.Contains(t, result, "kubernetesVendor") |
| 45 | + assert.Contains(t, result, "gitCommit") |
| 46 | + assert.Contains(t, result, "buildDate") |
| 47 | + assert.Contains(t, result, "goOs") |
| 48 | + assert.Contains(t, result, "goArch") |
| 49 | +} |
| 50 | + |
| 51 | +func TestGetVersionInfoFieldsArePopulated(t *testing.T) { |
| 52 | + v := getVersionInfo() |
| 53 | + |
| 54 | + assert.NotEmpty(t, v.KubeBuilderVersion) |
| 55 | + assert.NotEmpty(t, v.KubernetesVendor) |
| 56 | + assert.NotEmpty(t, v.GitCommit) |
| 57 | + assert.NotEmpty(t, v.BuildDate) |
| 58 | + assert.NotEmpty(t, v.GoOS) |
| 59 | + assert.NotEmpty(t, v.GoArch) |
| 60 | + |
| 61 | + assert.NotEqual(t, "unknown", v.KubeBuilderVersion, "KubeBuilderVersion should not be 'unknown'") |
| 62 | + assert.NotEqual(t, "unknown", v.GoOS, "GoOS should not be 'unknown'") |
| 63 | + assert.NotEqual(t, "unknown", v.GoArch, "GoArch should not be 'unknown'") |
| 64 | + assert.NotEqual(t, "$Format:%H$", v.GitCommit, "GitCommit should not be default placeholder") |
| 65 | +} |
0 commit comments