This repository has been archived by the owner on Aug 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain_test.go
85 lines (71 loc) · 2.32 KB
/
main_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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"context"
"testing"
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/resources"
"github.com/Azure/go-autorest/autorest"
"github.com/whiteducksoftware/azure-arm-action/pkg/github"
"github.com/whiteducksoftware/azure-arm-action/pkg/github/actions"
)
var (
opts github.Options
authorizer autorest.Authorizer
deploymentResult resources.DeploymentExtended
)
func TestLoadOptions(t *testing.T) {
var err error
opts, err = github.LoadOptions()
if err != nil {
t.Error(err.Error())
}
}
func TestAuthentication(t *testing.T) {
var err error
authorizer, err = actions.Authenticate(opts)
if err != nil {
t.Error(err.Error())
}
}
func TestDeploy(t *testing.T) {
var err error
deploymentResult, err = actions.Deploy(context.Background(), opts, authorizer)
if err != nil {
t.Error(err.Error())
}
}
func TestParseOutputs(t *testing.T) {
outputs, err := actions.ParseOutputs(deploymentResult.Properties.Outputs)
if err != nil {
t.Error(err.Error())
}
if len(outputs) != 3 {
t.Errorf("Got invalid count of outputs, expected got %d", len(outputs))
}
// Test output key location
value, ok := outputs["location"]
if !ok {
t.Errorf("Test key is missing in the outputs, exptected the key location to be present")
}
if value.Value != "westeurope" {
t.Errorf("Got invalid value for location key, expected %s got %s", "westeurope", value.Value)
}
// Test output key containername
value, ok = outputs["containerName"]
if !ok {
t.Errorf("Test key is missing in the outputs, exptected the key containerName to be present")
}
// This also tests if the override did work
if value.Value != "github-action-overriden" {
t.Errorf("Got invalid value for containerName key, expected %s got %s", "github-action-overriden", value.Value)
}
// Test output key containername
value, ok = outputs["connectionString"]
if !ok {
t.Errorf("Test key is missing in the outputs, exptected the key containerName to be present")
}
// This also tests if the override did work
var expectedConnectionString = "Server=tcp:test.database.windows.net;Database=test;User ID=test;Password=test;Trusted_Connection=False;Encrypt=True;"
if value.Value != expectedConnectionString {
t.Errorf("Got invalid value for connectionString key, expected %s got %s", expectedConnectionString, value.Value)
}
}