diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b312b2c..8b2cfb1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,8 +14,8 @@ on: env: # Common versions - GO_VERSION: '1.25.10' - GOLANGCI_VERSION: 'v2.8.0' + GO_VERSION: '1.26.0' + GOLANGCI_VERSION: 'v2.12.2' DOCKER_BUILDX_VERSION: 'v0.23.0' # These environment variables are important to the Crossplane CLI install.sh diff --git a/fn.go b/fn.go index 09320c3..df9a5ed 100644 --- a/fn.go +++ b/fn.go @@ -63,6 +63,24 @@ const ( LastQueryTimestampsField = "lastQueryTimestamps" ) +const ( + // Microsoft Graph field names used in query projections ($select) and in the + // maps returned for query results. + fieldDisplayName = "displayName" + fieldAppID = "appId" + fieldDescription = "description" + fieldMail = "mail" + fieldUserPrincipalName = "userPrincipalName" + fieldType = "type" +) + +const ( + // Member type discriminators returned for group members. + userType = "user" + servicePrincipalType = "servicePrincipal" + unknownType = "unknown" +) + // GraphQueryInterface defines the methods required for querying Microsoft Graph API. type GraphQueryInterface interface { graphQuery(ctx context.Context, azureCreds map[string]string, in *v1beta1.Input) (interface{}, error) @@ -526,7 +544,7 @@ func (g *GraphQuery) validateUsers(ctx context.Context, client *msgraphsdk.Graph requestConfig.QueryParameters.Filter = &filterValue // Use standard fields for user validation - requestConfig.QueryParameters.Select = []string{"id", "displayName", "userPrincipalName", "mail"} + requestConfig.QueryParameters.Select = []string{"id", fieldDisplayName, fieldUserPrincipalName, fieldMail} // Execute the query result, err := client.Users().Get(ctx, requestConfig) @@ -538,10 +556,10 @@ func (g *GraphQuery) validateUsers(ctx context.Context, client *msgraphsdk.Graph if result.GetValue() != nil { for _, user := range result.GetValue() { userMap := map[string]interface{}{ - "id": ptr.Deref(user.GetId(), ""), - "displayName": ptr.Deref(user.GetDisplayName(), ""), - "userPrincipalName": ptr.Deref(user.GetUserPrincipalName(), ""), - "mail": ptr.Deref(user.GetMail(), ""), + "id": ptr.Deref(user.GetId(), ""), + fieldDisplayName: ptr.Deref(user.GetDisplayName(), ""), + fieldUserPrincipalName: ptr.Deref(user.GetUserPrincipalName(), ""), + fieldMail: ptr.Deref(user.GetMail(), ""), } results = append(results, userMap) } @@ -617,7 +635,7 @@ func (g *GraphQuery) extractDisplayName(member models.DirectoryObjectable, membe additionalData := member.GetAdditionalData() // Try to get from additional data first - if displayNameVal, exists := additionalData["displayName"]; exists && displayNameVal != nil { + if displayNameVal, exists := additionalData[fieldDisplayName]; exists && displayNameVal != nil { if displayName, ok := displayNameVal.(string); ok { return displayName } @@ -657,22 +675,22 @@ func (g *GraphQuery) extractStringProperty(additionalData map[string]interface{} func (g *GraphQuery) extractUserProperties(member models.DirectoryObjectable, additionalData map[string]interface{}, memberMap map[string]interface{}) { if user, ok := member.(models.Userable); ok { if mail := ptr.Deref(user.GetMail(), ""); mail != "" { - memberMap["mail"] = mail + memberMap[fieldMail] = mail } if upn := ptr.Deref(user.GetUserPrincipalName(), ""); upn != "" { - memberMap["userPrincipalName"] = upn + memberMap[fieldUserPrincipalName] = upn } } // Fall back to additionalData when the typed getters did not provide a value. - if _, ok := memberMap["mail"]; !ok { - if mail, found := g.extractStringProperty(additionalData, "mail"); found { - memberMap["mail"] = mail + if _, ok := memberMap[fieldMail]; !ok { + if mail, found := g.extractStringProperty(additionalData, fieldMail); found { + memberMap[fieldMail] = mail } } - if _, ok := memberMap["userPrincipalName"]; !ok { - if upn, found := g.extractStringProperty(additionalData, "userPrincipalName"); found { - memberMap["userPrincipalName"] = upn + if _, ok := memberMap[fieldUserPrincipalName]; !ok { + if upn, found := g.extractStringProperty(additionalData, fieldUserPrincipalName); found { + memberMap[fieldUserPrincipalName] = upn } } } @@ -682,27 +700,20 @@ func (g *GraphQuery) extractUserProperties(member models.DirectoryObjectable, ad func (g *GraphQuery) extractServicePrincipalProperties(member models.DirectoryObjectable, additionalData map[string]interface{}, memberMap map[string]interface{}) { if sp, ok := member.(models.ServicePrincipalable); ok { if appID := ptr.Deref(sp.GetAppId(), ""); appID != "" { - memberMap["appId"] = appID + memberMap[fieldAppID] = appID } } // Fall back to additionalData when the typed getter did not provide a value. - if _, ok := memberMap["appId"]; !ok { - if appID, found := g.extractStringProperty(additionalData, "appId"); found { - memberMap["appId"] = appID + if _, ok := memberMap[fieldAppID]; !ok { + if appID, found := g.extractStringProperty(additionalData, fieldAppID); found { + memberMap[fieldAppID] = appID } } } // processMember extracts member information into a map func (g *GraphQuery) processMember(member models.DirectoryObjectable) map[string]interface{} { - // Define constants for member types - const ( - userType = "user" - servicePrincipalType = "servicePrincipal" - unknownType = "unknown" - ) - memberID := ptr.Deref(member.GetId(), "") additionalData := member.GetAdditionalData() @@ -715,14 +726,14 @@ func (g *GraphQuery) processMember(member models.DirectoryObjectable) map[string memberType := unknownType // Check properties that indicate user type - _, hasUserPrincipalName := g.extractStringProperty(additionalData, "userPrincipalName") - _, hasMail := g.extractStringProperty(additionalData, "mail") + _, hasUserPrincipalName := g.extractStringProperty(additionalData, fieldUserPrincipalName) + _, hasMail := g.extractStringProperty(additionalData, fieldMail) if hasUserPrincipalName || hasMail { memberType = userType } // Check properties that indicate service principal type - _, hasAppID := g.extractStringProperty(additionalData, "appId") + _, hasAppID := g.extractStringProperty(additionalData, fieldAppID) if hasAppID { memberType = servicePrincipalType } @@ -736,10 +747,10 @@ func (g *GraphQuery) processMember(member models.DirectoryObjectable) map[string } // Add type to member info - memberMap["type"] = memberType + memberMap[fieldType] = memberType // Extract display name - memberMap["displayName"] = g.extractDisplayName(member, memberID) + memberMap[fieldDisplayName] = g.extractDisplayName(member, memberID) // Extract type-specific properties switch memberType { @@ -809,7 +820,7 @@ func (g *GraphQuery) getGroupObjectIDs(ctx context.Context, client *msgraphsdk.G requestConfig.QueryParameters.Filter = &filterValue // Use standard fields for group object IDs - requestConfig.QueryParameters.Select = []string{"id", "displayName", "description"} + requestConfig.QueryParameters.Select = []string{"id", fieldDisplayName, fieldDescription} groupResult, err := client.Groups().Get(ctx, requestConfig) if err != nil { @@ -819,9 +830,9 @@ func (g *GraphQuery) getGroupObjectIDs(ctx context.Context, client *msgraphsdk.G if groupResult.GetValue() != nil && len(groupResult.GetValue()) > 0 { for _, group := range groupResult.GetValue() { groupMap := map[string]interface{}{ - "id": ptr.Deref(group.GetId(), ""), - "displayName": ptr.Deref(group.GetDisplayName(), ""), - "description": ptr.Deref(group.GetDescription(), ""), + "id": ptr.Deref(group.GetId(), ""), + fieldDisplayName: ptr.Deref(group.GetDisplayName(), ""), + fieldDescription: ptr.Deref(group.GetDescription(), ""), } results = append(results, groupMap) } @@ -854,7 +865,7 @@ func (g *GraphQuery) getServicePrincipalDetails(ctx context.Context, client *msg requestConfig.QueryParameters.Filter = &filterValue // Use standard fields for service principals - requestConfig.QueryParameters.Select = []string{"id", "appId", "displayName", "description"} + requestConfig.QueryParameters.Select = []string{"id", fieldAppID, fieldDisplayName, fieldDescription} spResult, err := client.ServicePrincipals().Get(ctx, requestConfig) if err != nil { @@ -864,10 +875,10 @@ func (g *GraphQuery) getServicePrincipalDetails(ctx context.Context, client *msg if spResult.GetValue() != nil && len(spResult.GetValue()) > 0 { for _, sp := range spResult.GetValue() { spMap := map[string]interface{}{ - "id": ptr.Deref(sp.GetId(), ""), - "appId": ptr.Deref(sp.GetAppId(), ""), - "displayName": ptr.Deref(sp.GetDisplayName(), ""), - "description": ptr.Deref(sp.GetDescription(), ""), + "id": ptr.Deref(sp.GetId(), ""), + fieldAppID: ptr.Deref(sp.GetAppId(), ""), + fieldDisplayName: ptr.Deref(sp.GetDisplayName(), ""), + fieldDescription: ptr.Deref(sp.GetDescription(), ""), } results = append(results, spMap) } diff --git a/fn_test.go b/fn_test.go index 0042956..9b53a3e 100644 --- a/fn_test.go +++ b/fn_test.go @@ -20,6 +20,26 @@ import ( "github.com/crossplane/function-sdk-go/response" ) +const ( + // Repeated fixture values used across the table-driven tests. + testRequestTag = "hello" + testCredentialsKey = "credentials" + testAzureCredsName = "azure-creds" + testSPID1 = "sp-id-1" + testUser1Email = "user1@example.com" + testUser2Email = "user2@example.com" + watchedResourceKey = "ops.crossplane.io/watched-resource" + + // Condition fields asserted on successful function responses. + condTypeFunctionSuccess = "FunctionSuccess" + condReasonSuccess = "Success" + + // Result messages emitted per query type. + msgUserValidationQueryType = `QueryType: "UserValidation"` + msgGroupObjectIDsQueryType = `QueryType: "GroupObjectIDs"` + msgServicePrincipalDetailsQueryType = `QueryType: "ServicePrincipalDetails"` +) + type MockGraphQuery struct { GraphQueryFunc func(ctx context.Context, azureCreds map[string]string, in *v1beta1.Input) (interface{}, error) } @@ -40,7 +60,7 @@ func TestResolveGroupsRef(t *testing.T) { xr = `{"apiVersion":"example.org/v1","kind":"XR","metadata":{"name":"cool-xr"},"spec":{"count":2}}` creds = &fnv1.CredentialData{ Data: map[string][]byte{ - "credentials": []byte(`{ + testCredentialsKey: []byte(`{ "clientId": "test-client-id", "clientSecret": "test-client-secret", "subscriptionId": "test-subscription-id", @@ -69,7 +89,7 @@ func TestResolveGroupsRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -89,7 +109,7 @@ func TestResolveGroupsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -97,19 +117,19 @@ func TestResolveGroupsRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "GroupObjectIDs"`, + Message: msgGroupObjectIDsQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -148,7 +168,7 @@ func TestResolveGroupsRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -165,7 +185,7 @@ func TestResolveGroupsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -173,19 +193,19 @@ func TestResolveGroupsRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "GroupObjectIDs"`, + Message: msgGroupObjectIDsQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -232,7 +252,7 @@ func TestResolveGroupsRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -254,7 +274,7 @@ func TestResolveGroupsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -262,19 +282,19 @@ func TestResolveGroupsRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "GroupObjectIDs"`, + Message: msgGroupObjectIDsQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -317,7 +337,7 @@ func TestResolveGroupsRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -339,7 +359,7 @@ func TestResolveGroupsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -347,19 +367,19 @@ func TestResolveGroupsRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "GroupObjectIDs"`, + Message: msgGroupObjectIDsQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -386,7 +406,7 @@ func TestResolveGroupsRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -409,7 +429,7 @@ func TestResolveGroupsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -417,19 +437,19 @@ func TestResolveGroupsRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "GroupObjectIDs"`, + Message: msgGroupObjectIDsQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -456,7 +476,7 @@ func TestResolveGroupsRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -479,7 +499,7 @@ func TestResolveGroupsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -487,7 +507,7 @@ func TestResolveGroupsRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{}, Results: []*fnv1.Result{ { @@ -516,7 +536,7 @@ func TestResolveGroupsRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -530,7 +550,7 @@ func TestResolveGroupsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -538,7 +558,7 @@ func TestResolveGroupsRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -593,9 +613,9 @@ func TestResolveGroupsRef(t *testing.T) { } groupMap := map[string]interface{}{ - "id": groupID, - "displayName": *group, - "description": description, + "id": groupID, + fieldDisplayName: *group, + fieldDescription: description, } results = append(results, groupMap) } @@ -628,7 +648,7 @@ func TestResolveGroupRef(t *testing.T) { xr = `{"apiVersion":"example.org/v1","kind":"XR","metadata":{"name":"cool-xr"},"spec":{"count":2}}` creds = &fnv1.CredentialData{ Data: map[string][]byte{ - "credentials": []byte(`{ + testCredentialsKey: []byte(`{ "clientId": "test-client-id", "clientSecret": "test-client-secret", "subscriptionId": "test-subscription-id", @@ -657,7 +677,7 @@ func TestResolveGroupRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -679,7 +699,7 @@ func TestResolveGroupRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -687,12 +707,12 @@ func TestResolveGroupRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, @@ -738,7 +758,7 @@ func TestResolveGroupRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -757,7 +777,7 @@ func TestResolveGroupRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -765,12 +785,12 @@ func TestResolveGroupRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, @@ -824,7 +844,7 @@ func TestResolveGroupRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -846,7 +866,7 @@ func TestResolveGroupRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -854,12 +874,12 @@ func TestResolveGroupRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, @@ -907,7 +927,7 @@ func TestResolveGroupRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -921,7 +941,7 @@ func TestResolveGroupRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -929,7 +949,7 @@ func TestResolveGroupRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -967,17 +987,17 @@ func TestResolveGroupRef(t *testing.T) { } return []interface{}{ map[string]interface{}{ - "id": "user-id-1", - "displayName": "Test User 1", - "mail": "user1@example.com", - "userPrincipalName": "user1@example.com", - "type": "user", + "id": "user-id-1", + fieldDisplayName: "Test User 1", + fieldMail: testUser1Email, + fieldUserPrincipalName: testUser1Email, + fieldType: userType, }, map[string]interface{}{ - "id": "sp-id-1", - "displayName": "Test Service Principal", - "appId": "sp-app-id-1", - "type": "servicePrincipal", + "id": testSPID1, + fieldDisplayName: "Test Service Principal", + fieldAppID: "sp-app-id-1", + fieldType: servicePrincipalType, }, }, nil } @@ -1008,7 +1028,7 @@ func TestResolveUsersRef(t *testing.T) { xr = `{"apiVersion":"example.org/v1","kind":"XR","metadata":{"name":"cool-xr"},"spec":{"count":2}}` creds = &fnv1.CredentialData{ Data: map[string][]byte{ - "credentials": []byte(`{ + testCredentialsKey: []byte(`{ "clientId": "test-client-id", "clientSecret": "test-client-secret", "subscriptionId": "test-subscription-id", @@ -1037,7 +1057,7 @@ func TestResolveUsersRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -1057,7 +1077,7 @@ func TestResolveUsersRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1065,19 +1085,19 @@ func TestResolveUsersRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "UserValidation"`, + Message: msgUserValidationQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -1119,7 +1139,7 @@ func TestResolveUsersRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -1136,7 +1156,7 @@ func TestResolveUsersRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1144,19 +1164,19 @@ func TestResolveUsersRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "UserValidation"`, + Message: msgUserValidationQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -1206,7 +1226,7 @@ func TestResolveUsersRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -1228,7 +1248,7 @@ func TestResolveUsersRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1236,19 +1256,19 @@ func TestResolveUsersRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "UserValidation"`, + Message: msgUserValidationQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -1294,7 +1314,7 @@ func TestResolveUsersRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -1316,7 +1336,7 @@ func TestResolveUsersRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1324,19 +1344,19 @@ func TestResolveUsersRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "UserValidation"`, + Message: msgUserValidationQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -1363,7 +1383,7 @@ func TestResolveUsersRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -1386,7 +1406,7 @@ func TestResolveUsersRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1394,19 +1414,19 @@ func TestResolveUsersRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "UserValidation"`, + Message: msgUserValidationQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -1433,7 +1453,7 @@ func TestResolveUsersRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -1456,7 +1476,7 @@ func TestResolveUsersRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1464,7 +1484,7 @@ func TestResolveUsersRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{}, Results: []*fnv1.Result{ { @@ -1493,7 +1513,7 @@ func TestResolveUsersRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -1507,7 +1527,7 @@ func TestResolveUsersRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1515,7 +1535,7 @@ func TestResolveUsersRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -1565,10 +1585,10 @@ func TestResolveUsersRef(t *testing.T) { // Generate different test data based on user principal name switch *user { - case "user1@example.com": + case testUser1Email: userID = "user-id-1" displayName = "User 1" - case "user2@example.com": + case testUser2Email: userID = "user-id-2" displayName = "User 2" case "admin@example.onmicrosoft.com": @@ -1580,10 +1600,10 @@ func TestResolveUsersRef(t *testing.T) { } userMap := map[string]interface{}{ - "id": userID, - "displayName": displayName, - "userPrincipalName": *user, - "mail": *user, + "id": userID, + fieldDisplayName: displayName, + fieldUserPrincipalName: *user, + fieldMail: *user, } results = append(results, userMap) } @@ -1616,7 +1636,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { xr = `{"apiVersion":"example.org/v1","kind":"XR","metadata":{"name":"cool-xr"},"spec":{"count":2}}` creds = &fnv1.CredentialData{ Data: map[string][]byte{ - "credentials": []byte(`{ + testCredentialsKey: []byte(`{ "clientId": "test-client-id", "clientSecret": "test-client-secret", "subscriptionId": "test-subscription-id", @@ -1645,7 +1665,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -1665,7 +1685,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1673,19 +1693,19 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "ServicePrincipalDetails"`, + Message: msgServicePrincipalDetailsQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -1727,7 +1747,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -1744,7 +1764,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1752,19 +1772,19 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "ServicePrincipalDetails"`, + Message: msgServicePrincipalDetailsQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -1814,7 +1834,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -1836,7 +1856,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1844,19 +1864,19 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "ServicePrincipalDetails"`, + Message: msgServicePrincipalDetailsQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -1902,7 +1922,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -1924,7 +1944,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1932,19 +1952,19 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "ServicePrincipalDetails"`, + Message: msgServicePrincipalDetailsQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -1971,7 +1991,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -1994,7 +2014,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2002,19 +2022,19 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "ServicePrincipalDetails"`, + Message: msgServicePrincipalDetailsQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -2041,7 +2061,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -2064,7 +2084,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2072,7 +2092,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{}, Results: []*fnv1.Result{ { @@ -2101,7 +2121,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -2115,7 +2135,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2123,7 +2143,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -2175,7 +2195,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { // Generate different test data based on service principal name switch *sp { case "MyServiceApp": - spID = "sp-id-1" + spID = testSPID1 appID = "app-id-1" description = "Service application" case "ApiConnector": @@ -2193,10 +2213,10 @@ func TestResolveServicePrincipalsRef(t *testing.T) { } spMap := map[string]interface{}{ - "id": spID, - "appId": appID, - "displayName": *sp, - "description": description, + "id": spID, + fieldAppID: appID, + fieldDisplayName: *sp, + fieldDescription: description, } results = append(results, spMap) } @@ -2229,7 +2249,7 @@ func TestRunFunction(t *testing.T) { xr = `{"apiVersion":"example.org/v1","kind":"XR","metadata":{"name":"cool-xr","finalizers":["composite.apiextensions.crossplane.io"]},"spec":{"count":2}}` creds = &fnv1.CredentialData{ Data: map[string][]byte{ - "credentials": []byte(`{ + testCredentialsKey: []byte(`{ "clientId": "test-cliend-id", "clientSecret": "test-client-secret", "subscriptionId": "test-subscription-id", @@ -2257,7 +2277,7 @@ func TestRunFunction(t *testing.T) { reason: "The Function should return a fatal result if no credentials were specified", args: args{ req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -2273,7 +2293,7 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -2302,7 +2322,7 @@ func TestRunFunction(t *testing.T) { reason: "The Function should return a fatal result if no target is specified", args: args{ req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -2315,7 +2335,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2323,7 +2343,7 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -2353,7 +2373,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -2366,7 +2386,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2374,7 +2394,7 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -2404,7 +2424,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -2418,7 +2438,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2426,19 +2446,19 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "UserValidation"`, + Message: msgUserValidationQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -2473,7 +2493,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -2486,7 +2506,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2494,7 +2514,7 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -2524,7 +2544,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -2538,7 +2558,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2546,12 +2566,12 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, @@ -2600,7 +2620,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -2613,7 +2633,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2621,7 +2641,7 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -2651,7 +2671,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -2665,7 +2685,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2673,19 +2693,19 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "GroupObjectIDs"`, + Message: msgGroupObjectIDsQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -2724,7 +2744,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -2737,7 +2757,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2745,7 +2765,7 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -2775,7 +2795,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -2789,7 +2809,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2797,19 +2817,19 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "ServicePrincipalDetails"`, + Message: msgServicePrincipalDetailsQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -2844,7 +2864,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -2857,7 +2877,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2865,7 +2885,7 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -2895,7 +2915,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -2923,7 +2943,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2931,7 +2951,7 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { Type: "FunctionSkip", @@ -2941,9 +2961,9 @@ func TestRunFunction(t *testing.T) { Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, @@ -2972,7 +2992,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -3003,7 +3023,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -3011,7 +3031,7 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { Type: "FunctionSkip", @@ -3021,9 +3041,9 @@ func TestRunFunction(t *testing.T) { Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, @@ -3055,7 +3075,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -3086,7 +3106,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -3094,19 +3114,19 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "UserValidation"`, + Message: msgUserValidationQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -3138,7 +3158,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -3153,7 +3173,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -3161,19 +3181,19 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "UserValidation"`, + Message: msgUserValidationQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -3211,7 +3231,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -3226,7 +3246,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -3234,7 +3254,7 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -3264,7 +3284,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -3280,7 +3300,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -3288,12 +3308,12 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, @@ -3305,7 +3325,7 @@ func TestRunFunction(t *testing.T) { }, { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "UserValidation"`, + Message: msgUserValidationQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -3343,7 +3363,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -3357,7 +3377,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -3365,19 +3385,19 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "UserValidation"`, + Message: msgUserValidationQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -3415,7 +3435,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -3424,7 +3444,7 @@ func TestRunFunction(t *testing.T) { "target": "context.validatedUsers" }`), Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -3433,7 +3453,7 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -3449,7 +3469,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -3458,12 +3478,12 @@ func TestRunFunction(t *testing.T) { "target": "context.validatedUsers" }`), Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, RequiredResources: map[string]*fnv1.Resources{ - "ops.crossplane.io/watched-resource": { + watchedResourceKey: { Items: nil, }, }, @@ -3471,7 +3491,7 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -3487,7 +3507,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -3496,12 +3516,12 @@ func TestRunFunction(t *testing.T) { "target": "context.validatedUsers" }`), Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, RequiredResources: map[string]*fnv1.Resources{ - "ops.crossplane.io/watched-resource": { + watchedResourceKey: { Items: []*fnv1.Resource{ { Resource: resource.MustStructJSON(xr), @@ -3516,7 +3536,7 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -3532,7 +3552,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -3541,12 +3561,12 @@ func TestRunFunction(t *testing.T) { "target": "context.validatedUsers" }`), Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, RequiredResources: map[string]*fnv1.Resources{ - "ops.crossplane.io/watched-resource": { + watchedResourceKey: { Items: []*fnv1.Resource{ {}, }, @@ -3556,7 +3576,7 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -3572,7 +3592,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -3581,12 +3601,12 @@ func TestRunFunction(t *testing.T) { "target": "status.validatedUsers" }`), Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, RequiredResources: map[string]*fnv1.Resources{ - "ops.crossplane.io/watched-resource": { + watchedResourceKey: { Items: []*fnv1.Resource{ { Resource: resource.MustStructJSON(`{"apiVersion":"example.org/v1","kind":"XR","metadata":{"name":"cool-xr"},"spec":{"count":2}}`), @@ -3598,7 +3618,7 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -3614,7 +3634,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -3623,12 +3643,12 @@ func TestRunFunction(t *testing.T) { "target": "status.validatedUsers" }`), Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, RequiredResources: map[string]*fnv1.Resources{ - "ops.crossplane.io/watched-resource": { + watchedResourceKey: { Items: []*fnv1.Resource{ { Resource: resource.MustStructJSON(`{ @@ -3662,19 +3682,19 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "UserValidation"`, + Message: msgUserValidationQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -3703,7 +3723,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -3712,12 +3732,12 @@ func TestRunFunction(t *testing.T) { "target": "status.validatedUsers" }`), Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, RequiredResources: map[string]*fnv1.Resources{ - "ops.crossplane.io/watched-resource": { + watchedResourceKey: { Items: []*fnv1.Resource{ { Resource: resource.MustStructJSON(`{ @@ -3754,19 +3774,19 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "UserValidation"`, + Message: msgUserValidationQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -3796,7 +3816,7 @@ func TestRunFunction(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -3805,12 +3825,12 @@ func TestRunFunction(t *testing.T) { "target": "status.validatedUsers" }`), Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, RequiredResources: map[string]*fnv1.Resources{ - "ops.crossplane.io/watched-resource": { + watchedResourceKey: { Items: []*fnv1.Resource{ { Resource: resource.MustStructJSON(`{ @@ -3844,19 +3864,19 @@ func TestRunFunction(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Conditions: []*fnv1.Condition{ { - Type: "FunctionSuccess", + Type: condTypeFunctionSuccess, Status: fnv1.Status_STATUS_CONDITION_TRUE, - Reason: "Success", + Reason: condReasonSuccess, Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(), }, }, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "UserValidation"`, + Message: msgUserValidationQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -3894,10 +3914,10 @@ func TestRunFunction(t *testing.T) { } return []interface{}{ map[string]interface{}{ - "id": "test-user-id", - "displayName": "Test User", - "userPrincipalName": "user@example.com", - "mail": "user@example.com", + "id": "test-user-id", + fieldDisplayName: "Test User", + fieldUserPrincipalName: "user@example.com", + fieldMail: "user@example.com", }, }, nil case "GroupMembership": @@ -3906,17 +3926,17 @@ func TestRunFunction(t *testing.T) { } return []interface{}{ map[string]interface{}{ - "id": "user-id-1", - "displayName": "Test User 1", - "mail": "user1@example.com", - "userPrincipalName": "user1@example.com", - "type": "user", + "id": "user-id-1", + fieldDisplayName: "Test User 1", + fieldMail: testUser1Email, + fieldUserPrincipalName: testUser1Email, + fieldType: userType, }, map[string]interface{}{ - "id": "sp-id-1", - "displayName": "Test Service Principal", - "appId": "sp-app-id-1", - "type": "servicePrincipal", + "id": testSPID1, + fieldDisplayName: "Test Service Principal", + fieldAppID: "sp-app-id-1", + fieldType: servicePrincipalType, }, }, nil case "GroupObjectIDs": @@ -3925,14 +3945,14 @@ func TestRunFunction(t *testing.T) { } return []interface{}{ map[string]interface{}{ - "id": "group-id-1", - "displayName": "Developers", - "description": "Development team", + "id": "group-id-1", + fieldDisplayName: "Developers", + fieldDescription: "Development team", }, map[string]interface{}{ - "id": "group-id-2", - "displayName": "Operations", - "description": "Operations team", + "id": "group-id-2", + fieldDisplayName: "Operations", + fieldDescription: "Operations team", }, }, nil case "ServicePrincipalDetails": @@ -3941,10 +3961,10 @@ func TestRunFunction(t *testing.T) { } return []interface{}{ map[string]interface{}{ - "id": "sp-id-1", - "appId": "app-id-1", - "displayName": "MyServiceApp", - "description": "Service application", + "id": testSPID1, + fieldAppID: "app-id-1", + fieldDisplayName: "MyServiceApp", + fieldDescription: "Service application", }, }, nil default: @@ -3981,7 +4001,7 @@ func TestIdentityType(t *testing.T) { }}` servicePrincipalCreds = &fnv1.CredentialData{ Data: map[string][]byte{ - "credentials": []byte(`{ + testCredentialsKey: []byte(`{ "clientId": "test-client-id", "clientSecret": "test-client-secret", "subscriptionId": "test-subscription-id", @@ -3991,7 +4011,7 @@ func TestIdentityType(t *testing.T) { } workloadIdentityCredentials = &fnv1.CredentialData{ Data: map[string][]byte{ - "credentials": []byte(`{ + testCredentialsKey: []byte(`{ "federatedTokenFile": "/var/run/secrets/azure/tokens/azure-identity-token" }`), }, @@ -4017,7 +4037,7 @@ func TestIdentityType(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -4031,7 +4051,7 @@ func TestIdentityType(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: servicePrincipalCreds}, }, }, @@ -4039,7 +4059,7 @@ func TestIdentityType(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -4060,7 +4080,7 @@ func TestIdentityType(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -4077,7 +4097,7 @@ func TestIdentityType(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: servicePrincipalCreds}, }, }, @@ -4085,7 +4105,7 @@ func TestIdentityType(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -4106,7 +4126,7 @@ func TestIdentityType(t *testing.T) { args: args{ ctx: context.Background(), req: &fnv1.RunFunctionRequest{ - Meta: &fnv1.RequestMeta{Tag: "hello"}, + Meta: &fnv1.RequestMeta{Tag: testRequestTag}, Input: resource.MustStructJSON(`{ "apiVersion": "msgraph.fn.crossplane.io/v1alpha1", "kind": "Input", @@ -4123,7 +4143,7 @@ func TestIdentityType(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: workloadIdentityCredentials}, }, }, @@ -4131,7 +4151,7 @@ func TestIdentityType(t *testing.T) { }, want: want{ rsp: &fnv1.RunFunctionResponse{ - Meta: &fnv1.ResponseMeta{Tag: "hello", Ttl: durationpb.New(response.DefaultTTL)}, + Meta: &fnv1.ResponseMeta{Tag: testRequestTag, Ttl: durationpb.New(response.DefaultTTL)}, Results: []*fnv1.Result{ { Severity: fnv1.Severity_SEVERITY_FATAL, @@ -4195,8 +4215,8 @@ func newTestUser() models.DirectoryObjectable { user := models.NewUser() user.SetId(ptr.To("user-id-1")) user.SetDisplayName(ptr.To("Test User 1")) - user.SetMail(ptr.To("user1@example.com")) - user.SetUserPrincipalName(ptr.To("user1@example.com")) + user.SetMail(ptr.To(testUser1Email)) + user.SetUserPrincipalName(ptr.To(testUser1Email)) return user } @@ -4215,7 +4235,7 @@ func newTestUserWithoutMail() models.DirectoryObjectable { // newTestServicePrincipal builds a typed service principal directory object. func newTestServicePrincipal() models.DirectoryObjectable { sp := models.NewServicePrincipal() - sp.SetId(ptr.To("sp-id-1")) + sp.SetId(ptr.To(testSPID1)) sp.SetDisplayName(ptr.To("Test Service Principal")) sp.SetAppId(ptr.To("sp-app-id-1")) return sp @@ -4227,9 +4247,9 @@ func newTestDirectoryObject() models.DirectoryObjectable { do := models.NewDirectoryObject() do.SetId(ptr.To("user-id-2")) do.SetAdditionalData(map[string]interface{}{ - "displayName": "Fallback User", - "mail": "user2@example.com", - "userPrincipalName": "user2@example.com", + fieldDisplayName: "Fallback User", + fieldMail: testUser2Email, + fieldUserPrincipalName: testUser2Email, }) return do } @@ -4247,42 +4267,42 @@ func TestProcessMember(t *testing.T) { reason: "A typed user member should expose mail and userPrincipalName from the typed getters", member: newTestUser(), want: map[string]interface{}{ - "id": "user-id-1", - "displayName": "Test User 1", - "type": "user", - "mail": "user1@example.com", - "userPrincipalName": "user1@example.com", + "id": "user-id-1", + fieldDisplayName: "Test User 1", + fieldType: userType, + fieldMail: testUser1Email, + fieldUserPrincipalName: testUser1Email, }, }, "TypedUserWithoutMailOmitsMail": { reason: "A typed user without a mail attribute should omit mail but still expose userPrincipalName", member: newTestUserWithoutMail(), want: map[string]interface{}{ - "id": "user-id-3", - "displayName": "No Mail User", - "type": "user", - "userPrincipalName": "nomail@example.com", + "id": "user-id-3", + fieldDisplayName: "No Mail User", + fieldType: userType, + fieldUserPrincipalName: "nomail@example.com", }, }, "TypedServicePrincipalIncludesAppID": { reason: "A typed service principal member should expose appId from the typed getter", member: newTestServicePrincipal(), want: map[string]interface{}{ - "id": "sp-id-1", - "displayName": "Test Service Principal", - "type": "servicePrincipal", - "appId": "sp-app-id-1", + "id": testSPID1, + fieldDisplayName: "Test Service Principal", + fieldType: servicePrincipalType, + fieldAppID: "sp-app-id-1", }, }, "PlainDirectoryObjectUsesAdditionalDataFallback": { reason: "A plain directory object should fall back to additionalData for user properties", member: newTestDirectoryObject(), want: map[string]interface{}{ - "id": "user-id-2", - "displayName": "Fallback User", - "type": "user", - "mail": "user2@example.com", - "userPrincipalName": "user2@example.com", + "id": "user-id-2", + fieldDisplayName: "Fallback User", + fieldType: userType, + fieldMail: testUser2Email, + fieldUserPrincipalName: testUser2Email, }, }, } diff --git a/go.mod b/go.mod index d4fbac0..676a8d8 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/upbound/function-msgraph -go 1.25.10 +go 1.26.0 require ( github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.13.1 @@ -9,8 +9,8 @@ require ( github.com/google/go-cmp v0.7.0 github.com/microsoft/kiota-authentication-azure-go v1.3.1 github.com/microsoftgraph/msgraph-sdk-go v1.96.0 - google.golang.org/protobuf v1.36.11 - k8s.io/apimachinery v0.35.3 + google.golang.org/protobuf v1.36.12-0.20260120151049-f2248ac996af + k8s.io/apimachinery v0.36.2 k8s.io/utils v0.0.0-20260319190234-28399d86e0b5 sigs.k8s.io/controller-tools v0.20.1 ) @@ -107,11 +107,11 @@ require ( k8s.io/client-go v0.35.1 // indirect k8s.io/code-generator v0.35.0 // indirect k8s.io/gengo/v2 v2.0.0-20251215205346-5ee0d033ba5b // indirect - k8s.io/klog/v2 v2.130.1 // indirect - k8s.io/kube-openapi v0.0.0-20260127142750-a19766b6e2d4 // indirect + k8s.io/klog/v2 v2.140.0 // indirect + k8s.io/kube-openapi v0.0.0-20260317180543-43fb72c5454a // indirect sigs.k8s.io/controller-runtime v0.23.1 // indirect sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect sigs.k8s.io/randfill v1.0.0 // indirect - sigs.k8s.io/structured-merge-diff/v6 v6.3.2-0.20260122202528-d9cc6641c482 // indirect + sigs.k8s.io/structured-merge-diff/v6 v6.3.2 // indirect sigs.k8s.io/yaml v1.6.0 // indirect ) diff --git a/go.sum b/go.sum index 7761acf..ec2e4b4 100644 --- a/go.sum +++ b/go.sum @@ -288,8 +288,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20260427160629-7cedc36a6bc4 h1: google.golang.org/genproto/googleapis/rpc v0.0.0-20260427160629-7cedc36a6bc4/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= google.golang.org/grpc v1.81.1 h1:VnnIIZ88UzOOKLukQi+ImGz8O1Wdp8nAGGnvOfEIWQQ= google.golang.org/grpc v1.81.1/go.mod h1:xGH9GfzOyMTGIOXBJmXt+BX/V0kcdQbdcuwQ/zNw42I= -google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= -google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= +google.golang.org/protobuf v1.36.12-0.20260120151049-f2248ac996af h1:+5/Sw3GsDNlEmu7TfklWKPdQ0Ykja5VEmq2i817+jbI= +google.golang.org/protobuf v1.36.12-0.20260120151049-f2248ac996af/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= @@ -308,8 +308,8 @@ k8s.io/api v0.35.3 h1:pA2fiBc6+N9PDf7SAiluKGEBuScsTzd2uYBkA5RzNWQ= k8s.io/api v0.35.3/go.mod h1:9Y9tkBcFwKNq2sxwZTQh1Njh9qHl81D0As56tu42GA4= k8s.io/apiextensions-apiserver v0.35.0 h1:3xHk2rTOdWXXJM+RDQZJvdx0yEOgC0FgQ1PlJatA5T4= k8s.io/apiextensions-apiserver v0.35.0/go.mod h1:E1Ahk9SADaLQ4qtzYFkwUqusXTcaV2uw3l14aqpL2LU= -k8s.io/apimachinery v0.35.3 h1:MeaUwQCV3tjKP4bcwWGgZ/cp/vpsRnQzqO6J6tJyoF8= -k8s.io/apimachinery v0.35.3/go.mod h1:jQCgFZFR1F4Ik7hvr2g84RTJSZegBc8yHgFWKn//hns= +k8s.io/apimachinery v0.36.2 h1:0PE/W/WNy1UX61NLbXY5TMbJ6UwLL6E6lAPkYrKFxbQ= +k8s.io/apimachinery v0.36.2/go.mod h1:fvf/HOLXq9RId0rnDIbN1OEBvHXdQbLMM8nu0LcBUf4= k8s.io/apiserver v0.35.0 h1:CUGo5o+7hW9GcAEF3x3usT3fX4f9r8xmgQeCBDaOgX4= k8s.io/apiserver v0.35.0/go.mod h1:QUy1U4+PrzbJaM3XGu2tQ7U9A4udRRo5cyxkFX0GEds= k8s.io/client-go v0.35.1 h1:+eSfZHwuo/I19PaSxqumjqZ9l5XiTEKbIaJ+j1wLcLM= @@ -320,10 +320,10 @@ k8s.io/component-base v0.35.0 h1:+yBrOhzri2S1BVqyVSvcM3PtPyx5GUxCK2tinZz1G94= k8s.io/component-base v0.35.0/go.mod h1:85SCX4UCa6SCFt6p3IKAPej7jSnF3L8EbfSyMZayJR0= k8s.io/gengo/v2 v2.0.0-20251215205346-5ee0d033ba5b h1:0YkdvW3rX2vaBWsqCGZAekxPRwaI5NuYNprOsMNVLns= k8s.io/gengo/v2 v2.0.0-20251215205346-5ee0d033ba5b/go.mod h1:yvyl3l9E+UxlqOMUULdKTAYB0rEhsmjr7+2Vb/1pCSo= -k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= -k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= -k8s.io/kube-openapi v0.0.0-20260127142750-a19766b6e2d4 h1:HhDfevmPS+OalTjQRKbTHppRIz01AWi8s45TMXStgYY= -k8s.io/kube-openapi v0.0.0-20260127142750-a19766b6e2d4/go.mod h1:kdmbQkyfwUagLfXIad1y2TdrjPFWp2Q89B3qkRwf/pQ= +k8s.io/klog/v2 v2.140.0 h1:Tf+J3AH7xnUzZyVVXhTgGhEKnFqye14aadWv7bzXdzc= +k8s.io/klog/v2 v2.140.0/go.mod h1:o+/RWfJ6PwpnFn7OyAG3QnO47BFsymfEfrz6XyYSSp0= +k8s.io/kube-openapi v0.0.0-20260317180543-43fb72c5454a h1:xCeOEAOoGYl2jnJoHkC3hkbPJgdATINPMAxaynU2Ovg= +k8s.io/kube-openapi v0.0.0-20260317180543-43fb72c5454a/go.mod h1:uGBT7iTA6c6MvqUvSXIaYZo9ukscABYi2btjhvgKGZ0= k8s.io/utils v0.0.0-20260319190234-28399d86e0b5 h1:kBawHLSnx/mYHmRnNUf9d4CpjREbeZuxoSGOX/J+aYM= k8s.io/utils v0.0.0-20260319190234-28399d86e0b5/go.mod h1:xDxuJ0whA3d0I4mf/C4ppKHxXynQ+fxnkmQH0vTHnuk= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.34.0 h1:hSfpvjjTQXQY2Fol2CS0QHMNs/WI1MOSGzCm1KhM5ec= @@ -336,7 +336,7 @@ sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 h1:IpInykpT6ceI+QxKBbEflcR5E sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg= sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU= sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY= -sigs.k8s.io/structured-merge-diff/v6 v6.3.2-0.20260122202528-d9cc6641c482 h1:2WOzJpHUBVrrkDjU4KBT8n5LDcj824eX0I5UKcgeRUs= -sigs.k8s.io/structured-merge-diff/v6 v6.3.2-0.20260122202528-d9cc6641c482/go.mod h1:M3W8sfWvn2HhQDIbGWj3S099YozAsymCo/wrT5ohRUE= +sigs.k8s.io/structured-merge-diff/v6 v6.3.2 h1:kwVWMx5yS1CrnFWA/2QHyRVJ8jM6dBA80uLmm0wJkk8= +sigs.k8s.io/structured-merge-diff/v6 v6.3.2/go.mod h1:M3W8sfWvn2HhQDIbGWj3S099YozAsymCo/wrT5ohRUE= sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs= sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4=