Skip to content

Commit

Permalink
enh: add test for get int from service annotation (#2402)
Browse files Browse the repository at this point in the history
Signed-off-by: sakshi-1505 <[email protected]>
  • Loading branch information
sakshi-1505 authored Oct 9, 2023
1 parent 5e2668a commit 098a52b
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions pkg/openstack/loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type testPopListener struct {
Expand Down Expand Up @@ -534,3 +535,61 @@ func Test_getListenerProtocol(t *testing.T) {
})
}
}

func Test_getIntFromServiceAnnotation(t *testing.T) {
type args struct {
service *corev1.Service
annotationKey string
defaultSetting int
}
tests := []struct {
name string
args args
want int
}{
{
name: "return default setting if no service annotation",
args: args{
defaultSetting: 1,
annotationKey: "bar",
service: &corev1.Service{
ObjectMeta: v1.ObjectMeta{
Annotations: map[string]string{"foo": "2"},
},
},
},
want: 1,
},
{
name: "return annotation key if it exists in service annotation",
args: args{
defaultSetting: 1,
annotationKey: "foo",
service: &corev1.Service{
ObjectMeta: v1.ObjectMeta{
Annotations: map[string]string{"foo": "2"},
},
},
},
want: 2,
},
{
name: "return default setting if key isn't valid integer",
args: args{
defaultSetting: 1,
annotationKey: "foo",
service: &corev1.Service{
ObjectMeta: v1.ObjectMeta{
Annotations: map[string]string{"foo": "bar"},
},
},
},
want: 1,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, getIntFromServiceAnnotation(tt.args.service, tt.args.annotationKey, tt.args.defaultSetting))
})
}
}

0 comments on commit 098a52b

Please sign in to comment.