Skip to content
Merged
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
73 changes: 73 additions & 0 deletions cloud/linode/service_controller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package linode

import (
"testing"

"github.com/golang/mock/gomock"
"github.com/linode/linode-cloud-controller-manager/cloud/linode/client/mocks"
"github.com/stretchr/testify/assert"
"k8s.io/client-go/util/workqueue"
)

func Test_serviceController_processNextDeletion(t *testing.T) {
type fields struct {
loadbalancers *loadbalancers
queue workqueue.TypedDelayingInterface[any]
Client *mocks.MockClient
}
tests := []struct {
name string
fields fields
Setup func(*fields)
want bool
queueLen int
}{
{
name: "Invalid service type",
fields: fields{
loadbalancers: nil,
},
Setup: func(f *fields) {
f.loadbalancers = &loadbalancers{client: f.Client, zone: "test", loadBalancerType: Options.LoadBalancerType}
f.queue = workqueue.NewTypedDelayingQueueWithConfig(workqueue.TypedDelayingQueueConfig[any]{Name: "testQueue"})
f.queue.Add("test")
},
want: true,
queueLen: 0,
},
{
name: "Valid service type",
fields: fields{
loadbalancers: nil,
},
Setup: func(f *fields) {
f.loadbalancers = &loadbalancers{client: f.Client, zone: "test", loadBalancerType: Options.LoadBalancerType}
f.queue = workqueue.NewTypedDelayingQueueWithConfig(workqueue.TypedDelayingQueueConfig[any]{Name: "testQueue"})
svc := createTestService()
f.queue.Add(svc)
},
want: true,
queueLen: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &serviceController{
loadbalancers: tt.fields.loadbalancers,
queue: tt.fields.queue,
}
ctrl := gomock.NewController(t)
defer ctrl.Finish()
client := mocks.NewMockClient(ctrl)
tt.fields.Client = client
tt.Setup(&tt.fields)
s.loadbalancers = tt.fields.loadbalancers
s.queue = tt.fields.queue
s.loadbalancers.client = tt.fields.Client
if got := s.processNextDeletion(); got != tt.want {
t.Errorf("serviceController.processNextDeletion() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.queueLen, tt.fields.queue.Len())
})
}
}
Loading