github.com/Axway/agent-sdk@v1.1.101/pkg/agent/handler/accesscontrollist_test.go (about) 1 package handler 2 3 import ( 4 "testing" 5 6 agentcache "github.com/Axway/agent-sdk/pkg/agent/cache" 7 v1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/api/v1" 8 catalog "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/catalog/v1alpha1" 9 management "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/management/v1alpha1" 10 "github.com/Axway/agent-sdk/pkg/config" 11 "github.com/Axway/agent-sdk/pkg/watchmanager/proto" 12 "github.com/stretchr/testify/assert" 13 ) 14 15 func TestACLHandler(t *testing.T) { 16 tests := []struct { 17 name string 18 hasError bool 19 resource *v1.ResourceInstance 20 action proto.Event_Type 21 }{ 22 { 23 name: "should save an Access Request Definition", 24 hasError: false, 25 action: proto.Event_CREATED, 26 resource: &v1.ResourceInstance{ 27 ResourceMeta: v1.ResourceMeta{ 28 Name: "name", 29 Title: "title", 30 Metadata: v1.Metadata{ 31 ID: "123", 32 }, 33 GroupVersionKind: v1.GroupVersionKind{ 34 GroupKind: v1.GroupKind{ 35 Kind: management.AccessControlListGVK().Kind, 36 }, 37 }, 38 }, 39 }, 40 }, 41 { 42 name: "should update an Access Request Definition", 43 hasError: false, 44 action: proto.Event_UPDATED, 45 resource: &v1.ResourceInstance{ 46 ResourceMeta: v1.ResourceMeta{ 47 Name: "name", 48 Title: "title", 49 Metadata: v1.Metadata{ 50 ID: "123", 51 }, 52 GroupVersionKind: v1.GroupVersionKind{ 53 GroupKind: v1.GroupKind{ 54 Kind: management.AccessControlListGVK().Kind, 55 }, 56 }, 57 }, 58 }, 59 }, 60 { 61 name: "should delete an Access Request Definition", 62 hasError: false, 63 action: proto.Event_DELETED, 64 resource: &v1.ResourceInstance{ 65 ResourceMeta: v1.ResourceMeta{ 66 Name: "name", 67 Title: "title", 68 Metadata: v1.Metadata{ 69 ID: "123", 70 }, 71 GroupVersionKind: v1.GroupVersionKind{ 72 GroupKind: v1.GroupKind{ 73 Kind: management.AccessControlListGVK().Kind, 74 }, 75 }, 76 }, 77 }, 78 }, 79 { 80 name: "should return nil when the kind is not an Access Request Definition", 81 hasError: false, 82 action: proto.Event_UPDATED, 83 resource: &v1.ResourceInstance{ 84 ResourceMeta: v1.ResourceMeta{ 85 Name: "name", 86 Title: "title", 87 Metadata: v1.Metadata{ 88 ID: "123", 89 }, 90 GroupVersionKind: v1.GroupVersionKind{ 91 GroupKind: v1.GroupKind{ 92 Kind: catalog.CategoryGVK().Kind, 93 }, 94 }, 95 }, 96 }, 97 }, 98 } 99 100 cacheManager := agentcache.NewAgentCacheManager(&config.CentralConfiguration{}, false) 101 for _, tc := range tests { 102 t.Run(tc.name, func(t *testing.T) { 103 handler := NewACLHandler(cacheManager) 104 105 err := handler.Handle(NewEventContext(tc.action, nil, tc.resource.Kind, tc.resource.Name), nil, tc.resource) 106 if tc.hasError { 107 assert.NotNil(t, err) 108 } else { 109 assert.Nil(t, err) 110 } 111 }) 112 } 113 }