forked from kubernetes-sigs/kustomize
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Versioning to Improve Output (kubernetes-sigs#5000)
* Update Versioning to Improve Output * Always get commit from build info, always get date and version from ldflag * Just replace broken main output with semver and deprecate short flag as is --------- Co-authored-by: Katrina Verey <katrina.verey@shopify.com>
- Loading branch information
Showing
8 changed files
with
151 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2022 The Kubernetes Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package provenance_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"sigs.k8s.io/kustomize/api/provenance" | ||
) | ||
|
||
const expectedBuildDateFromLdFlag = "2023-01-31T23:38:41Z" | ||
const expectedVersionFromLdFlag = "(test)" | ||
|
||
func TestGetProvenance(t *testing.T) { | ||
p := provenance.GetProvenance() | ||
// These are set by ldflags in our Makefile | ||
assert.Equal(t, expectedVersionFromLdFlag, p.Version) | ||
assert.Equal(t, expectedBuildDateFromLdFlag, p.BuildDate) | ||
// This comes from BuildInfo, which is not set during go test: https://github.com/golang/go/issues/33976 | ||
assert.Equal(t, "unknown", p.GitCommit) | ||
|
||
// These are set properly during go test | ||
assert.NotEmpty(t, p.GoArch) | ||
assert.NotEmpty(t, p.GoOs) | ||
assert.Contains(t, p.GoVersion, "go1.") | ||
} | ||
|
||
func TestProvenance_Short(t *testing.T) { | ||
p := provenance.GetProvenance() | ||
// The version not set during go test, so this comes from an ldflag: https://github.com/golang/go/issues/33976 | ||
assert.Equal(t, fmt.Sprintf("{%s %s }", expectedVersionFromLdFlag, expectedBuildDateFromLdFlag), p.Short()) | ||
|
||
p.Version = "kustomize/v4.11.12" | ||
assert.Equal(t, fmt.Sprintf("{kustomize/v4.11.12 %s }", expectedBuildDateFromLdFlag), p.Short()) | ||
} | ||
|
||
func TestProvenance_Semver(t *testing.T) { | ||
p := provenance.GetProvenance() | ||
// The version not set during go test | ||
assert.Equal(t, "(test)", p.Semver()) | ||
|
||
p.Version = "kustomize/v4.11.12" | ||
assert.Equal(t, "v4.11.12", p.Semver()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters