Skip to content

Commit

Permalink
Simplify test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsokolovsky committed Jun 28, 2024
1 parent 7698d0e commit 114bf38
Showing 1 changed file with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import (

func TestValidateAgentTLSMode(t *testing.T) {
t.Parallel()
type testState struct {
clusterCache *fake.MockNonNamespacedCacheInterface[*v3.Cluster]
}
tests := map[string]struct {
oldSetting v3.Setting
newSetting v3.Setting
Expand Down Expand Up @@ -278,17 +275,15 @@ func TestValidateAgentTLSMode(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()
ctrl := gomock.NewController(t)
state := testState{
clusterCache: fake.NewMockNonNamespacedCacheInterface[*v3.Cluster](ctrl),
}
clusterCache := fake.NewMockNonNamespacedCacheInterface[*v3.Cluster](ctrl)
_, force := tc.newSetting.Annotations["cattle.io/force"]
if tc.operation == admissionv1.Update && !force && len(tc.clusters) > 0 {
state.clusterCache.EXPECT().List(gomock.Any()).Return(tc.clusters, nil)
clusterCache.EXPECT().List(gomock.Any()).Return(tc.clusters, nil)
}
if tc.clusterListerFails {
state.clusterCache.EXPECT().List(gomock.Any()).Return(tc.clusters, errors.New("some error"))
clusterCache.EXPECT().List(gomock.Any()).Return(tc.clusters, errors.New("some error"))
}
v := NewValidator(state.clusterCache)
v := NewValidator(clusterCache)
admitters := v.Admitters()
require.Len(t, admitters, 1)

Expand Down

0 comments on commit 114bf38

Please sign in to comment.