mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 17:02:49 +03:00
75 lines
1.7 KiB
Go
75 lines
1.7 KiB
Go
|
package version
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestNew(t *testing.T) {
|
||
|
v := New()
|
||
|
if v == nil {
|
||
|
t.Fatal("expected a version object, got nil")
|
||
|
}
|
||
|
if v.CLI != BuildVersion {
|
||
|
t.Fatalf("expected %s, got %s", BuildVersion, v.CLI)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestNewCLIVersion(t *testing.T) {
|
||
|
v := NewCLIVersion("v1.0.0")
|
||
|
if v == nil {
|
||
|
t.Fatal("expected a version object, got nil")
|
||
|
}
|
||
|
if v.CLI != "v1.0.0" {
|
||
|
t.Fatalf("expected v1.0.0, got %s", v.CLI)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestSetVersions(t *testing.T) {
|
||
|
var one int64 = 1
|
||
|
var zero int64 = 0
|
||
|
tt := []struct {
|
||
|
name string
|
||
|
in string
|
||
|
out string
|
||
|
major *int64
|
||
|
minor *int64
|
||
|
}{
|
||
|
{"valid semver without v", "1.0.1-alpha01", "v1.0.1-alpha01", &one, &zero},
|
||
|
{"valid semver with v", "v1.0.1-alpha01", "v1.0.1-alpha01", &one, &zero},
|
||
|
{"invalid semver", "dev", "dev", nil, nil},
|
||
|
{"invalid semver", "build-system-1234abc", "build-system-1234abc", nil, nil},
|
||
|
}
|
||
|
|
||
|
for _, tc := range tt {
|
||
|
t.Run(tc.name, func(t *testing.T) {
|
||
|
v := &Version{}
|
||
|
v.SetCLIVersion(tc.in)
|
||
|
v.SetServerVersion(tc.in)
|
||
|
if v.CLI != tc.out {
|
||
|
t.Fatalf("expected version to be %s, got %s", tc.out, v.CLI)
|
||
|
}
|
||
|
if v.Server != tc.out {
|
||
|
t.Fatalf("expected version to be %s, got %s", tc.out, v.Server)
|
||
|
}
|
||
|
if v.CLISemver == nil {
|
||
|
if tc.major != nil {
|
||
|
t.Fatalf("expected semver to parse, but did not")
|
||
|
}
|
||
|
} else {
|
||
|
if v.CLISemver.Major() != *(tc.major) {
|
||
|
t.Fatalf("expected major to be %d, got %d", *(tc.major), v.CLISemver.Major())
|
||
|
}
|
||
|
}
|
||
|
if v.ServerSemver == nil {
|
||
|
if tc.major != nil {
|
||
|
t.Fatalf("expected semver to parse, but did not")
|
||
|
}
|
||
|
} else {
|
||
|
if v.ServerSemver.Major() != *(tc.major) {
|
||
|
t.Fatalf("expected major to be %d, got %d", *(tc.major), v.ServerSemver.Major())
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|