fix: node segment enable_version_mismatch

This commit is contained in:
Mansur 2021-11-15 13:35:45 +03:00 committed by GitHub
parent 2a44dca898
commit c1bc4404e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 8 deletions

View file

@ -61,5 +61,13 @@ func (n *node) matchesVersionFile() bool {
if len(fileVersion) == 0 {
return true
}
return fileVersion == n.language.activeCommand.version.Full
regex := fmt.Sprintf(
`(?im)^v?%s(\.?%s)?(\.?%s)?$`,
n.language.activeCommand.version.Major,
n.language.activeCommand.version.Minor,
n.language.activeCommand.version.Patch,
)
return matchString(regex, fileVersion)
}

View file

@ -7,15 +7,25 @@ import (
)
func TestNodeMatchesVersionFile(t *testing.T) {
nodeVersion := version{
Full: "1.2.3",
Major: "1",
Minor: "2",
Patch: "3",
}
cases := []struct {
Case string
Expected bool
RCVersion string
Version string
}{
{Case: "no file context", Expected: true, RCVersion: "", Version: "durp"},
{Case: "version match", Expected: true, RCVersion: "durp", Version: "durp"},
{Case: "version mismatch", Expected: false, RCVersion: "werp", Version: "durp"},
{Case: "no file context", Expected: true, RCVersion: ""},
{Case: "version match", Expected: true, RCVersion: "1.2.3"},
{Case: "version mismatch", Expected: false, RCVersion: "3.2.1"},
{Case: "version match in other format", Expected: true, RCVersion: "v1.2.3"},
{Case: "version match without patch", Expected: true, RCVersion: "1.2"},
{Case: "version match without patch in other format", Expected: true, RCVersion: "v1.2"},
{Case: "version match without minor", Expected: true, RCVersion: "1"},
{Case: "version match without minor in other format", Expected: true, RCVersion: "v1"},
}
for _, tc := range cases {
@ -25,9 +35,7 @@ func TestNodeMatchesVersionFile(t *testing.T) {
language: &language{
env: env,
activeCommand: &cmd{
version: &version{
Full: tc.Version,
},
version: &nodeVersion,
},
},
}