forked from concourse/registry-image-resource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types_test.go
99 lines (80 loc) · 2.82 KB
/
types_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package resource_test
import (
"encoding/json"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/aws/aws-sdk-go/service/ecr"
"github.com/aws/aws-sdk-go/service/ecr/ecriface"
resource "github.com/concourse/registry-image-resource"
)
var _ = Describe("Source", func() {
It("should unmarshal tag float value into a string", func() {
var source resource.Source
raw := []byte(`{ "tag": 42.1 }`)
err := json.Unmarshal(raw, &source)
Expect(err).ToNot(HaveOccurred())
Expect(source.Tag.String()).To(Equal("42.1"))
})
It("should unmarshal tag int value into a string", func() {
var source resource.Source
raw := []byte(`{ "tag": 42 }`)
err := json.Unmarshal(raw, &source)
Expect(err).ToNot(HaveOccurred())
Expect(source.Tag.String()).To(Equal("42"))
})
It("should unmarshal tag string value into a string", func() {
var source resource.Source
raw := []byte(`{ "tag": "foo" }`)
err := json.Unmarshal(raw, &source)
Expect(err).ToNot(HaveOccurred())
Expect(source.Tag.String()).To(Equal("foo"))
})
It("should marshal a tag back out to a string", func() {
source := resource.Source{Repository: "foo", Tag: "0"}
json, err := json.Marshal(source)
Expect(err).ToNot(HaveOccurred())
Expect(json).To(MatchJSON(`{"repository":"foo","tag":"0"}`))
})
Describe("ecr", func() {
It("should exclude a registry id as part of the request for an authorization token when omitted", func() {
source := resource.Source{
Repository: "foo",
AwsCredentials: resource.AwsCredentials{
AwsAccessKeyId: "foo",
AwsSecretAccessKey: "bar",
AwsRegion: "us-east-1",
},
}
m := &mockECR{}
_, err := source.GetECRAuthorizationToken(m)
Expect(err).ToNot(HaveOccurred())
Expect(len(m.getAuthorizationInput.RegistryIds)).To(Equal(0))
})
It("should include a registry id as part of the request for an authorization token when specified", func() {
source := resource.Source{
Repository: "foo",
AwsCredentials: resource.AwsCredentials{
AwsAccessKeyId: "foo",
AwsSecretAccessKey: "bar",
AwsRegion: "us-east-1",
AWSECRRegistryId: "012345678901",
},
}
m := &mockECR{}
_, err := source.GetECRAuthorizationToken(m)
Expect(err).ToNot(HaveOccurred())
Expect(len(m.getAuthorizationInput.RegistryIds)).To(Equal(1))
Expect(*m.getAuthorizationInput.RegistryIds[0]).To(Equal(source.AwsCredentials.AWSECRRegistryId))
})
})
})
type mockECR struct {
ecriface.ECRAPI
getAuthorizationInput *ecr.GetAuthorizationTokenInput
getAuthorizationOutput *ecr.GetAuthorizationTokenOutput
getAuthorizationError error
}
func (m *mockECR) GetAuthorizationToken(input *ecr.GetAuthorizationTokenInput) (*ecr.GetAuthorizationTokenOutput, error) {
m.getAuthorizationInput = input
return m.getAuthorizationOutput, m.getAuthorizationError
}