forked from rancher/go-machine-service
/
azure_test.go
77 lines (65 loc) · 1.78 KB
/
azure_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
package handlers
import (
"github.com/rancherio/go-machine-service/events"
"github.com/rancherio/go-rancher/client"
"os"
"strconv"
"testing"
"time"
)
func TestAzure(t *testing.T) {
subscriptionId := os.Getenv("SUBSCRIPTION_ID")
if subscriptionId == "" {
t.Log("Skipping Azure test.")
return
}
subscriptionCert := os.Getenv("SUBSCRIPTION_CERT")
if subscriptionCert == "" {
t.Log("Skipping Azure test.")
return
}
setupAZ(subscriptionId, subscriptionCert)
resourceId := "AZ-" + strconv.FormatInt(time.Now().Unix(), 10)
event := &events.Event{
ResourceId: resourceId,
Id: "event-id",
ReplyTo: "reply-to-id",
}
mockApiClient := &client.RancherClient{}
err := CreateMachine(event, mockApiClient)
if err != nil {
t.Fatal(err)
}
err = ActivateMachine(event, mockApiClient)
if err != nil {
// Fail, not a fatal, so purge will still run.
t.Log(err)
t.Fail()
}
err = PurgeMachine(event, mockApiClient)
if err != nil {
t.Fatal(err)
}
}
func setupAZ(subscription_id, subscription_cert string) {
// TODO Replace functions during teardown.
machine := &client.Machine{
AzureConfig: &client.AzureConfig{
SubscriptionId: subscription_id,
SubscriptionCert: subscription_cert,
},
Kind: "machine",
Driver: "azure",
}
getMachine = func(id string, apiClient *client.RancherClient) (*client.Machine, error) {
machine.Id = id
machine.Name = "name-" + id
machine.ExternalId = "ext-" + id
return machine, nil
}
getRegistrationUrlAndImage = func(accountId string, apiClient *client.RancherClient) (string, string, string, error) {
return "http://1.2.3.4/v1", "rancher/agent", "v0.7.6", nil
}
publishReply = buildMockPublishReply(machine)
publishTransitioningReply = func(msg string, event *events.Event, apiClient *client.RancherClient) {}
}