Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Test empty TrafficTarget.Spec.Rules
Browse files Browse the repository at this point in the history
  • Loading branch information
draychev committed Jan 5, 2021
1 parent cd9b0e4 commit 863da5a
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions pkg/catalog/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
},
}
Expand Down

0 comments on commit 863da5a

Please sign in to comment.