forked from kedacore/keda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcp_pubsub_scaler_test.go
40 lines (35 loc) · 1.33 KB
/
gcp_pubsub_scaler_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package scalers
import (
"testing"
)
var testPubSubResolvedEnv = map[string]string{
"SAMPLE_CREDS": "{}",
}
type parsePubSubMetadataTestData struct {
metadata map[string]string
isError bool
}
var testPubSubMetadata = []parsePubSubMetadataTestData{
{map[string]string{}, true},
// all properly formed
{map[string]string{"subscriptionName": "mysubscription", "subscriptionSize": "7", "credentials": "SAMPLE_CREDS"}, false},
// missing subscriptionName
{map[string]string{"subscriptionName": "", "subscriptionSize": "7", "credentials": "SAMPLE_CREDS"}, true},
// missing credentials
{map[string]string{"subscriptionName": "mysubscription", "subscriptionSize": "7", "credentials": ""}, true},
// incorrect credentials
{map[string]string{"subscriptionName": "mysubscription", "subscriptionSize": "7", "credentials": "WRONG_CREDS"}, true},
// malformed subscriptionSize
{map[string]string{"subscriptionName": "mysubscription", "subscriptionSize": "AA", "credentials": "SAMPLE_CREDS"}, true},
}
func TestPubSubParseMetadata(t *testing.T) {
for _, testData := range testPubSubMetadata {
_, err := parsePubSubMetadata(testData.metadata, testPubSubResolvedEnv)
if err != nil && !testData.isError {
t.Error("Expected success but got error", err)
}
if testData.isError && err == nil {
t.Error("Expected error but got success")
}
}
}