-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rick Brouwer <[email protected]>
- Loading branch information
1 parent
fa68ac5
commit e253199
Showing
3 changed files
with
102 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,29 +5,113 @@ import ( | |
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/kedacore/keda/v2/apis/keda/v1alpha1" | ||
"github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" | ||
) | ||
|
||
type parseMSSQLMetadataTestData struct { | ||
name string | ||
metadata map[string]string | ||
resolvedEnv map[string]string | ||
authParams map[string]string | ||
podIdentity v1alpha1.AuthPodIdentity | ||
expectedError string | ||
name string | ||
metadata map[string]string | ||
resolvedEnv map[string]string | ||
authParams map[string]string | ||
podIdentity v1alpha1.AuthPodIdentity | ||
expectedError string | ||
expectedConnectionString string | ||
expectedMetricName string | ||
} | ||
|
||
var testMSSQLMetadata = []parseMSSQLMetadataTestData{ | ||
{ | ||
name: "Valid metadata", | ||
metadata: map[string]string{"query": "SELECT 1", "targetValue": "1", "host": "localhost"}, | ||
resolvedEnv: map[string]string{}, | ||
authParams: map[string]string{}, | ||
expectedError: "", | ||
name: "Direct connection string input", | ||
metadata: map[string]string{"query": "SELECT 1", "targetValue": "1"}, | ||
resolvedEnv: map[string]string{}, | ||
authParams: map[string]string{"connectionString": "sqlserver://localhost"}, | ||
expectedConnectionString: "sqlserver://localhost", | ||
}, | ||
{ | ||
name: "Direct connection string input with activationTargetValue", | ||
metadata: map[string]string{"query": "SELECT 1", "targetValue": "1", "activationTargetValue": "20"}, | ||
resolvedEnv: map[string]string{}, | ||
authParams: map[string]string{"connectionString": "sqlserver://localhost"}, | ||
expectedConnectionString: "sqlserver://localhost", | ||
}, | ||
{ | ||
name: "Direct connection string input, OLEDB format", | ||
metadata: map[string]string{"query": "SELECT 1", "targetValue": "1"}, | ||
resolvedEnv: map[string]string{}, | ||
authParams: map[string]string{"connectionString": "Server=example.database.windows.net;port=1433;Database=AdventureWorks;Persist Security Info=False;User ID=user1;Password=Password#1;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"}, | ||
expectedConnectionString: "Server=example.database.windows.net;port=1433;Database=AdventureWorks;Persist Security Info=False;User ID=user1;Password=Password#1;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;", | ||
}, | ||
{ | ||
name: "Connection string input via environment variables", | ||
metadata: map[string]string{"query": "SELECT 1", "targetValue": "1", "connectionStringFromEnv": "test_connection_string"}, | ||
resolvedEnv: map[string]string{"test_connection_string": "sqlserver://localhost?database=AdventureWorks"}, | ||
authParams: map[string]string{}, | ||
expectedConnectionString: "sqlserver://localhost?database=AdventureWorks", | ||
}, | ||
{ | ||
name: "Connection string generated from minimal required metadata", | ||
metadata: map[string]string{"query": "SELECT 1", "targetValue": "1", "host": "127.0.0.1"}, | ||
resolvedEnv: map[string]string{}, | ||
authParams: map[string]string{}, | ||
expectedMetricName: "mssql", | ||
expectedConnectionString: "sqlserver://127.0.0.1", | ||
}, | ||
{ | ||
name: "Connection string generated from full metadata", | ||
metadata: map[string]string{"query": "SELECT 1", "targetValue": "1", "host": "example.database.windows.net", "username": "user1", "passwordFromEnv": "test_password", "port": "1433", "database": "AdventureWorks"}, | ||
resolvedEnv: map[string]string{"test_password": "Password#1"}, | ||
authParams: map[string]string{}, | ||
expectedConnectionString: "sqlserver://user1:Password%[email protected]:1433?database=AdventureWorks", | ||
}, | ||
{ | ||
name: "Variation of previous: no port, password from authParams, metricName from database name", | ||
metadata: map[string]string{"query": "SELECT 1", "targetValue": "1", "host": "example.database.windows.net", "username": "user2", "database": "AdventureWorks"}, | ||
resolvedEnv: map[string]string{}, | ||
authParams: map[string]string{"password": "Password#2"}, | ||
expectedMetricName: "mssql", | ||
expectedConnectionString: "sqlserver://user2:Password%[email protected]?database=AdventureWorks", | ||
}, | ||
{ | ||
name: "Connection string generated from full authParams", | ||
metadata: map[string]string{"query": "SELECT 1", "targetValue": "1"}, | ||
resolvedEnv: map[string]string{}, | ||
authParams: map[string]string{"password": "Password#2", "host": "example.database.windows.net", "username": "user2", "database": "AdventureWorks", "port": "1433"}, | ||
expectedMetricName: "mssql", | ||
expectedConnectionString: "sqlserver://user2:Password%[email protected]:1433?database=AdventureWorks", | ||
}, | ||
{ | ||
name: "Variation of previous: no database name, metricName from host", | ||
metadata: map[string]string{"query": "SELECT 1", "targetValue": "1", "host": "example.database.windows.net", "username": "user3"}, | ||
resolvedEnv: map[string]string{}, | ||
authParams: map[string]string{"password": "Password#3"}, | ||
expectedMetricName: "mssql", | ||
expectedConnectionString: "sqlserver://user3:Password%[email protected]", | ||
}, | ||
{ | ||
name: "Valid metadata with Azure Workload Identity", | ||
name: "Error: missing query", | ||
metadata: map[string]string{"targetValue": "1"}, | ||
resolvedEnv: map[string]string{}, | ||
authParams: map[string]string{"connectionString": "sqlserver://localhost"}, | ||
expectedError: "missing required parameter \"query\" in [triggerMetadata]", | ||
}, | ||
{ | ||
name: "Error: missing targetValue", | ||
metadata: map[string]string{"query": "SELECT 1"}, | ||
resolvedEnv: map[string]string{}, | ||
authParams: map[string]string{"connectionString": "sqlserver://localhost"}, | ||
expectedError: "missing required parameter \"targetValue\"in [triggerMetadata]", | ||
}, | ||
{ | ||
name: "Error: missing host", | ||
metadata: map[string]string{"query": "SELECT 1", "targetValue": "1"}, | ||
resolvedEnv: map[string]string{}, | ||
authParams: map[string]string{}, | ||
expectedError: "must provide either connectionstring or host", | ||
}, | ||
{ | ||
name: "Valid metadata with Azure Workload Identity", | ||
metadata: map[string]string{ | ||
"query": "SELECT COUNT(*) FROM table", | ||
"targetValue": "5", | ||
|
@@ -44,34 +128,6 @@ var testMSSQLMetadata = []parseMSSQLMetadataTestData{ | |
}, | ||
expectedError: "", | ||
}, | ||
{ | ||
name: "Missing query", | ||
metadata: map[string]string{"targetValue": "1", "host": "localhost"}, | ||
resolvedEnv: map[string]string{}, | ||
authParams: map[string]string{}, | ||
expectedError: "missing required parameter \"query\"", | ||
}, | ||
{ | ||
name: "Missing targetValue", | ||
metadata: map[string]string{"query": "SELECT 1", "host": "localhost"}, | ||
resolvedEnv: map[string]string{}, | ||
authParams: map[string]string{}, | ||
expectedError: "missing required parameter \"targetValue\"", | ||
}, | ||
{ | ||
name: "Invalid targetValue", | ||
metadata: map[string]string{"query": "SELECT 1", "targetValue": "invalid", "host": "localhost"}, | ||
resolvedEnv: map[string]string{}, | ||
authParams: map[string]string{}, | ||
expectedError: "error parsing targetValue", | ||
}, | ||
{ | ||
name: "Missing host", | ||
metadata: map[string]string{"query": "SELECT 1", "targetValue": "1"}, | ||
resolvedEnv: map[string]string{}, | ||
authParams: map[string]string{}, | ||
expectedError: "missing required parameter \"host\"", | ||
}, | ||
} | ||
|
||
func TestParseMSSQLMetadata(t *testing.T) { | ||
|
@@ -123,7 +179,7 @@ func TestMSSQLGetMetricSpecForScaling(t *testing.T) { | |
assert.NoError(t, err) | ||
|
||
mockMSSQLScaler := mssqlScaler{ | ||
metadata: *meta, | ||
metadata: meta, | ||
} | ||
|
||
metricSpec := mockMSSQLScaler.GetMetricSpecForScaling(context.Background()) | ||
|