cli(test): refactor integration test metadata directory (#4491)

This commit is contained in:
Aravind Shankar 2020-04-22 16:58:02 +05:30 committed by GitHub
parent ae11e9b557
commit 455b78552d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 64 additions and 34 deletions

View File

@ -33,7 +33,7 @@ PID=$!
wait_for_port 8080
# test cli
HASURA_GRAPHQL_TEST_ENDPOINT="http://localhost:8080" TEST_TAGS="latest_release" make test
HASURA_GRAPHQL_TEST_ENDPOINT="http://localhost:8080" make test
# kill the running server
kill -s INT $PID
@ -47,5 +47,5 @@ PID=$!
wait_for_port 8080
# test cli
HASURA_GRAPHQL_TEST_ENDPOINT="http://localhost:8080" HASURA_GRAPHQL_TEST_ADMIN_SECRET="abcd" TEST_TAGS="latest_release" make test
HASURA_GRAPHQL_TEST_ENDPOINT="http://localhost:8080" HASURA_GRAPHQL_TEST_ADMIN_SECRET="abcd" make test
kill -s INT $PID

View File

@ -35,7 +35,7 @@ func TestMetadataCmd(t *testing.T, ec *cli.ExecutionContext) {
},
nil,
"",
filepath.Join(currDir, getMetadataDir(), "1_metadata.yaml"),
filepath.Join(currDir, getMetadataDir(ec.Version.ServerSemver), "1_metadata.yaml"),
},
{
"metadata-apply",
@ -44,7 +44,7 @@ func TestMetadataCmd(t *testing.T, ec *cli.ExecutionContext) {
ActionType: "apply",
},
nil,
filepath.Join(currDir, getMetadataDir(), "2_metadata.yaml"),
filepath.Join(currDir, getMetadataDir(ec.Version.ServerSemver), "2_metadata.yaml"),
"",
},
{
@ -55,7 +55,7 @@ func TestMetadataCmd(t *testing.T, ec *cli.ExecutionContext) {
},
nil,
"",
filepath.Join(currDir, getMetadataDir(), "2_metadata.yaml"),
filepath.Join(currDir, getMetadataDir(ec.Version.ServerSemver), "2_metadata.yaml"),
},
{
"metadata-clear",
@ -75,13 +75,13 @@ func TestMetadataCmd(t *testing.T, ec *cli.ExecutionContext) {
},
nil,
"",
filepath.Join(currDir, getMetadataDir(), "1_metadata.yaml"),
filepath.Join(currDir, getMetadataDir(ec.Version.ServerSemver), "1_metadata.yaml"),
},
{
"metadata-diff",
&commands.MetadataDiffOptions{
EC: ec,
Args: []string{filepath.Join(currDir, getMetadataDir(), "2_metadata.yaml")},
Args: []string{filepath.Join(currDir, getMetadataDir(ec.Version.ServerSemver), "2_metadata.yaml")},
Output: new(bytes.Buffer),
},
nil,

View File

@ -1,7 +1,29 @@
//+build !latest_release
package v1
func getMetadataDir() string {
return "v1/metadata"
import (
"fmt"
"os"
"path/filepath"
"github.com/Masterminds/semver"
)
const (
metadataDirPrefix = "v1/metadata"
)
func getMetadataDir(serverVersion *semver.Version) string {
var version string
if serverVersion == nil {
version = "latest"
} else {
currDir, _ := os.Getwd()
versionDir := fmt.Sprintf("v%d.%d", serverVersion.Major(), serverVersion.Minor())
if _, err := os.Stat(filepath.Join(currDir, metadataDirPrefix, versionDir)); err != nil {
version = "latest"
} else {
version = versionDir
}
}
return filepath.Join(metadataDirPrefix, version)
}

View File

@ -1,7 +0,0 @@
//+build latest_release
package v1
func getMetadataDir() string {
return "v1/metadata_latest"
}

View File

@ -34,7 +34,7 @@ func TestMetadataCmd(t *testing.T, ec *cli.ExecutionContext) {
},
nil,
"",
filepath.Join(currDir, getMetadataDir(), "1_metadata"),
filepath.Join(currDir, getMetadataDir(ec.Version.ServerSemver), "1_metadata"),
},
{
"metadata-apply",
@ -43,7 +43,7 @@ func TestMetadataCmd(t *testing.T, ec *cli.ExecutionContext) {
ActionType: "apply",
},
nil,
filepath.Join(currDir, getMetadataDir(), "2_metadata"),
filepath.Join(currDir, getMetadataDir(ec.Version.ServerSemver), "2_metadata"),
"",
},
{
@ -54,7 +54,7 @@ func TestMetadataCmd(t *testing.T, ec *cli.ExecutionContext) {
},
nil,
"",
filepath.Join(currDir, getMetadataDir(), "2_metadata"),
filepath.Join(currDir, getMetadataDir(ec.Version.ServerSemver), "2_metadata"),
},
{
"metadata-clear",
@ -74,13 +74,13 @@ func TestMetadataCmd(t *testing.T, ec *cli.ExecutionContext) {
},
nil,
"",
filepath.Join(currDir, getMetadataDir(), "1_metadata"),
filepath.Join(currDir, getMetadataDir(ec.Version.ServerSemver), "1_metadata"),
},
{
"metadata-diff",
&commands.MetadataDiffOptions{
EC: ec,
Args: []string{filepath.Join(currDir, getMetadataDir(), "1_metadata")},
Args: []string{filepath.Join(currDir, getMetadataDir(ec.Version.ServerSemver), "1_metadata")},
Output: new(bytes.Buffer),
},
nil,

View File

@ -1,7 +1,29 @@
//+build !latest_release
package v2
func getMetadataDir() string {
return "v2/metadata"
import (
"fmt"
"os"
"path/filepath"
"github.com/Masterminds/semver"
)
const (
metadataDirPrefix = "v2/metadata"
)
func getMetadataDir(serverVersion *semver.Version) string {
var version string
if serverVersion == nil {
version = "latest"
} else {
currDir, _ := os.Getwd()
versionDir := fmt.Sprintf("v%d.%d", serverVersion.Major(), serverVersion.Minor())
if _, err := os.Stat(filepath.Join(currDir, metadataDirPrefix, versionDir)); err != nil {
version = "latest"
} else {
version = versionDir
}
}
return filepath.Join(metadataDirPrefix, version)
}

View File

@ -1,7 +0,0 @@
//+build latest_release
package v2
func getMetadataDir() string {
return "v2/metadata_latest"
}