diff --git a/.github/workflows/bdd.yaml b/.github/workflows/bdd.yaml new file mode 100644 index 00000000..0cba005b --- /dev/null +++ b/.github/workflows/bdd.yaml @@ -0,0 +1,30 @@ +name: BDD tests + +on: + push: + branches: + - master + pull_request: + +jobs: + bdd: + runs-on: ubuntu-20.04 + strategy: + matrix: + go-version: + - "1.18" + name: BDD for Go ${{ matrix.go-version}} + steps: + - uses: actions/checkout@v4 + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + - name: Build project + run: make build + - name: Retrieve Docker compose file + run: wget -O docker-compose.yml https://raw.githubusercontent.com/RedHatInsights/insights-behavioral-spec/main/docker-compose.yml + - name: Retrieve BDD runner + run: wget -O bdd_runner.sh https://raw.githubusercontent.com/RedHatInsights/insights-behavioral-spec/main/run_in_docker.sh && chmod +x bdd_runner.sh + - name: Run BDD + run: ./bdd_runner.sh aggregator-tests . diff --git a/.github/workflows/gotests.yaml b/.github/workflows/gotests.yaml new file mode 100644 index 00000000..4ee85ab5 --- /dev/null +++ b/.github/workflows/gotests.yaml @@ -0,0 +1,47 @@ +name: Go tests + +on: + push: + branches: + - master + pull_request: + +jobs: + gotests: + runs-on: ubuntu-20.04 + strategy: + matrix: + go-version: + - "1.18" + - "1.19" + - "1.20" + - "1.21" + name: Tests for Go ${{ matrix.go-version}} + services: + postgres: + image: postgres + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + steps: + - uses: actions/checkout@v4 + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + - name: Print env vars + run: env + - name: Unit tests + run: make test + - name: Check code coverage + run: ./check_coverage.sh + - name: Display code coverage + run: make coverage diff --git a/.github/workflows/linters.yaml b/.github/workflows/linters.yaml new file mode 100644 index 00000000..03229c0d --- /dev/null +++ b/.github/workflows/linters.yaml @@ -0,0 +1,29 @@ +name: Go linters + +on: + push: + branches: + - master + pull_request: + +jobs: + golint: + runs-on: ubuntu-20.04 + strategy: + matrix: + go-version: + - "1.18" + - "1.19" + - "1.20" + - "1.21" + name: Linters for Go ${{ matrix.go-version}} + steps: + - uses: actions/checkout@v4 + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + - name: Build project + run: go build + - name: Style linters + run: make style diff --git a/.github/workflows/shellcheck.yaml b/.github/workflows/shellcheck.yaml new file mode 100644 index 00000000..f57217c2 --- /dev/null +++ b/.github/workflows/shellcheck.yaml @@ -0,0 +1,15 @@ +name: Shell check + +on: + push: + branches: + - master + pull_request: + +jobs: + shellcheck: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + - name: Shell check + run: ./shellcheck.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a124bde9..00000000 --- a/.travis.yml +++ /dev/null @@ -1,65 +0,0 @@ -# Copyright 2021, 2022, 2023 Red Hat, Inc -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -language: go -go: -- "1.20" - -services: - - postgresql - -jobs: - include: - - name: "Build 1.20" - stage: build - script: - - make - - stage: style - script: - - make style - - stage: unit tests - script: - - make test - - ./check_coverage.sh - - make coverage - after_success: - - env - - bash <(curl -s https://codecov.io/bash) - - stage: openapi-checks - services: - - docker - before_install: - - docker pull openapitools/openapi-generator-cli - script: - - docker run -v ${PWD}:/local openapitools/openapi-generator-cli validate -i /local/openapi.json - - stage: bdd tests - services: - - docker - before_script: - - make - - wget -O docker-compose.yml https://raw.githubusercontent.com/RedHatInsights/insights-behavioral-spec/main/docker-compose.yml - - wget -O bdd_runner.sh https://raw.githubusercontent.com/RedHatInsights/insights-behavioral-spec/main/run_in_docker.sh && chmod +x bdd_runner.sh - script: - - ./bdd_runner.sh aggregator-tests . - - stage: integration tests - script: - - make integration_tests - -stages: - - build - - style - - unit tests - - openapi-checks - - bdd tests - - integration tests diff --git a/docker-compose.yml b/docker-compose.yml index d371f9c5..3cc9a365 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,8 +18,9 @@ services: ports: - 5432:5432 image: registry.redhat.io/rhscl/postgresql-10-rhel7 + platform: linux/x86_64 environment: - POSTGRESQL_USER=user - POSTGRESQL_PASSWORD=password - - POSTGRESQL_ADMIN_PASSWORD=admin - - POSTGRESQL_DATABASE=aggregator \ No newline at end of file + - POSTGRESQL_ADMIN_PASSWORD=postgres + - POSTGRESQL_DATABASE=aggregator diff --git a/storage/storage_rules_test.go b/storage/storage_rules_test.go index 3cff8098..4708fa3b 100644 --- a/storage/storage_rules_test.go +++ b/storage/storage_rules_test.go @@ -536,7 +536,7 @@ func TestDBStorageVoteOnRuleDBExecError(t *testing.T) { err = mockStorage.VoteOnRule("non int", testdata.Rule1ID, testdata.ErrorKey1, testdata.OrgID, testdata.UserID, types.UserVoteNone, "") assert.Error(t, err) const sqliteErrMessage = "CHECK constraint failed: cluster_rule_user_feedback" - const postgresErrMessage = "pq: invalid input syntax for integer: \"non int\"" + const postgresErrMessage = "pq: invalid input syntax for type integer: \"non int\"" if err.Error() != sqliteErrMessage && !strings.HasPrefix(err.Error(), postgresErrMessage) { t.Fatalf("expected one of: \n%v\n%v\ngot:\n%v", sqliteErrMessage, postgresErrMessage, err.Error()) } diff --git a/storage/storage_test.go b/storage/storage_test.go index bf39798f..03446898 100644 --- a/storage/storage_test.go +++ b/storage/storage_test.go @@ -427,7 +427,7 @@ func TestDBStorageWriteReportForClusterExecError(t *testing.T) { assert.Error(t, err) const sqliteErrMessage = "CHECK constraint failed: report" - const postgresErrMessage = "pq: invalid input syntax for integer" + const postgresErrMessage = "pq: invalid input syntax for type integer" if err.Error() != sqliteErrMessage && !strings.HasPrefix(err.Error(), postgresErrMessage) { t.Fatalf("expected on of: \n%v\n%v\ngot:\n%v", sqliteErrMessage, postgresErrMessage, err.Error()) } @@ -614,7 +614,7 @@ func TestDBStorageNewPostgresqlError(t *testing.T) { }) err := s.Init() - assert.Contains(t, err.Error(), "no such host") + assert.Contains(t, err.Error(), "non-existing-host") } func mustWriteReport( diff --git a/unit-tests.sh b/unit-tests.sh index fe48c99e..d970dbbd 100755 --- a/unit-tests.sh +++ b/unit-tests.sh @@ -53,7 +53,7 @@ fi path_to_config=$(pwd)/config-devel.toml export INSIGHTS_RESULTS_AGGREGATOR_CONFIG_FILE="$path_to_config" export INSIGHTS_RESULTS_AGGREGATOR__TESTS_DB="postgres" -export INSIGHTS_RESULTS_AGGREGATOR__TESTS_DB_ADMIN_PASS="admin" +export INSIGHTS_RESULTS_AGGREGATOR__TESTS_DB_ADMIN_PASS="postgres" run_unit_tests if [ -z "$CI" ]; then