From c35d1580ece7f0853be4db24ac746942f9efef55 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2026 16:42:00 +0000 Subject: [PATCH 1/6] Update module k8s.io/apimachinery to v0.36.2 --- go.mod | 12 ++++++------ go.sum | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) 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= From f6e231bdb976e5d7ebe2828331405da6fc0d9fbf Mon Sep 17 00:00:00 2001 From: Yury Tsarev Date: Tue, 21 Jul 2026 13:32:35 +0200 Subject: [PATCH 2/6] ci: bump GO_VERSION to 1.26.0 to match go.mod directive k8s.io/apimachinery v0.36.2 raised the go.mod go directive to 1.26.0, but CI pinned GO_VERSION=1.25.10 with GOTOOLCHAIN=local, causing lint, unit-test and build jobs to fail with: go: go.mod requires go >= 1.26.0 (running go 1.25.10; GOTOOLCHAIN=local) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b312b2c..5430389 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ on: env: # Common versions - GO_VERSION: '1.25.10' + GO_VERSION: '1.26.0' GOLANGCI_VERSION: 'v2.8.0' DOCKER_BUILDX_VERSION: 'v0.23.0' From e9e15d611ef680bc84207e8d643ba1c8ad1b10c7 Mon Sep 17 00:00:00 2001 From: Yury Tsarev Date: Tue, 21 Jul 2026 14:10:00 +0200 Subject: [PATCH 3/6] ci: bump golangci-lint to v2.12.2 for Go 1.26 golangci-lint v2.8.0 is built with Go 1.25 and refuses to lint a module targeting Go 1.26: can't load config: the Go language version (go1.25) used to build golangci-lint is lower than the targeted Go version (1.26.0) v2.12.2 is built with Go 1.26. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5430389..8b2cfb1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ on: env: # Common versions GO_VERSION: '1.26.0' - GOLANGCI_VERSION: 'v2.8.0' + GOLANGCI_VERSION: 'v2.12.2' DOCKER_BUILDX_VERSION: 'v0.23.0' # These environment variables are important to the Crossplane CLI install.sh From 68d58405c92ff99a06859bfbc81868bbea26a688 Mon Sep 17 00:00:00 2001 From: Yury Tsarev Date: Tue, 21 Jul 2026 14:22:35 +0200 Subject: [PATCH 4/6] lint: resolve new goconst findings under golangci-lint v2.12.2 The golangci-lint v2.12.2 bump (needed for Go 1.26) surfaced goconst findings that v2.8.0 did not report: - fn.go: extract repeated Microsoft Graph field-name literals (displayName, appId, description) into named constants. - .golangci.yml: set goconst.ignore-tests to skip repeated string literals in test fixtures, where extracting constants would only reduce readability. No behavior change. Verified locally with golangci-lint v2.11.4 (built with go1.26.1): 0 issues, all unit tests pass. --- .golangci.yml | 1 + fn.go | 44 ++++++++++++++++++++++++++------------------ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c236438..c7c703a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -53,6 +53,7 @@ linters: goconst: min-len: 3 min-occurrences: 5 + ignore-tests: true gocritic: enabled-tags: - performance diff --git a/fn.go b/fn.go index 09320c3..62175f2 100644 --- a/fn.go +++ b/fn.go @@ -63,6 +63,14 @@ 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" +) + // 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 +534,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, "userPrincipalName", "mail"} // Execute the query result, err := client.Users().Get(ctx, requestConfig) @@ -539,7 +547,7 @@ func (g *GraphQuery) validateUsers(ctx context.Context, client *msgraphsdk.Graph for _, user := range result.GetValue() { userMap := map[string]interface{}{ "id": ptr.Deref(user.GetId(), ""), - "displayName": ptr.Deref(user.GetDisplayName(), ""), + fieldDisplayName: ptr.Deref(user.GetDisplayName(), ""), "userPrincipalName": ptr.Deref(user.GetUserPrincipalName(), ""), "mail": ptr.Deref(user.GetMail(), ""), } @@ -617,7 +625,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 } @@ -682,14 +690,14 @@ 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 } } } @@ -722,7 +730,7 @@ func (g *GraphQuery) processMember(member models.DirectoryObjectable) map[string } // Check properties that indicate service principal type - _, hasAppID := g.extractStringProperty(additionalData, "appId") + _, hasAppID := g.extractStringProperty(additionalData, fieldAppID) if hasAppID { memberType = servicePrincipalType } @@ -739,7 +747,7 @@ func (g *GraphQuery) processMember(member models.DirectoryObjectable) map[string memberMap["type"] = memberType // Extract display name - memberMap["displayName"] = g.extractDisplayName(member, memberID) + memberMap[fieldDisplayName] = g.extractDisplayName(member, memberID) // Extract type-specific properties switch memberType { @@ -809,7 +817,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 +827,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 +862,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 +872,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) } From a27362c06654286c4587b585e756921bd43b12e7 Mon Sep 17 00:00:00 2001 From: Yury Tsarev Date: Tue, 21 Jul 2026 14:35:58 +0200 Subject: [PATCH 5/6] lint: extract test constants instead of ignoring tests for goconst Reverts goconst.ignore-tests so test code is linted too, and instead resolves the goconst findings by extracting the repeated string literals in fn_test.go into named constants: - fn.go: add fieldMail, fieldUserPrincipalName, fieldType field-name constants (alongside the existing displayName/appId/description) and use them in production map keys and $select projections. - fn_test.go: add a fixture const block (testRequestTag, testAzureCredsName, condTypeFunctionSuccess, the per-query-type messages, etc.) and reuse the field-name constants across the table-driven cases. Literals inside raw-string JSON fixtures are left untouched (they are single string literals, not separate tokens). No behavior change; verified locally with golangci-lint: 0 issues, all unit tests pass. --- .golangci.yml | 1 - fn.go | 41 +-- fn_test.go | 677 ++++++++++++++++++++++++++------------------------ 3 files changed, 370 insertions(+), 349 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c7c703a..c236438 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -53,7 +53,6 @@ linters: goconst: min-len: 3 min-occurrences: 5 - ignore-tests: true gocritic: enabled-tags: - performance diff --git a/fn.go b/fn.go index 62175f2..0c7b95b 100644 --- a/fn.go +++ b/fn.go @@ -66,9 +66,12 @@ const ( const ( // Microsoft Graph field names used in query projections ($select) and in the // maps returned for query results. - fieldDisplayName = "displayName" - fieldAppID = "appId" - fieldDescription = "description" + fieldDisplayName = "displayName" + fieldAppID = "appId" + fieldDescription = "description" + fieldMail = "mail" + fieldUserPrincipalName = "userPrincipalName" + fieldType = "type" ) // GraphQueryInterface defines the methods required for querying Microsoft Graph API. @@ -534,7 +537,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", fieldDisplayName, "userPrincipalName", "mail"} + requestConfig.QueryParameters.Select = []string{"id", fieldDisplayName, fieldUserPrincipalName, fieldMail} // Execute the query result, err := client.Users().Get(ctx, requestConfig) @@ -546,10 +549,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(), ""), - fieldDisplayName: 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) } @@ -665,22 +668,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 } } } @@ -723,8 +726,8 @@ 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 } @@ -744,7 +747,7 @@ func (g *GraphQuery) processMember(member models.DirectoryObjectable) map[string } // Add type to member info - memberMap["type"] = memberType + memberMap[fieldType] = memberType // Extract display name memberMap[fieldDisplayName] = g.extractDisplayName(member, memberID) diff --git a/fn_test.go b/fn_test.go index 0042956..137ee3d 100644 --- a/fn_test.go +++ b/fn_test.go @@ -20,6 +20,25 @@ 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" + 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 +59,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 +88,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 +108,7 @@ func TestResolveGroupsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -97,19 +116,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 +167,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 +184,7 @@ func TestResolveGroupsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -173,19 +192,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 +251,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 +273,7 @@ func TestResolveGroupsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -262,19 +281,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 +336,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 +358,7 @@ func TestResolveGroupsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -347,19 +366,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 +405,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 +428,7 @@ func TestResolveGroupsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -417,19 +436,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 +475,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 +498,7 @@ func TestResolveGroupsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -487,7 +506,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 +535,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 +549,7 @@ func TestResolveGroupsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -538,7 +557,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 +612,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 +647,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 +676,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 +698,7 @@ func TestResolveGroupRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -687,12 +706,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 +757,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 +776,7 @@ func TestResolveGroupRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -765,12 +784,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 +843,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 +865,7 @@ func TestResolveGroupRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -854,12 +873,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 +926,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 +940,7 @@ func TestResolveGroupRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -929,7 +948,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 +986,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: "user1@example.com", + fieldUserPrincipalName: "user1@example.com", + fieldType: "user", }, 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: "servicePrincipal", }, }, nil } @@ -1008,7 +1027,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 +1056,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 +1076,7 @@ func TestResolveUsersRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1065,19 +1084,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 +1138,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 +1155,7 @@ func TestResolveUsersRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1144,19 +1163,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 +1225,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 +1247,7 @@ func TestResolveUsersRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1236,19 +1255,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 +1313,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 +1335,7 @@ func TestResolveUsersRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1324,19 +1343,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 +1382,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 +1405,7 @@ func TestResolveUsersRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1394,19 +1413,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 +1452,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 +1475,7 @@ func TestResolveUsersRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1464,7 +1483,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 +1512,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 +1526,7 @@ func TestResolveUsersRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1515,7 +1534,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, @@ -1568,7 +1587,7 @@ func TestResolveUsersRef(t *testing.T) { case "user1@example.com": 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 +1599,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 +1635,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 +1664,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 +1684,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1673,19 +1692,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 +1746,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 +1763,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1752,19 +1771,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 +1833,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 +1855,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1844,19 +1863,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 +1921,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 +1943,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -1932,19 +1951,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 +1990,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 +2013,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2002,19 +2021,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 +2060,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 +2083,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2072,7 +2091,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 +2120,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 +2134,7 @@ func TestResolveServicePrincipalsRef(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2123,7 +2142,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 +2194,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 +2212,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 +2248,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 +2276,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 +2292,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 +2321,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 +2334,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2323,7 +2342,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 +2372,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 +2385,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2374,7 +2393,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 +2423,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 +2437,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2426,19 +2445,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 +2492,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 +2505,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2494,7 +2513,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 +2543,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 +2557,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2546,12 +2565,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 +2619,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 +2632,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2621,7 +2640,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 +2670,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 +2684,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2673,19 +2692,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 +2743,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 +2756,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2745,7 +2764,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 +2794,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 +2808,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2797,19 +2816,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 +2863,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 +2876,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2865,7 +2884,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 +2914,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 +2942,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -2931,7 +2950,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 +2960,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 +2991,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 +3022,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -3011,7 +3030,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 +3040,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 +3074,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 +3105,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -3094,19 +3113,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 +3157,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 +3172,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -3161,19 +3180,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 +3230,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 +3245,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -3234,7 +3253,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 +3283,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 +3299,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -3288,12 +3307,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 +3324,7 @@ func TestRunFunction(t *testing.T) { }, { Severity: fnv1.Severity_SEVERITY_NORMAL, - Message: `QueryType: "UserValidation"`, + Message: msgUserValidationQueryType, Target: fnv1.Target_TARGET_COMPOSITE.Enum(), }, }, @@ -3343,7 +3362,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 +3376,7 @@ func TestRunFunction(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: creds}, }, }, @@ -3365,19 +3384,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 +3434,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 +3443,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 +3452,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 +3468,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 +3477,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 +3490,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 +3506,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 +3515,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 +3535,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 +3551,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 +3560,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 +3575,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 +3591,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 +3600,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 +3617,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 +3633,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 +3642,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 +3681,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 +3722,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 +3731,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 +3773,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 +3815,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 +3824,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 +3863,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 +3913,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 +3925,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: "user1@example.com", + fieldUserPrincipalName: "user1@example.com", + fieldType: "user", }, 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: "servicePrincipal", }, }, nil case "GroupObjectIDs": @@ -3925,14 +3944,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 +3960,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 +4000,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 +4010,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 +4036,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 +4050,7 @@ func TestIdentityType(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: servicePrincipalCreds}, }, }, @@ -4039,7 +4058,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 +4079,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 +4096,7 @@ func TestIdentityType(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: servicePrincipalCreds}, }, }, @@ -4085,7 +4104,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 +4125,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 +4142,7 @@ func TestIdentityType(t *testing.T) { }, }, Credentials: map[string]*fnv1.Credentials{ - "azure-creds": { + testAzureCredsName: { Source: &fnv1.Credentials_CredentialData{CredentialData: workloadIdentityCredentials}, }, }, @@ -4131,7 +4150,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, @@ -4215,7 +4234,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 +4246,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 +4266,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: "user", + fieldMail: "user1@example.com", + fieldUserPrincipalName: "user1@example.com", }, }, "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: "user", + 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: "servicePrincipal", + 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: "user", + fieldMail: testUser2Email, + fieldUserPrincipalName: testUser2Email, }, }, } From c5bc206a7b67c24204d80be6a31aaef1363d7aff Mon Sep 17 00:00:00 2001 From: Yury Tsarev Date: Tue, 21 Jul 2026 14:44:59 +0200 Subject: [PATCH 6/6] lint: reuse member-type constants and add user1 email fixture Two goconst findings surfaced only under golangci-lint v2.12.2 (local v2.11.4 did not report them): - Promote userType/servicePrincipalType/unknownType from function-local constants in processMember to package level, and reuse them for the repeated "user"/"servicePrincipal" literals in fn_test.go. - Add testUser1Email for the repeated "user1@example.com" fixture. Verified with golangci-lint v2.12.2 (CI parity): 0 issues, tests pass. --- fn.go | 14 +++++++------- fn_test.go | 35 ++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/fn.go b/fn.go index 0c7b95b..df9a5ed 100644 --- a/fn.go +++ b/fn.go @@ -74,6 +74,13 @@ const ( 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) @@ -707,13 +714,6 @@ func (g *GraphQuery) extractServicePrincipalProperties(member models.DirectoryOb // 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() diff --git a/fn_test.go b/fn_test.go index 137ee3d..9b53a3e 100644 --- a/fn_test.go +++ b/fn_test.go @@ -26,6 +26,7 @@ const ( testCredentialsKey = "credentials" testAzureCredsName = "azure-creds" testSPID1 = "sp-id-1" + testUser1Email = "user1@example.com" testUser2Email = "user2@example.com" watchedResourceKey = "ops.crossplane.io/watched-resource" @@ -988,15 +989,15 @@ func TestResolveGroupRef(t *testing.T) { map[string]interface{}{ "id": "user-id-1", fieldDisplayName: "Test User 1", - fieldMail: "user1@example.com", - fieldUserPrincipalName: "user1@example.com", - fieldType: "user", + fieldMail: testUser1Email, + fieldUserPrincipalName: testUser1Email, + fieldType: userType, }, map[string]interface{}{ "id": testSPID1, fieldDisplayName: "Test Service Principal", fieldAppID: "sp-app-id-1", - fieldType: "servicePrincipal", + fieldType: servicePrincipalType, }, }, nil } @@ -1584,7 +1585,7 @@ 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 testUser2Email: @@ -3927,15 +3928,15 @@ func TestRunFunction(t *testing.T) { map[string]interface{}{ "id": "user-id-1", fieldDisplayName: "Test User 1", - fieldMail: "user1@example.com", - fieldUserPrincipalName: "user1@example.com", - fieldType: "user", + fieldMail: testUser1Email, + fieldUserPrincipalName: testUser1Email, + fieldType: userType, }, map[string]interface{}{ "id": testSPID1, fieldDisplayName: "Test Service Principal", fieldAppID: "sp-app-id-1", - fieldType: "servicePrincipal", + fieldType: servicePrincipalType, }, }, nil case "GroupObjectIDs": @@ -4214,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 } @@ -4268,9 +4269,9 @@ func TestProcessMember(t *testing.T) { want: map[string]interface{}{ "id": "user-id-1", fieldDisplayName: "Test User 1", - fieldType: "user", - fieldMail: "user1@example.com", - fieldUserPrincipalName: "user1@example.com", + fieldType: userType, + fieldMail: testUser1Email, + fieldUserPrincipalName: testUser1Email, }, }, "TypedUserWithoutMailOmitsMail": { @@ -4279,7 +4280,7 @@ func TestProcessMember(t *testing.T) { want: map[string]interface{}{ "id": "user-id-3", fieldDisplayName: "No Mail User", - fieldType: "user", + fieldType: userType, fieldUserPrincipalName: "nomail@example.com", }, }, @@ -4289,7 +4290,7 @@ func TestProcessMember(t *testing.T) { want: map[string]interface{}{ "id": testSPID1, fieldDisplayName: "Test Service Principal", - fieldType: "servicePrincipal", + fieldType: servicePrincipalType, fieldAppID: "sp-app-id-1", }, }, @@ -4299,7 +4300,7 @@ func TestProcessMember(t *testing.T) { want: map[string]interface{}{ "id": "user-id-2", fieldDisplayName: "Fallback User", - fieldType: "user", + fieldType: userType, fieldMail: testUser2Email, fieldUserPrincipalName: testUser2Email, },