constants: make VersionInfo readonly (#1316)

The variable VersionInfo is supposed to be set by `go build -X ...` during link time but should not be modified at runtime.
This change ensures the underlying var is private and can only be accessed by a public getter.
This commit is contained in:
Malte Poll 2023-03-01 11:55:12 +01:00 committed by GitHub
parent 0157537852
commit fc33a74c78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 43 additions and 43 deletions

View file

@ -250,7 +250,6 @@ func TestConfigFetchMeasurements(t *testing.T) {
gcpConfig := defaultConfigWithExpectedMeasurements(t, config.Default(), cloudprovider.GCP)
gcpConfig.Image = "v999.999.999"
constants.VersionInfo = "v999.999.999"
err := fileHandler.WriteYAML(constants.ConfigFilename, gcpConfig, file.OptMkdirAll)
require.NoError(err)

View file

@ -79,7 +79,7 @@ func runUpgradeCheck(cmd *cobra.Command, args []string) error {
client: http.DefaultClient,
rekor: rekor,
flags: flags,
cliVersion: compatibility.EnsurePrefixV(constants.VersionInfo),
cliVersion: compatibility.EnsurePrefixV(constants.VersionInfo()),
log: log,
},
log: log,

View file

@ -233,7 +233,6 @@ func TestUpgradeCheck(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
constants.VersionInfo = "v0.0.0"
fileHandler := file.NewHandler(afero.NewMemMapFs())
cfg := defaultConfigWithExpectedMeasurements(t, config.Default(), tc.csp)
require.NoError(fileHandler.WriteYAML(tc.flags.configPath, cfg))

View file

@ -34,7 +34,7 @@ func runVersion(cmd *cobra.Command, args []string) {
commit, state, date, goVersion, compiler, platform := parseBuildInfo(buildInfo)
cmd.Printf("Version:\t%s (%s)\n", constants.VersionInfo, constants.VersionBuild)
cmd.Printf("Version:\t%s (%s)\n", constants.VersionInfo(), constants.VersionBuild)
cmd.Printf("GitCommit:\t%s\n", commit)
cmd.Printf("GitTreeState:\t%s\n", state)
cmd.Printf("BuildDate:\t%s\n", date)

View file

@ -28,7 +28,7 @@ func TestVersionCmd(t *testing.T) {
s, err := io.ReadAll(b)
assert.NoError(err)
assert.Contains(string(s), constants.VersionInfo)
assert.Contains(string(s), constants.VersionInfo())
}
func TestParseBuildInfo(t *testing.T) {

View file

@ -149,11 +149,11 @@ func (c *Client) upgradeRelease(
values = loader.loadCertManagerValues()
case conOperatorsReleaseName:
// ensure that the operator chart has the same version as the CLI
updateVersions(chart, compatibility.EnsurePrefixV(constants.VersionInfo))
updateVersions(chart, compatibility.EnsurePrefixV(constants.VersionInfo()))
values, err = loader.loadOperatorsValues()
case conServicesReleaseName:
// ensure that the services chart has the same version as the CLI
updateVersions(chart, compatibility.EnsurePrefixV(constants.VersionInfo))
updateVersions(chart, compatibility.EnsurePrefixV(constants.VersionInfo()))
values, err = loader.loadConstellationServicesValues()
default:
return fmt.Errorf("invalid release name: %s", releaseName)

View file

@ -283,7 +283,7 @@ func (i *ChartLoader) loadOperators() (helm.Release, error) {
return helm.Release{}, fmt.Errorf("loading operators chart: %w", err)
}
updateVersions(chart, compatibility.EnsurePrefixV(constants.VersionInfo))
updateVersions(chart, compatibility.EnsurePrefixV(constants.VersionInfo()))
values, err := i.loadOperatorsValues()
if err != nil {
@ -370,7 +370,7 @@ func (i *ChartLoader) loadConstellationServices() (helm.Release, error) {
return helm.Release{}, fmt.Errorf("loading constellation-services chart: %w", err)
}
updateVersions(chart, compatibility.EnsurePrefixV(constants.VersionInfo))
updateVersions(chart, compatibility.EnsurePrefixV(constants.VersionInfo()))
values, err := i.loadConstellationServicesValues()
if err != nil {