🌱 avoid assumptions about versions in tests (#4134)

For example NixOS builds and tests scorecards in an environment that
sets the version, which would make this test fail as it currently
assumes the version is unset when running tests.

Signed-off-by: Arnout Engelen <arnout@bzzt.net>
This commit is contained in:
Arnout Engelen 2024-05-30 15:02:55 +02:00 committed by GitHub
parent 16ed8a68aa
commit 6b49140bbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,6 +20,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"sigs.k8s.io/release-utils/version"
"github.com/ossf/scorecard/v5/checker"
"github.com/ossf/scorecard/v5/clients"
@ -128,6 +129,10 @@ func TestRunScorecard(t *testing.T) {
uri string
commitSHA string
}
// These values depend on the environment,
// so don't encode particular expectations
// in the test:
versionInfo := version.GetVersionInfo()
tests := []struct {
name string
args args
@ -145,8 +150,8 @@ func TestRunScorecard(t *testing.T) {
Name: "github.com/ossf/scorecard",
},
Scorecard: ScorecardInfo{
Version: "devel",
CommitSHA: "unknown",
Version: versionInfo.GitVersion,
CommitSHA: versionInfo.GitCommit,
},
},
wantErr: false,
@ -194,6 +199,10 @@ func TestRunScorecard(t *testing.T) {
func TestExperimentalRunProbes(t *testing.T) {
t.Parallel()
// These values depend on the environment,
// so don't encode particular expectations
// in the test:
versionInfo := version.GetVersionInfo()
type args struct {
uri string
commitSHA string
@ -230,8 +239,8 @@ func TestExperimentalRunProbes(t *testing.T) {
},
},
Scorecard: ScorecardInfo{
Version: "devel",
CommitSHA: "unknown",
Version: versionInfo.GitVersion,
CommitSHA: versionInfo.GitCommit,
},
Findings: []finding.Finding{
{