This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 561
/
mocks.go
165 lines (142 loc) · 4.85 KB
/
mocks.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package armhelpers
import (
"fmt"
"time"
"github.com/Azure/azure-sdk-for-go/arm/compute"
"github.com/Azure/azure-sdk-for-go/arm/resources/resources"
"github.com/Azure/go-autorest/autorest"
)
//FailingMockClient is an implemetnation of ACSEngineClient where all requests error out
type FailingMockClient struct{}
//DeployTemplate mock
func (fmc *FailingMockClient) DeployTemplate(resourceGroup, name string, template, parameters map[string]interface{}, cancel <-chan struct{}) (*resources.DeploymentExtended, error) {
return nil, fmt.Errorf("failed")
}
//EnsureResourceGroup mock
func (fmc *FailingMockClient) EnsureResourceGroup(resourceGroup, location string) (*resources.Group, error) {
return nil, fmt.Errorf("failed")
}
//ListVirtualMachines mock
func (fmc *FailingMockClient) ListVirtualMachines(resourceGroup string) (compute.VirtualMachineListResult, error) {
return compute.VirtualMachineListResult{}, fmt.Errorf("failed")
}
//GetVirtualMachine mock
func (fmc *FailingMockClient) GetVirtualMachine(resourceGroup, name string) (compute.VirtualMachine, error) {
return compute.VirtualMachine{}, fmt.Errorf("failed")
}
//DeleteVirtualMachine mock
func (fmc *FailingMockClient) DeleteVirtualMachine(resourceGroup, name string, cancel <-chan struct{}) (<-chan compute.OperationStatusResponse, <-chan error) {
errChan := make(chan error)
respChan := make(chan compute.OperationStatusResponse)
go func() {
defer func() {
close(errChan)
}()
defer func() {
close(respChan)
}()
errChan <- fmt.Errorf("failed")
time.Sleep(1 * time.Second)
}()
return respChan, errChan
}
//GetStorageClient mock
func (fmc *FailingMockClient) GetStorageClient(resourceGroup, accountName string) (ACSStorageClient, error) {
return nil, fmt.Errorf("failed")
}
//DeleteNetworkInterface mock
func (fmc *FailingMockClient) DeleteNetworkInterface(resourceGroup, nicName string, cancel <-chan struct{}) (<-chan autorest.Response, <-chan error) {
errChan := make(chan error)
respChan := make(chan autorest.Response)
go func() {
defer func() {
close(errChan)
}()
defer func() {
close(respChan)
}()
errChan <- fmt.Errorf("failed")
time.Sleep(1 * time.Second)
}()
return respChan, errChan
}
//MockClient is an implementation of ACSEngineClient where all requests return a valid response
type MockClient struct{}
//DeployTemplate mock
func (mc *MockClient) DeployTemplate(resourceGroup, name string, template, parameters map[string]interface{}, cancel <-chan struct{}) (*resources.DeploymentExtended, error) {
return nil, nil
}
//EnsureResourceGroup mock
func (mc *MockClient) EnsureResourceGroup(resourceGroup, location string) (*resources.Group, error) {
return nil, nil
}
//ListVirtualMachines mock
func (mc *MockClient) ListVirtualMachines(resourceGroup string) (compute.VirtualMachineListResult, error) {
return compute.VirtualMachineListResult{}, nil
}
var validOsDiskURI = "https://osdisk.storage.com/container/blob/disk.vhd"
var validNicID = "/subscriptions/subid/resourceGroups/acs-k8s-int/providers/Microsoft.Network/networkInterfaces/k8s-agent-F8EADCCF-nic-0"
//GetVirtualMachine mock
func (mc *MockClient) GetVirtualMachine(resourceGroup, name string) (compute.VirtualMachine, error) {
return compute.VirtualMachine{
VirtualMachineProperties: &compute.VirtualMachineProperties{
StorageProfile: &compute.StorageProfile{
OsDisk: &compute.OSDisk{
Vhd: &compute.VirtualHardDisk{
URI: &validOsDiskURI},
},
},
NetworkProfile: &compute.NetworkProfile{
NetworkInterfaces: &[]compute.NetworkInterfaceReference{
{
ID: &validNicID,
},
},
},
},
}, nil
}
//DeleteVirtualMachine mock
func (mc *MockClient) DeleteVirtualMachine(resourceGroup, name string, cancel <-chan struct{}) (<-chan compute.OperationStatusResponse, <-chan error) {
errChan := make(chan error)
respChan := make(chan compute.OperationStatusResponse)
go func() {
defer func() {
close(errChan)
}()
defer func() {
close(respChan)
}()
errChan <- nil
respChan <- compute.OperationStatusResponse{}
time.Sleep(1 * time.Second)
}()
return respChan, errChan
}
//GetStorageClient mock
func (mc *MockClient) GetStorageClient(resourceGroup, accountName string) (ACSStorageClient, error) {
return &MockStorageClient{}, nil
}
//DeleteNetworkInterface mock
func (mc *MockClient) DeleteNetworkInterface(resourceGroup, nicName string, cancel <-chan struct{}) (<-chan autorest.Response, <-chan error) {
errChan := make(chan error)
respChan := make(chan autorest.Response)
go func() {
defer func() {
close(errChan)
}()
defer func() {
close(respChan)
}()
errChan <- nil
respChan <- autorest.Response{}
time.Sleep(1 * time.Second)
}()
return respChan, errChan
}
//MockStorageClient mock implementation of StorageClient
type MockStorageClient struct{}
//DeleteBlob mock
func (msc *MockStorageClient) DeleteBlob(container, blob string) error {
return nil
}