-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.bats
More file actions
executable file
·94 lines (65 loc) · 1.93 KB
/
test.bats
File metadata and controls
executable file
·94 lines (65 loc) · 1.93 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
#!/usr/bin/env bats
source power-assert.bash
PATH=../..:$PATH
##################################################
# Setup & Teardown
##################################################
setup() {
rm -rf tmp
mkdir tmp
}
##################################################
# Shared
##################################################
base_apply() {
cp conf.tf tmp
cd tmp
terraform init
terraform apply -auto-approve
}
get_infermv_line_count() {
similarity_threshold=${1:-1.0}
terraform plan -out=./plan-result > /dev/null 2>&1
terraform show -json plan-result > plan-result.json 2> /dev/null
infermv plan-result.json $similarity_threshold | wc -l
}
##################################################
# Test
##################################################
@test "terraform works correctly" {
base_apply
}
@test "no output when no changes" {
base_apply
result_line_count=$(get_infermv_line_count)
[[[ $result_line_count -eq 0 ]]]
}
@test "1 line output when resource name changes" {
base_apply
cp ../name_change.tf conf.tf
result_line_count=$(get_infermv_line_count)
[[[ $result_line_count -eq 1 ]]]
}
@test "no output when content and name change" {
base_apply
cp ../name_content_change.tf conf.tf
result_line_count=$(get_infermv_line_count)
[[[ $result_line_count -eq 0 ]]]
}
@test "no output when content and name change and similarity threshold is 0.9" {
base_apply
cp ../name_content_change.tf conf.tf
result_line_count=$(get_infermv_line_count 0.9)
[[[ $result_line_count -eq 0 ]]]
}
@test "1 line output when content and name change and similarity threshold is 0.7" {
base_apply
cp ../name_content_change.tf conf.tf
result_line_count=$(get_infermv_line_count 0.7)
[[[ $result_line_count -eq 1 ]]]
}
@test "automatic script works correctly" {
base_apply
cp ../name_content_change.tf conf.tf
[[[ "$(generate_state_mv.sh 0.7)" == "terraform state mv local_file.foo local_file.bar" ]]]
}