mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
53749aa796
We bake the version number into the binary, which means that changing it causes a lot of files to rebuild (also thanks to Template Haskell). We can avoid this by simply using a dummy value which does not change. When releasing, we still use the Git tag. This should speed up the server build a lot, most of the time. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8916 GitOrigin-RevId: 7e5f9d4d582dba3eecab52fd37a216cadefba941
75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
package version
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestNewCLIVersionWithSemver(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 TestNewCLIVersionWithDev(t *testing.T) {
|
|
v := NewCLIVersion("dev")
|
|
if v == nil {
|
|
t.Fatal("expected a version object, got nil")
|
|
}
|
|
if v.CLI != "dev" {
|
|
t.Fatalf("expected %s, got %s", "dev", 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())
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|