From cc50af7c3d712c140811fcc21f3425e4b3f98b9f Mon Sep 17 00:00:00 2001 From: MOREL Matthieu Date: Mon, 26 Apr 2021 07:41:43 +0200 Subject: [PATCH] Integration tests for enterprise, deletion of unused env variables in community edition integration tests --- .../integration-test-enterprise.yaml | 52 +++++++++++++++++++ .github/workflows/integration-test.yaml | 2 - cmd/common_test.go | 45 +++++++++++----- 3 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/integration-test-enterprise.yaml diff --git a/.github/workflows/integration-test-enterprise.yaml b/.github/workflows/integration-test-enterprise.yaml new file mode 100644 index 000000000..e616226b3 --- /dev/null +++ b/.github/workflows/integration-test-enterprise.yaml @@ -0,0 +1,52 @@ +name: "Integration Test : Enterprise" + +on: [push, pull_request] + +jobs: + test: + continue-on-error: true + strategy: + matrix: + kong_version: + - "enterprise-1.3.0.2" + - "enterprise-1.5.0.9" + - "enterprise-2.1.4.4" + - "enterprise-2.2.1.0" + - "enterprise-2.3.2.0" + env: + KONG_VERSION: ${{ matrix.kong_version }} + KONG_ENTERPRISE_REPO_USERNAME: ${{ secrets.KONG_ENTERPRISE_REPO_USERNAME }} + KONG_ENTERPRISE_REPO_PASSSWORD: ${{ secrets.KONG_ENTERPRISE_REPO_PASSSWORD }} + KONG_LICENSE_DATA: ${{ secrets.KONG_LICENSE_DATA }} + KONG_ANONYMOUS_REPORTS: "off" + KONG_ADMIN_TOKEN: kong + runs-on: ubuntu-latest + services: + postgres: + image: postgres:11.6-alpine + ports: + - 5432:5432 + # needed because the postgres container does not provide a healthcheck + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + steps: + - name: Setup go + uses: actions/setup-go@v2 + with: + go-version: "^1.16" + - name: Checkout repository + uses: actions/checkout@v2 + - name: Setup Postgres + run: | + psql -c 'create database kong;' -U postgres -h 127.0.0.1 -p 5432 + psql -c 'create user kong;' -U postgres -h 127.0.0.1 -p 5432 + psql -c 'GRANT ALL PRIVILEGES ON DATABASE "kong" to kong;' -U postgres -h 127.0.0.1 -p 5432 + - name: Setup Kong + run: make setup-kong + - name: Run tests + run: make integration-test-coverage + - name: Upload Code Coverage + uses: codecov/codecov-action@v1 + with: + name: codecov-${{ matrix.kong_version }} + flags: ${{ matrix.kong_version }},integration,enterprise + fail_ci_if_error: true diff --git a/.github/workflows/integration-test.yaml b/.github/workflows/integration-test.yaml index 6a0cc43aa..49a8162af 100644 --- a/.github/workflows/integration-test.yaml +++ b/.github/workflows/integration-test.yaml @@ -18,8 +18,6 @@ jobs: - "2.3.0" env: KONG_VERSION: ${{ matrix.kong_version }} - KONG_ENTERPRISE_REPO_USERNAME: ${{ secrets.KONG_ENTERPRISE_REPO_USERNAME }} - KONG_ENTERPRISE_REPO_PASSSWORD: ${{ secrets.KONG_ENTERPRISE_REPO_PASSSWORD }} KONG_LICENSE_DATA: ${{ secrets.KONG_LICENSE_DATA }} KONG_ANONYMOUS_REPORTS: "off" runs-on: ubuntu-latest diff --git a/cmd/common_test.go b/cmd/common_test.go index 4fb093598..7954b0c1e 100644 --- a/cmd/common_test.go +++ b/cmd/common_test.go @@ -17,8 +17,11 @@ var ( defaultCtx = context.Background() ) -func Test_kongVersion(T *testing.T) { +func Test_kongVersion_Community(T *testing.T) { kongVersionEnv, _ := os.LookupEnv("KONG_VERSION") + if strings.Contains(kongVersionEnv, "enterprise") { + T.Skip() + } var expectedVersion = semver.MustParse(kongVersionEnv) var config = NewTestClientConfig("") version, err := kongVersion(defaultCtx, config) @@ -27,21 +30,35 @@ func Test_kongVersion(T *testing.T) { assert.NotNil(version) assert.Equal(version.Major, expectedVersion.Major, "The two version should have the same major") assert.Equal(version.Minor, expectedVersion.Minor, "The two version should have the same minor") +} - if strings.Contains(kongVersionEnv, "enterprise") { - T.Log("Enterprise test Kong") - client, err := utils.GetKongClient(config) - ws := &kong.Workspace{ - Name: kong.String("test"), - } - client.Workspaces.Create(defaultCtx, ws) - config = NewTestClientConfig(*ws.Name) - workspaceversion, err := kongVersion(defaultCtx, config) - assert.Nil(err) - assert.NotNil(workspaceversion) - assert.Equal(workspaceversion.Major, expectedVersion.Major, "The two version should have the same major") - assert.Equal(workspaceversion.Minor, expectedVersion.Minor, "The two version should have the same minor") +func Test_kongVersion_Enterprise(T *testing.T) { + kongVersionEnv, _ := os.LookupEnv("KONG_VERSION") + if !strings.Contains(kongVersionEnv, "enterprise") { + T.Skip() } + kongVersionEnv = strings.Replace(kongVersionEnv, "enterprise-", "", 1) + var expectedVersion = semver.MustParse(kongVersionEnv) + var config = NewTestClientConfig("") + version, err := kongVersion(defaultCtx, config) + assert := assert.New(T) + assert.Nil(err) + assert.NotNil(version) + assert.Equal(version.Major, expectedVersion.Major, "The two version should have the same major") + assert.Equal(version.Minor, expectedVersion.Minor, "The two version should have the same minor") + + client, err := utils.GetKongClient(config) + ws := &kong.Workspace{ + Name: kong.String("test"), + } + client.Workspaces.Create(defaultCtx, ws) + config = NewTestClientConfig(*ws.Name) + workspaceversion, err := kongVersion(defaultCtx, config) + assert.Nil(err) + assert.NotNil(workspaceversion) + assert.Equal(workspaceversion.Major, expectedVersion.Major, "The two version should have the same major") + assert.Equal(workspaceversion.Minor, expectedVersion.Minor, "The two version should have the same minor") + } func NewTestClientConfig(workspace string) utils.KongClientConfig {