From 57ff6f11e257555d2f0812c2dd9eda1d8369f57f Mon Sep 17 00:00:00 2001 From: przemyslaw Date: Thu, 10 Oct 2024 14:48:29 +0200 Subject: [PATCH 1/6] extract test methods for easier reading --- .../test_reading_clickhouse_tables.go | 19 ++++++++++----- ci/it/testcases/test_transparent_proxy.go | 24 +++++++++++++------ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/ci/it/testcases/test_reading_clickhouse_tables.go b/ci/it/testcases/test_reading_clickhouse_tables.go index 279e0ed20..58d2107c3 100644 --- a/ci/it/testcases/test_reading_clickhouse_tables.go +++ b/ci/it/testcases/test_reading_clickhouse_tables.go @@ -28,32 +28,39 @@ func (a *ReadingClickHouseTablesIntegrationTestcase) SetupContainers(ctx context } func (a *ReadingClickHouseTablesIntegrationTestcase) RunTests(ctx context.Context, t *testing.T) error { + a.testBasicRequest(ctx, t) + a.testRandomThing(ctx, t) + return nil +} + +func (a *ReadingClickHouseTablesIntegrationTestcase) testBasicRequest(ctx context.Context, t *testing.T) { resp, err := a.RequestToQuesma(ctx, "GET", "/", nil) if err != nil { t.Fatalf("Failed to make GET request: %s", err) } defer resp.Body.Close() assert.Equal(t, 200, resp.StatusCode) - /*--------*/ +} + +func (a *ReadingClickHouseTablesIntegrationTestcase) testRandomThing(ctx context.Context, t *testing.T) { createTableQuery := "CREATE TABLE IF NOT EXISTS test_table (id UInt32, name String) ENGINE = Memory" - if _, err = a.ExecuteClickHouseStatement(ctx, createTableQuery); err != nil { - return err + if _, err := a.ExecuteClickHouseStatement(ctx, createTableQuery); err != nil { + t.Fatalf("Failed to create table: %s", err) } insertRowsQuery := "INSERT INTO test_table (id, name) VALUES (1, 'Alice'), (2, 'Bob'), (3, 'Charlie')" if _, err := a.ExecuteClickHouseStatement(ctx, insertRowsQuery); err != nil { - return err + t.Fatalf("Failed to insert rows: %s", err) } // This returns 500 Internal Server Error, but will be tackled in separate PR. // (The table has not yet been discovered by Quesma ) // ERR quesma/quesma/quesma.go:198 > quesma request failed: Q2002: Missing table. Table: test_table: can't load test_table table opaque_id= path=/test_table/_search reason="Missing table." request_id=01926654-b214-7e1d-944a-a7545cd7d419 - resp, err = a.RequestToQuesma(ctx, "GET", "/test_table/_search", []byte(`{"query": {"match_all": {}}}`)) + resp, err := a.RequestToQuesma(ctx, "GET", "/test_table/_search", []byte(`{"query": {"match_all": {}}}`)) if err != nil { t.Fatalf("Failed to make GET request: %s", err) } defer resp.Body.Close() assert.Equal(t, "Clickhouse", resp.Header.Get("X-Quesma-Source")) //assert.Equal(t, 200, resp.StatusCode) - return nil } diff --git a/ci/it/testcases/test_transparent_proxy.go b/ci/it/testcases/test_transparent_proxy.go index 1bbdb81a1..6501e2bbf 100644 --- a/ci/it/testcases/test_transparent_proxy.go +++ b/ci/it/testcases/test_transparent_proxy.go @@ -29,14 +29,23 @@ func (a *TransparentProxyIntegrationTestcase) SetupContainers(ctx context.Contex } func (a *TransparentProxyIntegrationTestcase) RunTests(ctx context.Context, t *testing.T) error { + a.testBasicRequest(ctx, t) + a.testIfCatHealthRequestReachesElasticsearch(ctx, t) + a.testIfIndexCreationWorks(ctx, t) + return nil +} + +func (a *TransparentProxyIntegrationTestcase) testBasicRequest(ctx context.Context, t *testing.T) { resp, err := a.RequestToQuesma(ctx, "GET", "/", nil) if err != nil { t.Fatalf("Failed to make GET request: %s", err) } defer resp.Body.Close() assert.Equal(t, 200, resp.StatusCode) - /* --------------------------- */ - resp, err = a.RequestToQuesma(ctx, "GET", "/_cat/health", nil) +} + +func (a *TransparentProxyIntegrationTestcase) testIfCatHealthRequestReachesElasticsearch(ctx context.Context, t *testing.T) { + resp, err := a.RequestToQuesma(ctx, "GET", "/_cat/health", nil) if err != nil { t.Fatalf("Failed to make GET request: %s", err) } @@ -48,20 +57,21 @@ func (a *TransparentProxyIntegrationTestcase) RunTests(ctx context.Context, t *t assert.Equal(t, 200, resp.StatusCode) assert.Equal(t, "Elasticsearch", resp.Header.Get("X-elastic-product")) assert.Contains(t, string(bodyBytes), "green") - /* --------------------------- */ - _, err = a.RequestToQuesma(ctx, "PUT", "/index_1", nil) +} + +func (a *TransparentProxyIntegrationTestcase) testIfIndexCreationWorks(ctx context.Context, t *testing.T) { + _, err := a.RequestToQuesma(ctx, "PUT", "/index_1", nil) _, err = a.RequestToQuesma(ctx, "PUT", "/index_2", nil) - resp, err = a.RequestToElasticsearch(ctx, "GET", "/_cat/indices", nil) + resp, err := a.RequestToElasticsearch(ctx, "GET", "/_cat/indices", nil) if err != nil { t.Fatalf("Failed to make GET request: %s", err) } defer resp.Body.Close() - bodyBytes, err = io.ReadAll(resp.Body) + bodyBytes, err := io.ReadAll(resp.Body) if err != nil { t.Fatalf("Failed to read response body: %s", err) } assert.Contains(t, string(bodyBytes), "index_1") assert.Contains(t, string(bodyBytes), "index_2") - return nil } From f7b60d6f7b7ab73e120a0ef1b4d4134f0d06f8e6 Mon Sep 17 00:00:00 2001 From: przemyslaw Date: Thu, 10 Oct 2024 15:34:42 +0200 Subject: [PATCH 2/6] run tests on push to `main` --- .github/workflows/integration-tests.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 04aae14f6..2659b5e3c 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -1,9 +1,8 @@ name: Integration tests on: -# #merge_group: -# push: -# branches: [ "main" ] + push: + branches: [ "main" ] workflow_dispatch: inputs: GIT_REF: From 5e68ffef852a0c7180b8cf7aba0944c1c560fa84 Mon Sep 17 00:00:00 2001 From: przemyslaw Date: Fri, 11 Oct 2024 08:12:03 +0200 Subject: [PATCH 3/6] slack notification --- .github/workflows/integration-tests.yml | 18 ++++++++++++++++-- .../test_reading_clickhouse_tables.go | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 2659b5e3c..b18ba6a7b 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -43,9 +43,23 @@ jobs: - name: Set environment variable run: echo "EXECUTING_ON_GITHUB_CI=true" >> $GITHUB_ENV + - name: Get last commit author + id: get_author + run: echo "::set-output name=author::$(git log -1 --pretty=format:'%an')" + - name: Run integration tests working-directory: ci/it -# env: -# EXECUTING_ON_GITHUB_CI: true run: go test -v + - name: Send Slack notification on failure + if: failure() + uses: slackapi/slack-github-action@v1.23.0 + with: + channel-id: ${{ secrets.SLACK_CHANNEL_ID }} + slack-message: | + :exclamation: *Integration tests failed.* FYSA @here + Author of the last commit: ${{ steps.get_author.outputs.author }} + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + + diff --git a/ci/it/testcases/test_reading_clickhouse_tables.go b/ci/it/testcases/test_reading_clickhouse_tables.go index 58d2107c3..99339e2d2 100644 --- a/ci/it/testcases/test_reading_clickhouse_tables.go +++ b/ci/it/testcases/test_reading_clickhouse_tables.go @@ -62,5 +62,5 @@ func (a *ReadingClickHouseTablesIntegrationTestcase) testRandomThing(ctx context } defer resp.Body.Close() assert.Equal(t, "Clickhouse", resp.Header.Get("X-Quesma-Source")) - //assert.Equal(t, 200, resp.StatusCode) + assert.Equal(t, 200, resp.StatusCode) // TODO INTENTIONAL FAILURE } From f5cf1ea1d173d271acbb93217f71f2e9c3875c0f Mon Sep 17 00:00:00 2001 From: przemyslaw Date: Fri, 11 Oct 2024 08:23:20 +0200 Subject: [PATCH 4/6] slack notification --- .github/workflows/integration-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index b18ba6a7b..866b31672 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -45,7 +45,7 @@ jobs: - name: Get last commit author id: get_author - run: echo "::set-output name=author::$(git log -1 --pretty=format:'%an')" + run: echo "::set-output name=author::$(git log -1 --pretty=format:'%an <%ae> sha1={%H}')" - name: Run integration tests working-directory: ci/it @@ -58,7 +58,7 @@ jobs: channel-id: ${{ secrets.SLACK_CHANNEL_ID }} slack-message: | :exclamation: *Integration tests failed.* FYSA @here - Author of the last commit: ${{ steps.get_author.outputs.author }} + Last commit by: ${{ steps.get_author.outputs.author }} env: SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} From 31f6bb76b655cb4865227d2e7dd81157e15b5362 Mon Sep 17 00:00:00 2001 From: przemyslaw Date: Fri, 11 Oct 2024 08:54:45 +0200 Subject: [PATCH 5/6] slack notification --- .github/workflows/integration-tests.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 866b31672..ef006de28 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -57,7 +57,18 @@ jobs: with: channel-id: ${{ secrets.SLACK_CHANNEL_ID }} slack-message: | - :exclamation: *Integration tests failed.* FYSA @here + :exclamation: *Integration tests failed.* :exclamation: @here + Last commit by: ${{ steps.get_author.outputs.author }} + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + + - name: Send Slack notification on success + if: success() + uses: slackapi/slack-github-action@v1.23.0 + with: + channel-id: ${{ secrets.SLACK_CHANNEL_ID }} + slack-message: | + :white_check_mark: *Integration tests passed.* Good job team! Last commit by: ${{ steps.get_author.outputs.author }} env: SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} From a887ea1f9c663b37d0a84f4b029ebc53c18ae8b4 Mon Sep 17 00:00:00 2001 From: przemyslaw Date: Fri, 11 Oct 2024 09:03:31 +0200 Subject: [PATCH 6/6] slack notification --- .github/workflows/integration-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index ef006de28..dce91702b 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -57,7 +57,7 @@ jobs: with: channel-id: ${{ secrets.SLACK_CHANNEL_ID }} slack-message: | - :exclamation: *Integration tests failed.* :exclamation: @here + :exclamation: *Integration tests failed.* :exclamation: @channel Last commit by: ${{ steps.get_author.outputs.author }} env: SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}