Skip to content

Commit

Permalink
Removing old test
Browse files Browse the repository at this point in the history
  • Loading branch information
aagusuab committed Nov 22, 2024
1 parent 1a731f0 commit 11f7818
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 40 deletions.
19 changes: 15 additions & 4 deletions pkg/scalers/azure/azure_app_insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,23 @@ func queryParamsForAppInsightsRequest(info AppInsightsInfo) (map[string]interfac
return queryParams, nil
}

func getAuthConfig(ctx context.Context, info AppInsightsInfo, podIdentity kedav1alpha1.AuthPodIdentity) (AADToken, error) {
token := AADToken{}
var err error

switch podIdentity.Provider {
case "", kedav1alpha1.PodIdentityProviderNone:
token, err = GetAzureADWorkloadIdentityToken(ctx, info.ClientID, info.TenantID, info.ActiveDirectoryEndpoint, info.AppInsightsResourceURL)
case kedav1alpha1.PodIdentityProviderAzureWorkload:
token, err = GetAzureADWorkloadIdentityToken(ctx, podIdentity.GetIdentityID(), podIdentity.GetIdentityTenantID(), podIdentity.GetIdentityAuthorityHost(), info.AppInsightsResourceURL)
}

return token, err
}

// GetAzureAppInsightsMetricValue returns the value of an Azure App Insights metric, rounded to the nearest int
func GetAzureAppInsightsMetricValue(ctx context.Context, info AppInsightsInfo, podIdentity kedav1alpha1.AuthPodIdentity, ignoreNullValues bool) (float64, error) {
token, err := GetAzureADWorkloadIdentityToken(ctx, podIdentity.GetIdentityID(), podIdentity.GetIdentityTenantID(), "", info.AppInsightsResourceURL)
if err != nil {
return -1, err
}
token, err := getAuthConfig(ctx, info, podIdentity)

queryParams, err := queryParamsForAppInsightsRequest(info)
if err != nil {
Expand Down
36 changes: 0 additions & 36 deletions pkg/scalers/azure/azure_app_insights_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package azure

import (
"context"
"testing"

kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1"
)

type testExtractAzAppInsightsTestData struct {
Expand Down Expand Up @@ -67,39 +64,6 @@ func TestAzGetAzureAppInsightsMetricValue(t *testing.T) {
}
}

type testAppInsightsAuthConfigTestData struct {
testName string
config string
info AppInsightsInfo
podIdentity kedav1alpha1.PodIdentityProvider
}

const (
msiConfig = "msiConfig"
clientCredentialsConfig = "clientCredentialsConfig"
workloadIdentityConfig = "workloadIdentityConfig"
)

var testAppInsightsAuthConfigData = []testAppInsightsAuthConfigTestData{
{"client credentials", clientCredentialsConfig, AppInsightsInfo{ClientID: "1234", ClientPassword: "pw", TenantID: "5678"}, ""},
{"client credentials - pod id none", clientCredentialsConfig, AppInsightsInfo{ClientID: "1234", ClientPassword: "pw", TenantID: "5678"}, kedav1alpha1.PodIdentityProviderNone},
{"azure workload identity", workloadIdentityConfig, AppInsightsInfo{}, kedav1alpha1.PodIdentityProviderAzureWorkload},
}

func TestAzAppInfoGetToken(t *testing.T) {
for _, testData := range testAppInsightsAuthConfigData {
authToken, err := GetAzureADWorkloadIdentityToken(context.TODO(), testData.info.ClientID, testData.info.TenantID, "", testData.info.AppInsightsResourceURL)

if err != nil {
t.Errorf("Test %v; Expected success but got error: %v", testData.testName, err)
}
if authToken.AccessToken == "" {
t.Errorf("Test %v; Expected token but got empty token: %v", testData.testName, authToken)
}
t.Logf("Test %v; data: %v, token: %v", testData.testName, testData.info, authToken)
}
}

type toISO8601TestData struct {
testName string
isError bool
Expand Down

0 comments on commit 11f7818

Please sign in to comment.