Skip to content

Commit

Permalink
Merge pull request #33 from barchw/v1alpha1-label-test
Browse files Browse the repository at this point in the history
Test for fetching by label v1alpha1
  • Loading branch information
barchw authored Sep 22, 2022
2 parents 331a6ad + 7a0c410 commit 459be10
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions internal/processing/processing_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package processing

import (
"context"
"fmt"
"testing"

Expand All @@ -16,6 +17,7 @@ import (
rulev1alpha1 "github.com/ory/oathkeeper-maester/api/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

const (
Expand Down Expand Up @@ -533,6 +535,60 @@ var _ = Describe("Factory", func() {
})
})

Describe("CalculateRequiredState", func() {
Context("when the access rule and virtual service has owner v1alpha1 owner label", func() {
It("should get the access rule and virtual service", func() {
noop := []*gatewayv1beta1.Authenticator{
{
Handler: &gatewayv1beta1.Handler{
Name: "noop",
},
},
}

noopRule := getRuleFor(apiPath, apiMethods, []*gatewayv1beta1.Mutator{}, noop)
rules := []gatewayv1beta1.Rule{noopRule}

apiRule := getAPIRuleFor(rules)


rule := rulev1alpha1.Rule{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
OwnerLabelv1alpha1: fmt.Sprintf("%s.%s", apiRule.ObjectMeta.Name, apiRule.ObjectMeta.Namespace),
},
},
Spec: rulev1alpha1.RuleSpec{
Match: &rulev1alpha1.Match{
URL: "some url",
},
},
}

vs := networkingv1beta1.VirtualService{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
OwnerLabelv1alpha1: fmt.Sprintf("%s.%s", apiRule.ObjectMeta.Name, apiRule.ObjectMeta.Namespace),
},
},
}

scheme := runtime.NewScheme()
rulev1alpha1.AddToScheme(scheme)
networkingv1beta1.AddToScheme(scheme)
gatewayv1beta1.AddToScheme(scheme)

client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&rule, &vs).Build()

f := NewFactory(client, ctrl.Log.WithName("test"), oathkeeperSvc, oathkeeperSvcPort, testCors, testAdditionalLabels, defaultDomain)
actualState, err := f.GetActualState(context.TODO(), apiRule)

Expect(err).To(BeNil())
Expect(actualState.accessRules).To(HaveLen(1))
Expect(actualState.virtualService).To(Not(BeNil()))
})
})
})
Describe("CalculateDiff", func() {
Context("between desired state & actual state", func() {
It("should produce patch containing VS to create & AR to create", func() {
Expand Down

0 comments on commit 459be10

Please sign in to comment.