forked from adamlaska/machine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstub_test.go
More file actions
139 lines (112 loc) · 3.74 KB
/
stub_test.go
File metadata and controls
139 lines (112 loc) · 3.74 KB
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
package amazonec2
import (
"errors"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/stretchr/testify/mock"
)
type fakeEC2 struct {
*ec2.EC2
}
type errorProvider struct{}
func (p *errorProvider) Retrieve() (credentials.Value, error) {
return credentials.Value{}, errors.New("bad credentials")
}
func (p *errorProvider) IsExpired() bool {
return true
}
type okProvider struct {
accessKeyID string
secretAccessKey string
sessionToken string
}
func (p *okProvider) Retrieve() (credentials.Value, error) {
return credentials.Value{
AccessKeyID: p.accessKeyID,
SecretAccessKey: p.secretAccessKey,
SessionToken: p.sessionToken,
}, nil
}
func (p *okProvider) IsExpired() bool {
return true
}
type cliCredentials struct{}
func (c *cliCredentials) NewStaticCredentials(id, secret, token string) *credentials.Credentials {
return credentials.NewCredentials(&okProvider{id, secret, token})
}
func (c *cliCredentials) NewSharedCredentials(filename, profile string) *credentials.Credentials {
return credentials.NewCredentials(&errorProvider{})
}
type fileCredentials struct{}
func (c *fileCredentials) NewStaticCredentials(id, secret, token string) *credentials.Credentials {
return nil
}
func (c *fileCredentials) NewSharedCredentials(filename, profile string) *credentials.Credentials {
return credentials.NewCredentials(&okProvider{"access", "secret", "token"})
}
type fakeEC2WithDescribe struct {
*fakeEC2
output *ec2.DescribeAccountAttributesOutput
err error
}
func (f *fakeEC2WithDescribe) DescribeAccountAttributes(input *ec2.DescribeAccountAttributesInput) (*ec2.DescribeAccountAttributesOutput, error) {
return f.output, f.err
}
type fakeEC2WithLogin struct {
*fakeEC2
}
func (f *fakeEC2WithLogin) DescribeAccountAttributes(input *ec2.DescribeAccountAttributesInput) (*ec2.DescribeAccountAttributesOutput, error) {
defaultVpc := "default-vpc"
vpcName := "vpc-9999"
return &ec2.DescribeAccountAttributesOutput{
AccountAttributes: []*ec2.AccountAttribute{
{
AttributeName: &defaultVpc,
AttributeValues: []*ec2.AccountAttributeValue{
{AttributeValue: &vpcName},
},
},
},
}, nil
}
type fakeEC2SecurityGroupTestRecorder struct {
*fakeEC2
mock.Mock
}
func (f *fakeEC2SecurityGroupTestRecorder) DescribeSecurityGroups(input *ec2.DescribeSecurityGroupsInput) (*ec2.DescribeSecurityGroupsOutput, error) {
result := f.Called(input)
err := result.Error(1)
value, ok := result.Get(0).(*ec2.DescribeSecurityGroupsOutput)
if !ok && err == nil {
return nil, errors.New("Type assertion to DescribeSecurityGroupsOutput failed")
}
return value, err
}
func (f *fakeEC2SecurityGroupTestRecorder) CreateSecurityGroup(input *ec2.CreateSecurityGroupInput) (*ec2.CreateSecurityGroupOutput, error) {
result := f.Called(input)
err := result.Error(1)
value, ok := result.Get(0).(*ec2.CreateSecurityGroupOutput)
if !ok && err == nil {
return nil, errors.New("Type assertion to CreateSecurityGroupOutput failed")
}
return value, err
}
func (f *fakeEC2SecurityGroupTestRecorder) AuthorizeSecurityGroupIngress(input *ec2.AuthorizeSecurityGroupIngressInput) (*ec2.AuthorizeSecurityGroupIngressOutput, error) {
result := f.Called(input)
err := result.Error(1)
value, ok := result.Get(0).(*ec2.AuthorizeSecurityGroupIngressOutput)
if !ok && err == nil {
return nil, errors.New("Type assertion to AuthorizeSecurityGroupIngressInput failed")
}
return value, err
}
func NewTestDriver() *Driver {
driver := NewDriver("machineFoo", "path")
driver.clientFactory = func() Ec2Client { return &fakeEC2{} }
return driver
}
func NewCustomTestDriver(ec2Client Ec2Client) *Driver {
driver := NewDriver("machineFoo", "path")
driver.clientFactory = func() Ec2Client { return ec2Client }
return driver
}