Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Feb 8, 2023
1 parent 067cd0e commit a759480
Show file tree
Hide file tree
Showing 5 changed files with 562 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,11 @@ test: test-unit test-integration ## Run all tests
test-integration: clean-cov generate fmt vet envtest ## Run Integration tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) $(ARCH_PARAM) use $(ENVTEST_K8S_VERSION) -p path)" USE_EXISTING_CLUSTER=true go test ./... -coverprofile $(PROJECT_PATH)/cover.out -tags integration -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.
go test ./... -coverprofile $(PROJECT_PATH)/cover.out -tags unit -v -timeout 0
go test ./... -coverprofile $(PROJECT_PATH)/cover.out -tags unit -v -timeout 0 $(TEST_PATTERN)

.PHONY: namespace
namespace: ## Creates a namespace where to deploy Kuadrant Operator
Expand Down
12 changes: 12 additions & 0 deletions doc/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@ make local-cleanup
make test-unit
```

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

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

or even subtest

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

### Integration tests

You need an active session open to a kubernetes cluster.
Expand Down
13 changes: 13 additions & 0 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ func SliceCopy[T any](s1 []T) []T {
return s2
}

func ReverseSlice[T any](input []T) []T {
inputLen := len(input)
output := make([]T, inputLen)

for i, n := range input {
j := inputLen - i - 1

output[j] = n
}

return output
}

// MergeMapStringString Merge desired into existing.
// Not Thread-Safe. Does it matter?
func MergeMapStringString(existing *map[string]string, desired map[string]string) bool {
Expand Down
11 changes: 11 additions & 0 deletions pkg/rlptools/limit_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ func SameLimitList(a, b []kuadrantv1beta1.Limit) bool {
copy(aCopy, a)
copy(bCopy, b)

// two limits with reordered conditions/variables are effectively the same
for idx := range aCopy {
sort.Strings(aCopy[idx].Conditions)
sort.Strings(aCopy[idx].Variables)
}

for idx := range bCopy {
sort.Strings(bCopy[idx].Conditions)
sort.Strings(bCopy[idx].Variables)
}

sort.Sort(LimitList(aCopy))
sort.Sort(LimitList(bCopy))

Expand Down
Loading

0 comments on commit a759480

Please sign in to comment.