-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
event_test.go
80 lines (69 loc) · 2.29 KB
/
event_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
package main
import (
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudwatchevents"
)
func TestMatchScoreForCWEventRuleAndDescribedRule(t *testing.T) {
cweventRule := cloudwatchevents.Rule{
Arn: aws.String("arn:aws:events:ap-northeast-1:000000000000:rule/test-cwevent"),
Description: aws.String("Test rule"),
EventPattern: nil,
Name: aws.String("test-cwevent"),
RoleArn: nil,
ScheduleExpression: aws.String("cron(0 20 * * ? *)"),
State: aws.String("ENABLED"),
}
describedRule := Rule{
Description: "Test rule",
EventPattern: "",
Name: "test-cwevent",
ScheduleExpression: "cron(0 20 * * ? *)",
State: "ENABLED",
Targets: nil,
}
result1 := MatchScoreForCWEventRuleAndDescribedRule(cweventRule, describedRule)
if result1 != 1.0 {
t.Error("match score should be eq 1.0 but got", result1)
}
describedRule.Description = "another test rule"
result2 := MatchScoreForCWEventRuleAndDescribedRule(cweventRule, describedRule)
if result2 != (5.0 / 6.0) {
t.Error("match score should be eq 0.833.. but got", result2)
}
}
func TestIsNewDefinedRule(t *testing.T) {
cweventRule := cloudwatchevents.Rule{
Arn: aws.String("arn:aws:events:ap-northeast-1:000000000000:rule/test-cwevent"),
Description: aws.String("Test rule"),
EventPattern: nil,
Name: aws.String("test-cwevent"),
RoleArn: nil,
ScheduleExpression: aws.String("cron(0 20 * * ? *)"),
State: aws.String("ENABLED"),
}
rule1 := Rule{
Description: "Test rule",
EventPattern: "",
Name: "test-cwevent",
ScheduleExpression: "cron(0 20 * * ? *)",
State: "ENABLED",
Targets: nil,
}
result1 := IsNewDefinedRule(cweventRule, rule1)
if result1 != false {
t.Error("return value should be false")
}
rule2 := Rule{
Description: "New defined test rule",
EventPattern: "",
Name: "another-test-cwevent",
ScheduleExpression: "cron(0 20 * * ? *)",
State: "ENABLED",
Targets: nil,
}
result2 := IsNewDefinedRule(cweventRule, rule2)
if result2 != true {
t.Error("return value should be true")
}
}