graphql-engine/cli/version/console_test.go
Shahidh K Muhammed 76ceb707f4
bundle console assets into server (close #516, close #521, close #2130) (#2192)
This PR builds console static assets into the server docker image at `/srv/console-assets`. When env var `HASURA_GRAPHQL_CONSOLE_ASSETS_DIR=/srv/console-assets` or flag `--console-assets-dir=/srv/console-assets` is set on the server, the files in this directory are served at `/console/assets/*`.

The console html template will have a variable called `cdnAssets: false` when this flag is set and it loads assets from server itself instead of CDN.

The assets are moved to a new bucket with a new naming scheme:

```
graphql-engine-cdn.hasura.io/console/assets/
   /common/{}
   /versioned/<version/{}
   /channel/<channel>/<version>/{}
```

Console served by CLI will still load assets from CDN - will fix that in the next release.
2019-05-16 13:15:29 +05:30

55 lines
1.4 KiB
Go

package version
import "testing"
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) {
v := &Version{}
v.SetServerVersion(tc.server)
tv := v.GetConsoleTemplateVersion()
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
}{
{"untagged server version", "some-random-version", "versioned/some-random-version"},
{"no server version", "", preReleaseVersion},
{"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"},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
v := &Version{}
v.SetServerVersion(tc.server)
tv := v.GetConsoleAssetsVersion()
if tv != tc.tv {
t.Fatalf("expected tv '%v', got '%v'", tc.tv, tv)
}
})
}
}