-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions_test.sh
executable file
·150 lines (114 loc) · 2.85 KB
/
functions_test.sh
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
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
# load testing payload from the testing file
PAYLOAD=$(<payload.json)
source ./functions.sh
#
# Test that URL is correctly extracted
# from payload
#
testUrlExtracted() {
# When:
url=`extractUrl "$PAYLOAD"`
# Then:
assertEquals "http://ci.myhost:8083" "$url"
}
#
# Test that the Project id is correctly extracted from payload
#
testProjectIdExtracted() {
# When:
projectId=`extractProjectId "$PAYLOAD"`
# Then:
assertEquals 303 $projectId
}
#
# Test that the Format is correctly extracted
#
testFormatExtracted() {
# When:
extractedFormat=`extractFormat "$PAYLOAD"`
# Then
assertEquals "json" $extractedFormat
}
#
# Test we extract the array of countries and file names.
# We transform all the entries to the strings "county|filename", later it could be used
# in a loop
#
testArrayCountries() {
# When:
countries=`extractCountries "$PAYLOAD"`
arrCountries=($countries)
# Then:
assertEquals "gb|en-gb.all.json" ${arrCountries[0]}
assertEquals "ru|ru-ru.all.json" ${arrCountries[1]}
assertEquals "cy|cy-cy.all.json" ${arrCountries[2]}
}
testDelimeter() {
# When:
delimeter=`extractDelimeter "$PAYLOAD"`
# Then:
assertEquals null $delimeter
}
#
# Test that URL is correctly build
#
testBuildUrlSimple() {
# Given:
LINE="gb|en-gb.all.json"
FORMAT="json"
PROJECT_ID=3
BASE_URL="http://localhost:8080"
# When
url=`buildUrlToFile "$LINE" "$FORMAT" "$PROJECT_ID" "$BASE_URL"`
# Then
assertEquals "http://localhost:8080/api/project/3/file/gb/json" "$url"
}
#
# Empty delimeter ignored
#
testBuildUrlSimpleEmptyDelimenter() {
# Given:
LINE="gb|en-gb.all.json"
FORMAT="json"
PROJECT_ID=3
BASE_URL="http://localhost:8080"
# and:
DELIMETER="" # <-- will be ignored
# When
url=`buildUrlToFile "$LINE" "$FORMAT" "$PROJECT_ID" "$BASE_URL" "$DELIMETER"`
# Then
assertEquals "http://localhost:8080/api/project/3/file/gb/json" "$url"
}
#
# Empty delimeter ignored
#
testBuildUrlSimpleNullDelimenter() {
# Given:
LINE="gb|en-gb.all.json"
FORMAT="json"
PROJECT_ID=3
BASE_URL="http://localhost:8080"
DELIMETER=null
# When
url=`buildUrlToFile "$LINE" "$FORMAT" "$PROJECT_ID" "$BASE_URL" "$DELIMETER"`
# Then
assertEquals "http://localhost:8080/api/project/3/file/gb/json" "$url"
}
#
# Test that URL is correctly build, including optional parameter "delimeter"
#
testBuildUrlWithDelimeter() {
# Given:
LINE="ru|messages-ru.properties"
FORMAT="properties"
PROJECT_ID=10
BASE_URL="http://localhost:8080"
DELIMETER="="
# When
url=`buildUrlToFile "$LINE" "$FORMAT" "$PROJECT_ID" "$BASE_URL" "$DELIMETER"`
# Then
assertEquals "http://localhost:8080/api/project/10/file/ru/properties?delimeter==" "$url"
}
# Load and run shUnit2.
. shunit2