2020-04-07 12:23:20 +03:00
|
|
|
package console
|
2018-07-04 15:43:52 +03:00
|
|
|
|
2020-04-07 12:23:20 +03:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-06-16 14:44:15 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/v2/version"
|
2020-04-07 12:23:20 +03:00
|
|
|
)
|
2018-07-04 15:43:52 +03:00
|
|
|
|
|
|
|
func TestGetConsoleTemplateVersion(t *testing.T) {
|
|
|
|
tt := []struct {
|
|
|
|
name string
|
|
|
|
server string
|
|
|
|
tv string
|
|
|
|
}{
|
|
|
|
{"untagged server version", "some-random-version", unversioned},
|
|
|
|
{"no server version", "", preReleaseVersion},
|
|
|
|
{"tagged server version", "v1.2.4", "v1.2"},
|
|
|
|
{"tagged server version without v", "2.3.4", "v2.3"},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tt {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2020-04-07 12:23:20 +03:00
|
|
|
v := &version.Version{}
|
2018-07-04 15:43:52 +03:00
|
|
|
v.SetServerVersion(tc.server)
|
2021-06-04 10:27:34 +03:00
|
|
|
templateProvider := NewDefaultTemplateProvider("test", "test", ConsoleFS)
|
2020-04-07 12:23:20 +03:00
|
|
|
tv := templateProvider.GetTemplateVersion(v)
|
2018-07-04 15:43:52 +03:00
|
|
|
if tv != tc.tv {
|
|
|
|
t.Fatalf("expected tv '%v', got '%v'", tc.tv, tv)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetConsoleAssetsVersion(t *testing.T) {
|
|
|
|
tt := []struct {
|
|
|
|
name string
|
|
|
|
server string
|
|
|
|
tv string
|
|
|
|
}{
|
2019-05-16 10:45:29 +03:00
|
|
|
{"untagged server version", "some-random-version", "versioned/some-random-version"},
|
2018-07-04 15:43:52 +03:00
|
|
|
{"no server version", "", preReleaseVersion},
|
2019-05-16 10:45:29 +03:00
|
|
|
{"tagged server version", "v1.2.4", "channel/stable/v1.2"},
|
|
|
|
{"tagged server version without v", "2.3.4", "channel/stable/v2.3"},
|
|
|
|
{"tagged alpha release without .", "v1.0.0-alpha45", "channel/alpha/v1.0"},
|
|
|
|
{"tagged beta release with .", "v1.0.0-beta.01", "channel/beta/v1.0"},
|
|
|
|
{"tagged rc release with .", "v2.3.1-rc.11", "channel/rc/v2.3"},
|
2020-03-04 17:40:47 +03:00
|
|
|
{"tagged rj release with .", "v1.2.0-rj.1", "channel/rj/v1.2"},
|
2021-05-04 14:58:55 +03:00
|
|
|
{"tagged cloud stable", "v2.0.0-cloud.9", "channel/stable/v2.0"},
|
|
|
|
{"tagged pro stable", "v2.0.0-pro.9", "channel/stable/v2.0"},
|
|
|
|
{"tagged pro alpha", "v2.0.0-alpha.pro.9", "channel/alpha/v2.0"},
|
|
|
|
{"tagged cloud alpha", "v2.0.0-alpha.cloud.9", "channel/alpha/v2.0"},
|
2018-07-04 15:43:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tt {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2020-04-07 12:23:20 +03:00
|
|
|
v := &version.Version{}
|
2018-07-04 15:43:52 +03:00
|
|
|
v.SetServerVersion(tc.server)
|
2021-06-04 10:27:34 +03:00
|
|
|
templateProvider := NewDefaultTemplateProvider("test", "test", ConsoleFS)
|
2020-04-07 12:23:20 +03:00
|
|
|
tv := templateProvider.GetAssetsVersion(v)
|
2018-07-04 15:43:52 +03:00
|
|
|
if tv != tc.tv {
|
|
|
|
t.Fatalf("expected tv '%v', got '%v'", tc.tv, tv)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|