Skip to content

Commit ebc01c2

Browse files
scriptnullscriptonist
authored andcommitted
cli, ci: enables docker based tests
Co-authored-by: Aravind K P <8335904+scriptonist@users.noreply.github.com> GitOrigin-RevId: d7a53e5
1 parent 489835e commit ebc01c2

44 files changed

Lines changed: 229 additions & 1190 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.circleci/config.yml‎

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -323,33 +323,34 @@ jobs:
323323
command: /build/_server_output/graphql-engine-tests unit
324324

325325
test_cli_with_last_release:
326-
docker:
327-
- image: hasura/graphql-engine-cli-builder:20210310
328-
- image: circleci/postgres:10-alpine
329-
environment:
330-
POSTGRES_USER: gql_test
331-
POSTGRES_DB: gql_test
326+
machine:
327+
image: ubuntu-2004:202101-01
332328
working_directory: ~/graphql-engine
333329
steps:
330+
- run:
331+
name: create /build directory
332+
command: |
333+
sudo mkdir /build
334+
sudo chmod 777 /build
334335
- attach_workspace:
335336
at: /build
336337
- *skip_job_on_ciignore
337338
- checkout
338-
- restore_cache:
339-
keys:
340-
- cli-gopkg-{{ checksum "cli/go.mod" }}-{{ checksum "cli/go.sum" }}
339+
- run:
340+
name: install deps
341+
command: |
342+
sudo .circleci/install-cli-builder-deps.sh
341343
- run:
342344
name: get cli dependencies
343345
working_directory: cli
344346
command: make deps
345-
- save_cache:
346-
key: cli-gopkg-{{ checksum "cli/go.mod" }}-{{ checksum "cli/go.sum" }}
347-
paths:
348-
- /go/pkg
349-
- *wait_for_postgres
350347
- run:
351348
name: test cli
352-
command: .circleci/test-cli-with-last-release.sh
349+
working_directory: cli
350+
command: |
351+
export HASURA_TEST_CLI_HGE_DOCKER_TAG=$(curl https://releases.hasura.io/graphql-engine | jq -r ".latest")
352+
make integration_tests_config_v2
353+
HASURA_GRAPHQL_TEST_ADMIN_SECRET="abcd" make integration_tests_config_v2
353354
- store_artifacts:
354355
path: /build/_cli_output
355356
destination: cli
@@ -392,14 +393,9 @@ jobs:
392393
paths:
393394
- _cli_ext_output
394395

395-
# test and build cli
396-
test_and_build_cli:
396+
build_cli:
397397
docker:
398398
- image: hasura/graphql-engine-cli-builder:20210310
399-
- image: circleci/postgres:10-alpine
400-
environment:
401-
POSTGRES_USER: gql_test
402-
POSTGRES_DB: gql_test
403399
working_directory: ~/graphql-engine
404400
steps:
405401
- attach_workspace:
@@ -409,10 +405,6 @@ jobs:
409405
- restore_cache:
410406
keys:
411407
- cli-gopkg-{{ checksum "cli/go.mod" }}-{{ checksum "cli/go.sum" }}
412-
- *wait_for_postgres
413-
- run:
414-
name: test cli
415-
command: .circleci/test-cli.sh
416408
- run:
417409
name: build cli
418410
working_directory: cli
@@ -432,6 +424,38 @@ jobs:
432424
paths:
433425
- _cli_output
434426

427+
test_cli:
428+
machine:
429+
image: ubuntu-2004:202101-01
430+
working_directory: ~/graphql-engine
431+
steps:
432+
- run:
433+
name: create /build directory
434+
command: |
435+
sudo mkdir /build
436+
sudo chmod 777 /build
437+
- attach_workspace:
438+
at: /build
439+
- *skip_job_on_ciignore
440+
- checkout
441+
- run:
442+
name: install deps
443+
command: |
444+
sudo .circleci/install-cli-builder-deps.sh
445+
- run:
446+
name: test cli
447+
working_directory: cli
448+
command: |
449+
chmod +x /build/_cli_output/binaries/cli-hasura-linux-amd64
450+
export SOURCE_IMAGE=$(docker load -i /build/_server_output/image.tar | grep "^Loaded image: " | sed "s/Loaded image: //g")
451+
echo "SOURCE_IMAGE = $SOURCE_IMAGE"
452+
export HASURA_TEST_CLI_HGE_DOCKER_TAG=$(echo "$SOURCE_IMAGE" | sed "s/.*:\(.*\)$/\1/")
453+
echo "HASURA_TEST_CLI_HGE_DOCKER_TAG = $HASURA_TEST_CLI_HGE_DOCKER_TAG"
454+
make test-all
455+
export HASURA_GRAPHQL_TEST_ADMIN_SECRET="abcd"
456+
export HASURA_GRAPHQL_ADMIN_SECRET="abcd"
457+
make test-all
458+
435459
test_and_build_cli_migrations:
436460
docker:
437461
- image: hasura/graphql-engine-cli-migrations-builder:20200415
@@ -701,21 +725,26 @@ workflows:
701725
- test_server_pg_9.5
702726
- server_unit_tests
703727
- test_server_upgrade
704-
- test_and_build_cli:
728+
- build_cli:
705729
<<: *filter_only_vtags
706730
requires:
707731
- test_and_build_cli_ext
708-
- build_server
732+
- test_cli:
733+
<<: *filter_only_vtags
734+
requires:
735+
- build_cli
736+
- build_image
709737
- test_and_build_cli_migrations:
710738
<<: *filter_only_vtags
711739
requires:
712740
- build_image
713-
- test_and_build_cli
741+
- build_cli
714742
- test_console:
715743
<<: *filter_only_vtags
716744
requires:
717745
- build_console
718-
- test_and_build_cli
746+
- build_cli
747+
- build_server
719748
- test_cli_with_last_release
720749
- deploy:
721750
<<: *filter_only_vtags_channel_branches
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
5+
apt-get update && apt-get install -y \
6+
xz-utils netcat libpq5 postgresql-client jq zip \
7+
&& curl -s https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list \
8+
&& curl -s https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
9+
&& echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list \
10+
&& curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - \
11+
&& apt-get update \
12+
&& ACCEPT_EULA=Y apt-get install -y ca-certificates libkrb5-3 libpq5 libnuma1 unixodbc-dev msodbcsql17 apt-transport-https gnupg google-cloud-sdk hub \
13+
&& apt-get -y auto-remove \
14+
&& rm -rf /var/lib/apt/lists/*
15+
16+
17+
# install go1.16
18+
19+
wget https://golang.org/dl/go1.16.3.linux-amd64.tar.gz
20+
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.16.3.linux-amd64.tar.gz
21+
export PATH=$PATH:/usr/local/go/bin
22+
go version

‎.circleci/test-cli-with-last-release.sh‎

Lines changed: 0 additions & 52 deletions
This file was deleted.

‎.circleci/test-cli.sh‎

Lines changed: 0 additions & 45 deletions
This file was deleted.

‎cli/Makefile‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ OUTPUT_DIR := _output
77

88
HAS_GOX := $(shell command -v gox;)
99
HAS_PKGER := $(shell command -v pkger;)
10+
HAS_GINKGO := $(shell command -v ginkgo;)
1011

1112
ifeq (${CI}, true)
1213
CLI_EXT_BIN_DIR := "/build/_cli_ext_output"
@@ -68,12 +69,21 @@ copy-cli-ext: clean-cli-ext
6869
# run tests
6970
.PHONY: test
7071
test: copy-cli-ext
71-
go test -ldflags "-X github.com/hasura/graphql-engine/cli/version.BuildVersion=$(VERSION)" -v -tags="${TEST_TAGS}" `go list ./... | grep -v integration_test`
72+
if [ -z "${HASURA_TEST_CLI_HGE_DOCKER_TAG}" ]; then echo "Please set HASURA_TEST_CLI_HGE_DOCKER_TAG env for populating testutil.HasuraVersion and run test"; exit 1; fi
73+
go test -ldflags "-X github.com/hasura/graphql-engine/cli/version.BuildVersion=$(VERSION)" -v -tags="${TEST_TAGS}" `go list ./... | grep -v integration_test | grep -v commands`
7274
integration_tests_config_v3: copy-cli-ext
75+
if [ -z "${HASURA_TEST_CLI_HGE_DOCKER_TAG}" ]; then echo "Please set HASURA_TEST_CLI_HGE_DOCKER_TAG env for populating testutil.HasuraVersion and run test"; exit 1; fi
7376
go test -ldflags "-X github.com/hasura/graphql-engine/cli/version.BuildVersion=$(VERSION)" -v -tags="${TEST_TAGS}" -run Commands/config=v3 ./integration_test
7477
integration_tests_config_v2: copy-cli-ext
78+
if [ -z "${HASURA_TEST_CLI_HGE_DOCKER_TAG}" ]; then echo "Please set HASURA_TEST_CLI_HGE_DOCKER_TAG env for populating testutil.HasuraVersion and run test"; exit 1; fi
7579
go test -ldflags "-X github.com/hasura/graphql-engine/cli/version.BuildVersion=$(VERSION)" -v -tags="${TEST_TAGS}" -run Commands/config=v2 ./integration_test
76-
test-all: test integration_tests_config_v2 integration_tests_config_v3
80+
test-e2e:
81+
ifndef HAS_GINKGO
82+
cd ~ && go get github.com/onsi/ginkgo/ginkgo && cd -
83+
endif
84+
cd commands && ginkgo -v --failFast
85+
86+
test-all: test integration_tests_config_v2 integration_tests_config_v3 test-e2e
7787
# clean the output directory
7888
.PHONY: clean
7989
clean:

‎cli/commands/commands_test.go‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"testing"
66

77
"github.com/hasura/graphql-engine/cli"
8-
"github.com/hasura/graphql-engine/cli/internal/testutil"
98
"gopkg.in/yaml.v2"
109

1110
. "github.com/onsi/ginkgo"
@@ -17,11 +16,6 @@ const (
1716
)
1817

1918
func TestE2e(t *testing.T) {
20-
BeforeSuite(func() {
21-
if testutil.SkipDockerTests {
22-
t.Skip()
23-
}
24-
})
2519
RegisterFailHandler(Fail)
2620
RunSpecs(t, "e2e testsuite")
2721
}

‎cli/commands/metadata_apply_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ var _ = Describe("metadata_apply", func() {
6161

6262
Context("metadata dry run ", func() {
6363
args := strings.Join([]string{
64-
"hasura", "metadata", "export", "-o", "json",
64+
testutil.CLIBinaryPath, "metadata", "export", "-o", "json",
6565
"|", "jq", `'.sources[0].configuration.connection_info.pool_settings.max_connections = 51'`,
66-
"|", "hasura", "md", "apply", "--dry-run",
66+
"|", testutil.CLIBinaryPath, "md", "apply", "--dry-run",
6767
}, " ")
6868
cmd := exec.Command("bash", "-c", args)
6969
cmd.Dir = dirName
@@ -78,9 +78,9 @@ var _ = Describe("metadata_apply", func() {
7878
})
7979
Context("metadata apply metadata from pipe", func() {
8080
args := strings.Join([]string{
81-
"hasura", "metadata", "export", "-o", "json",
81+
testutil.CLIBinaryPath, "metadata", "export", "-o", "json",
8282
"|", "jq", `'.sources[0].configuration.connection_info.pool_settings.max_connections = 51'`,
83-
"|", "hasura", "md", "apply",
83+
"|", testutil.CLIBinaryPath, "md", "apply",
8484
}, " ")
8585
cmd := exec.Command("bash", "-c", args)
8686
cmd.Dir = dirName

0 commit comments

Comments
 (0)