Skip to content

Commit

Permalink
integration tests and unit tests separated
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Sep 8, 2023
1 parent 3037c95 commit 1cfcfa9
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 14 deletions.
55 changes: 54 additions & 1 deletion .github/codecov.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,55 @@
# Find more at https://docs.codecov.com/docs/codecovyml-reference
codecov:
bot: "Codecov Bot"
max_report_age: 12
require_ci_to_pass: yes
notify:
after_n_builds: 1
wait_for_ci: yes

# Layout of the PR comment produced by Codecov bot
comment:
layout: "header, diff, flags, components, files"

# Find more at https://docs.codecov.com/docs/ignoring-paths
ignore:
- "**/*.deepcopy.go" # ignore controller-gen generated code
- "**/*.deepcopy.go" # ignore controller-gen generated code

flag_management:
individual_flags:
- name: unit
paths:
- pkg/**
- api/**
carryforward: true
- name: integration
paths:
- controllers/**
carryforward: true

component_management:
individual_components:
- component_id: api-v1alpha1
name: api/v1alpha1 (u)
paths:
- api/v1alpha1
- component_id: helpers
name: pkg/helpers (u)
paths:
- pkg/helpers
- component_id: log
name: pkg/log (u)
paths:
- pkg/log
- component_id: reconcilers
name: pkg/reconcilers (u)
paths:
- pkg/reconcilers
- component_id: limitador
name: pkg/limitador (u)
paths:
- pkg/limitador
- component_id: controllers
name: controllers (i)
paths:
- controllers
49 changes: 38 additions & 11 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,59 @@ name: Tests

on:
push:
branches:
- '*'
branches: [ 'main' ]
pull_request:
branches:
- '*'
branches: [ '*' ]

jobs:
test:
name: Test
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Set up Go 1.20.x
uses: actions/setup-go@v4
with:
go-version: 1.20.x
id: go
- uses: actions/checkout@v3
- name: Run the tests
run: make test
- name: Upload coverage reports to Codecov
- name: Check out code
uses: actions/checkout@v3
- name: Run make test-unit
run: |
make test-unit
- name: Upload unit-test coverage reports to CodeCov # more at https://github.com/codecov/codecov-action
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unit
verbose: true
fail_ci_if_error: false
verbose: true
integration-tests:
name: Integration Tests
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Set up Go 1.20.x
uses: actions/setup-go@v4
with:
go-version: 1.20.x
id: go
- name: Check out code
uses: actions/checkout@v3
- name: Run integration tests
run: |
make test-integration
- name: Upload integration-test coverage reports to CodeCov # more at https://github.com/codecov/codecov-action
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: integration
fail_ci_if_error: false
verbose: true
verify-manifests:
name: Verify manifests
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ testbin

/catalog/limitador-operator-catalog
/catalog/limitador-operator-catalog.Dockerfile
/coverage/

# Vendor dependencies
vendor
19 changes: 17 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,23 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) $(ARCH_PARAM) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
.PHONY: clean-cov
clean-cov: ## Remove coverage reports
rm -rf coverage

.PHONY: test
test: test-unit test-integration ## Run all tests

test-integration: clean-cov generate fmt vet envtest ## Run Integration tests.
mkdir -p coverage/integration
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) $(ARCH_PARAM) use $(ENVTEST_K8S_VERSION) -p path)" go test ./controllers... -coverprofile $(PROJECT_PATH)/coverage/integration/cover.out -ginkgo.v -ginkgo.progress -v -timeout 0

ifdef TEST_NAME
test-unit: TEST_PATTERN := --run $(TEST_NAME)
endif
test-unit: clean-cov generate fmt vet ## Run Unit tests.
mkdir -p coverage/unit
go test ./pkg/... ./api/... -coverprofile $(PROJECT_PATH)/coverage/unit/cover.out -v -timeout 0 $(TEST_PATTERN)

##@ Build

Expand Down

0 comments on commit 1cfcfa9

Please sign in to comment.