Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Unit-tests for common/common.go (part 3 of 3) #186

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,39 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [0.3.0] - 2023-05-09

## What's Changed
* [refactor] GW utils for all types of policies by @guicassolato in https://github.com/Kuadrant/kuadrant-operator/pull/134
* wasm shim image env var name does not match deployment var name by @eguzki in https://github.com/Kuadrant/kuadrant-operator/pull/136
* fix: `ComputeGatewayDiffs` when missing target HTTPRoute by @guicassolato in https://github.com/Kuadrant/kuadrant-operator/pull/139
* Istio workload selector fetched from the gateway service spec by @guicassolato in https://github.com/Kuadrant/kuadrant-operator/pull/143
* Improve policy constraint error message by @didierofrivia in https://github.com/Kuadrant/kuadrant-operator/pull/145
* Doc install operator by @eguzki in https://github.com/Kuadrant/kuadrant-operator/pull/148
* Simplify RateLimitPolicy by @eguzki in https://github.com/Kuadrant/kuadrant-operator/pull/144
* RLP conditions and variables order does not matter by @eguzki in https://github.com/Kuadrant/kuadrant-operator/pull/147
* Update limitador api to 0.4.0 by @eguzki in https://github.com/Kuadrant/kuadrant-operator/pull/150
* Bump Kind version from 0.11.1 to 0.17.0 by @art-tapin in https://github.com/Kuadrant/kuadrant-operator/pull/152
* Makefile: fix installing kind tool by @eguzki in https://github.com/Kuadrant/kuadrant-operator/pull/154
* Schedule build images with git sha reference by @didierofrivia in https://github.com/Kuadrant/kuadrant-operator/pull/149
* Fix GH Workflow inputs error by @didierofrivia in https://github.com/Kuadrant/kuadrant-operator/pull/155
* Inheriting all secrets from caller workflow by @didierofrivia in https://github.com/Kuadrant/kuadrant-operator/pull/157
* Fix bundle generation by @didierofrivia in https://github.com/Kuadrant/kuadrant-operator/pull/158
* Refactoring Github workflows by @didierofrivia in https://github.com/Kuadrant/kuadrant-operator/pull/161
* Update kind-cluster config by @art-tapin in https://github.com/Kuadrant/kuadrant-operator/pull/160
* Fix update action variables for dependencies by @didierofrivia in https://github.com/Kuadrant/kuadrant-operator/pull/162
* Fix scheduled build by @didierofrivia in https://github.com/Kuadrant/kuadrant-operator/pull/165
* Storing all dependencies sha by @didierofrivia in https://github.com/Kuadrant/kuadrant-operator/pull/170
* Fix inclusion of related wasm shim image by @didierofrivia in https://github.com/Kuadrant/kuadrant-operator/pull/171
* [test] Improve test coverage and performance in apimachinery_status_conditions by @art-tapin in https://github.com/Kuadrant/kuadrant-operator/pull/172
* [test] Add tests for authorino_conditions.go in common package by @art-tapin in https://github.com/Kuadrant/kuadrant-operator/pull/173
* [test] Add tests for hostname.go in common package by @art-tapin in https://github.com/Kuadrant/kuadrant-operator/pull/174
* Fixing image repo URL by @didierofrivia in https://github.com/Kuadrant/kuadrant-operator/pull/177
* Removing release workflow by @didierofrivia in https://github.com/Kuadrant/kuadrant-operator/pull/178

## New Contributors
* @art-tapin made their first contribution in https://github.com/Kuadrant/kuadrant-operator/pull/152

## [0.2.0] - 2022-12-16

### What's Changed
Expand Down Expand Up @@ -77,5 +110,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

**Full Changelog**: https://github.com/Kuadrant/kuadrant-operator/commits/v0.1.0

[Unreleased]: https://github.com/Kuadrant/kuadrant-operator/compare/v0.2.0...HEAD
[Unreleased]: https://github.com/Kuadrant/kuadrant-operator/compare/v0.3.0...HEAD
[0.3.0]: https://github.com/Kuadrant/kuadrant-operator/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/Kuadrant/kuadrant-operator/compare/v0.1.0...v0.2.0
8 changes: 5 additions & 3 deletions controllers/ratelimitpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
. "github.com/onsi/gomega"
istioclientgoextensionv1alpha1 "istio.io/client-go/pkg/apis/extensions/v1alpha1"
istioclientnetworkingv1alpha3 "istio.io/client-go/pkg/apis/networking/v1alpha3"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -31,9 +32,10 @@ func testBuildBasicGateway(gwName, ns string) *gatewayapiv1alpha2.Gateway {
APIVersion: gatewayapiv1alpha2.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: gwName,
Namespace: ns,
Labels: map[string]string{"app": "rlptest"},
Name: gwName,
Namespace: ns,
Labels: map[string]string{"app": "rlptest"},
Annotations: map[string]string{"networking.istio.io/service-type": string(corev1.ServiceTypeClusterIP)},
},
Spec: gatewayapiv1alpha2.GatewaySpec{
GatewayClassName: gatewayapiv1alpha2.ObjectName("istio"),
Expand Down
9 changes: 9 additions & 0 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func NamespacedNameToObjectKey(namespacedName, defaultNamespace string) client.O
return client.ObjectKey{Namespace: defaultNamespace, Name: namespacedName}
}

// Contains checks if the given target string is present in the slice of strings 'slice'.
// It returns true if the target string is found in the slice, false otherwise.
func Contains(slice []string, target string) bool {
for idx := range slice {
if slice[idx] == target {
Expand All @@ -103,6 +105,7 @@ func Find[T any](slice []T, match func(T) bool) (*T, bool) {
return nil, false
}

// Map applies the given mapper function to each element in the input slice and returns a new slice with the results.
func Map[T, U any](slice []T, f func(T) U) []U {
arr := make([]U, len(slice))
for i, e := range slice {
Expand All @@ -111,12 +114,14 @@ func Map[T, U any](slice []T, f func(T) U) []U {
return arr
}

// SliceCopy copies the elements from the input slice into the output slice, and returns the output slice.
func SliceCopy[T any](s1 []T) []T {
s2 := make([]T, len(s1))
copy(s2, s1)
return s2
}

// ReverseSlice creates a reversed copy of the input slice.
func ReverseSlice[T any](input []T) []T {
inputLen := len(input)
output := make([]T, inputLen)
Expand Down Expand Up @@ -171,6 +176,10 @@ func MarshallNamespace(gwKey client.ObjectKey, domain string) string {
return fmt.Sprintf("%s/%s#%s", gwKey.Namespace, gwKey.Name, domain)
}

// UnMarshallObjectKey takes a string input and converts it into an ObjectKey struct that
// can be used to access a specific Kubernetes object. The input string is expected to be in the format "namespace/name".
// If the input string does not contain a NamespaceSeparator (typically '/')
// or has too few components, this function returns an error.
func UnMarshallObjectKey(keyStr string) (client.ObjectKey, error) {
keySplit := strings.Split(keyStr, string(NamespaceSeparator))
if len(keySplit) < 2 {
Expand Down
Loading