1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-10-30 23:57:50 +02:00

fix(versioning): properly consider go.mod (#3687)

* fix(versioning): properly consider go.mod

* fix test
This commit is contained in:
Oliver Nocon
2022-03-31 17:07:10 +02:00
committed by GitHub
parent 23ea4111fb
commit 62b3a9a459
3 changed files with 27 additions and 5 deletions

View File

@@ -354,7 +354,7 @@ func TestRunGolangBuild(t *testing.T) {
telemetryData := telemetry.CustomData{}
err := runGolangBuild(&config, &telemetryData, utils, &cpe)
assert.EqualError(t, err, "no build descriptor available, supported: [VERSION version.txt go.mod]")
assert.EqualError(t, err, "no build descriptor available, supported: [go.mod VERSION version.txt]")
})
t.Run("failure - publish - received unexpected status code", func(t *testing.T) {

View File

@@ -94,7 +94,7 @@ func GetArtifact(buildTool, buildDescriptorFilePath string, opts *Options, utils
case "golang":
if len(buildDescriptorFilePath) == 0 {
var err error
buildDescriptorFilePath, err = searchDescriptor([]string{"VERSION", "version.txt", "go.mod"}, fileExists)
buildDescriptorFilePath, err = searchDescriptor([]string{"go.mod", "VERSION", "version.txt"}, fileExists)
if err != nil {
return artifact, err
}

View File

@@ -65,8 +65,13 @@ func TestGetArtifact(t *testing.T) {
assert.Equal(t, "semver2", dub.VersioningScheme())
})
t.Run("golang", func(t *testing.T) {
fileExists = func(string) (bool, error) { return true, nil }
t.Run("golang - version file", func(t *testing.T) {
fileExists = func(s string) (bool, error) {
if s == "go.mod" {
return false, nil
}
return true, nil
}
golang, err := GetArtifact("golang", "", &Options{}, nil)
assert.NoError(t, err)
@@ -77,11 +82,28 @@ func TestGetArtifact(t *testing.T) {
assert.Equal(t, "semver2", golang.VersioningScheme())
})
t.Run("golang - gomod", func(t *testing.T) {
fileExists = func(s string) (bool, error) {
if s == "go.mod" {
return true, nil
}
return false, nil
}
golang, err := GetArtifact("golang", "", &Options{}, nil)
assert.NoError(t, err)
theType, ok := golang.(*GoMod)
assert.True(t, ok)
assert.Equal(t, "go.mod", theType.path)
assert.Equal(t, "semver2", golang.VersioningScheme())
})
t.Run("golang - error", func(t *testing.T) {
fileExists = func(string) (bool, error) { return false, nil }
_, err := GetArtifact("golang", "", &Options{}, nil)
assert.EqualError(t, err, "no build descriptor available, supported: [VERSION version.txt go.mod]")
assert.EqualError(t, err, "no build descriptor available, supported: [go.mod VERSION version.txt]")
})
t.Run("gradle", func(t *testing.T) {