-
Notifications
You must be signed in to change notification settings - Fork 547
/
codepipeline_cloudwatch_test.go
99 lines (94 loc) · 2.76 KB
/
codepipeline_cloudwatch_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 events
import (
"encoding/json"
"github.com/stretchr/testify/require"
"io/ioutil" //nolint: staticcheck
"testing"
"time"
)
func TestUnmarshalCodePipelineEvent(t *testing.T) {
tests := []struct {
input string
expect CodePipelineCloudWatchEvent
}{
{
input: "testdata/codepipeline-action-execution-stage-change-event.json",
expect: CodePipelineCloudWatchEvent{
Version: "0",
ID: "CWE-event-id",
DetailType: "CodePipeline Action Execution State Change",
Source: "aws.codepipeline",
AccountID: "123456789012",
Time: time.Date(2017, 04, 22, 3, 31, 47, 0, time.UTC),
Region: "us-east-1",
Resources: []string{
"arn:aws:codepipeline:us-east-1:123456789012:pipeline:myPipeline",
},
Detail: CodePipelineEventDetail{
Pipeline: "myPipeline",
Version: 1,
ExecutionID: "01234567-0123-0123-0123-012345678901",
Stage: "Prod",
Action: "myAction",
State: "STARTED",
Region: "us-west-2",
Type: CodePipelineEventDetailType{
Owner: "AWS",
Category: "Deploy",
Provider: "CodeDeploy",
Version: 1,
},
},
},
},
{
input: "testdata/codepipeline-execution-stage-change-event.json",
expect: CodePipelineCloudWatchEvent{
Version: "0",
ID: "CWE-event-id",
DetailType: "CodePipeline Stage Execution State Change",
Source: "aws.codepipeline",
AccountID: "123456789012",
Time: time.Date(2017, 04, 22, 3, 31, 47, 0, time.UTC),
Region: "us-east-1",
Resources: []string{
"arn:aws:codepipeline:us-east-1:123456789012:pipeline:myPipeline",
},
Detail: CodePipelineEventDetail{
Pipeline: "myPipeline",
Version: 1,
ExecutionID: "01234567-0123-0123-0123-012345678901",
State: "STARTED",
},
},
},
{
input: "testdata/codepipeline-execution-state-change-event.json",
expect: CodePipelineCloudWatchEvent{
Version: "0",
ID: "CWE-event-id",
DetailType: "CodePipeline Pipeline Execution State Change",
Source: "aws.codepipeline",
AccountID: "123456789012",
Time: time.Date(2017, 04, 22, 3, 31, 47, 0, time.UTC),
Region: "us-east-1",
Resources: []string{
"arn:aws:codepipeline:us-east-1:123456789012:pipeline:myPipeline",
},
Detail: CodePipelineEventDetail{
Pipeline: "myPipeline",
Version: 1,
ExecutionID: "01234567-0123-0123-0123-012345678901",
State: "STARTED",
},
},
},
}
for _, testcase := range tests {
data, err := ioutil.ReadFile(testcase.input)
require.NoError(t, err)
var actual CodePipelineCloudWatchEvent
require.NoError(t, json.Unmarshal(data, &actual))
require.Equal(t, testcase.expect, actual)
}
}