Skip to content

Commit

Permalink
Merge pull request #98 from Kuadrant/integration-tests
Browse files Browse the repository at this point in the history
integration tests and unit tests separated
  • Loading branch information
eguzki authored Sep 8, 2023
2 parents 3ddcadc + 0abd270 commit f600496
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 24 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 -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
30 changes: 20 additions & 10 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@ limitations under the License.
package controllers

import (
"os"
"path/filepath"
"testing"
"time"

limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1"
"github.com/kuadrant/limitador-operator/pkg/log"
"github.com/kuadrant/limitador-operator/pkg/reconcilers"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
"k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1"
"github.com/kuadrant/limitador-operator/pkg/log"
"github.com/kuadrant/limitador-operator/pkg/reconcilers"
//+kubebuilder:scaffold:imports
)

Expand All @@ -47,13 +51,6 @@ func TestAPIs(t *testing.T) {
}

var _ = BeforeSuite(func() {
logger := log.NewLogger(
log.SetLevel(log.DebugLevel),
log.SetMode(log.ModeDev),
log.WriteTo(GinkgoWriter),
).WithName("controller_test")
log.SetLogger(logger)

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
Expand Down Expand Up @@ -107,3 +104,16 @@ var _ = BeforeSuite(func() {
var _ = AfterSuite(func() {
By("tearing down the test environment")
})

func TestMain(m *testing.M) {
logger := log.NewLogger(
log.SetLevel(log.DebugLevel),
log.SetMode(log.ModeDev),
log.WriteTo(GinkgoWriter),
).WithName("controller_test")
log.SetLogger(logger)

logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

os.Exit(m.Run())
}
30 changes: 30 additions & 0 deletions doc/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,36 @@ make local-cleanup

## Run tests

### Unittests

```sh
make test-unit
```

Optionally, add `TEST_NAME` makefile variable to run specific test

```sh
make test-unit TEST_NAME=TestConstants
```

or even subtest

```sh
make test-unit TEST_NAME=TestLimitIndexEquals/empty_indexes_are_equal
```

### Integration tests

Run integration tests

```sh
make test-integration
```

### All tests

Run all tests

```sh
make test
```
Expand Down

0 comments on commit f600496

Please sign in to comment.