fix(go): support 1.16

resolves #428
This commit is contained in:
Jan De Dobbeleer 2021-02-18 08:38:51 +01:00 committed by Jan De Dobbeleer
parent c7db86ed4c
commit de498044c9
2 changed files with 35 additions and 1 deletions

View file

@ -17,7 +17,7 @@ func (g *golang) init(props *properties, env environmentInfo) {
{
executable: "go",
args: []string{"version"},
regex: `(?:go(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+))))`,
regex: `(?:go(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+)(.(?P<patch>[0-9]+))?)))`,
},
},
versionURLTemplate: "[%s](https://golang.org/doc/go%s.%s)",

34
src/segment_golang_test.go Executable file
View file

@ -0,0 +1,34 @@
package main
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGolang(t *testing.T) {
cases := []struct {
Case string
ExpectedString string
Version string
}{
{Case: "Go 1.15", ExpectedString: "1.15.8", Version: "go version go1.15.8 darwin/amd64"},
{Case: "Go 1.16", ExpectedString: "1.16", Version: "go version go1.16 darwin/amd64"},
}
for _, tc := range cases {
env := new(MockedEnvironment)
env.On("hasCommand", "go").Return(true)
env.On("runCommand", "go", []string{"version"}).Return(tc.Version, nil)
env.On("hasFiles", "*.go").Return(true)
props := &properties{
values: map[Property]interface{}{
DisplayVersion: true,
},
}
g := &golang{}
g.init(props, env)
assert.True(t, g.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
assert.Equal(t, tc.ExpectedString, g.string(), fmt.Sprintf("Failed in case: %s", tc.Case))
}
}