From 2567a3aede67288089e129c7932bd31dbe8f39b3 Mon Sep 17 00:00:00 2001 From: Delyan Raychev Date: Mon, 4 Jan 2021 16:34:50 -0800 Subject: [PATCH] Test empty TrafficTarget.Spec.Rules Signed-off-by: Delyan Raychev --- pkg/catalog/routes_test.go | 56 ++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/pkg/catalog/routes_test.go b/pkg/catalog/routes_test.go index 93d0f79153..4a7abb61c8 100644 --- a/pkg/catalog/routes_test.go +++ b/pkg/catalog/routes_test.go @@ -27,6 +27,32 @@ import ( func TestIsValidTrafficTarget(t *testing.T) { assert := assert.New(t) + getTrafficTarget := func(rules []target.TrafficTargetRule) *target.TrafficTarget { + return &target.TrafficTarget{ + TypeMeta: v1.TypeMeta{ + APIVersion: "access.smi-spec.io/v1alpha2", + Kind: "TrafficTarget", + }, + ObjectMeta: v1.ObjectMeta{ + Name: "target", + Namespace: "default", + }, + Spec: target.TrafficTargetSpec{ + Destination: target.IdentityBindingSubject{ + Kind: "Name", + Name: "dest-id", + Namespace: "default", + }, + Sources: []target.IdentityBindingSubject{{ + Kind: "Name", + Name: "source-id", + Namespace: "default", + }}, + Rules: rules, + }, + } + } + testCases := []struct { name string input *target.TrafficTarget @@ -38,29 +64,13 @@ func TestIsValidTrafficTarget(t *testing.T) { expected: true, }, { - name: "is not valid", - input: &target.TrafficTarget{ - TypeMeta: v1.TypeMeta{ - APIVersion: "access.smi-spec.io/v1alpha2", - Kind: "TrafficTarget", - }, - ObjectMeta: v1.ObjectMeta{ - Name: "target", - Namespace: "default", - }, - Spec: target.TrafficTargetSpec{ - Destination: target.IdentityBindingSubject{ - Kind: "Name", - Name: "dest-id", - Namespace: "default", - }, - Sources: []target.IdentityBindingSubject{{ - Kind: "Name", - Name: "source-id", - Namespace: "default", - }}, - }, - }, + name: "is not valid because TrafficTarget.Spec.Rules is nil", + input: getTrafficTarget(nil), + expected: false, + }, + { + name: "is not valid because TrafficTarget.Spec.Rules is not nil but is empty", + input: getTrafficTarget([]target.TrafficTargetRule{}), expected: false, }, }