github.com/Axway/agent-sdk@v1.1.101/pkg/agent/handler/environment_test.go (about) 1 package handler 2 3 import ( 4 "testing" 5 6 agentcache "github.com/Axway/agent-sdk/pkg/agent/cache" 7 apiv1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/api/v1" 8 management "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/management/v1alpha1" 9 "github.com/Axway/agent-sdk/pkg/config" 10 "github.com/Axway/agent-sdk/pkg/watchmanager/proto" 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestEnvironmentHandler(t *testing.T) { 15 tests := []struct { 16 name string 17 hasError bool 18 credentialConfg config.CredentialConfig 19 resource *apiv1.ResourceInstance 20 action proto.Event_Type 21 meta *proto.EventMeta 22 }{ 23 { 24 name: "should update an Environment subresource", 25 hasError: false, 26 action: proto.Event_SUBRESOURCEUPDATED, 27 credentialConfg: &config.CredentialConfiguration{ 28 ExpirationDays: 90, 29 DeprovisionOnExpire: true, 30 }, 31 meta: &proto.EventMeta{ 32 Subresource: management.EnvironmentPoliciesSubResourceName, 33 }, 34 resource: &apiv1.ResourceInstance{ 35 ResourceMeta: apiv1.ResourceMeta{ 36 Name: "name", 37 Title: "title", 38 Metadata: apiv1.Metadata{ 39 ID: "12345", 40 }, 41 GroupVersionKind: apiv1.GroupVersionKind{ 42 GroupKind: apiv1.GroupKind{ 43 Kind: management.EnvironmentGVK().Kind, 44 }, 45 }, 46 }, 47 }, 48 }, 49 } 50 51 cacheManager := agentcache.NewAgentCacheManager(&config.CentralConfiguration{}, false) 52 53 for _, tc := range tests { 54 t.Run(tc.name, func(t *testing.T) { 55 handler := NewEnvironmentHandler(cacheManager, tc.credentialConfg, tc.resource.Name) 56 57 err := handler.Handle(NewEventContext(tc.action, nil, tc.resource.Kind, tc.resource.Name), tc.meta, tc.resource) 58 if tc.hasError { 59 assert.NotNil(t, err) 60 } else { 61 assert.Nil(t, err) 62 } 63 }) 64 } 65 66 }