-
Notifications
You must be signed in to change notification settings - Fork 111
/
run_tests.sh
executable file
·176 lines (143 loc) · 7.03 KB
/
run_tests.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/bash
# Run automated tests to ensure desk is behaving as expected
ensure() {
if [ $1 -ne 0 ]; then
echo "Failed: $2"
exit 1
fi
}
ensure_not(){
if [ $1 -eq 0 ]; then
echo "Failed: $2"
exit 1
fi
}
desk | grep "No desk activated." >/dev/null
ensure $? "Desk without desk activated fails."
desk --version | grep "◲ desk " >/dev/null
ensure $? "Desk version fails."
HELP=$(desk help)
ensure $? "Desk help fails."
echo "$HELP" | grep 'desk init' >/dev/null
ensure $? "Desk help doesn't contain init"
echo "$HELP" | grep 'desk (list|ls)' >/dev/null
ensure $? "Desk help doesn't contain list"
echo "$HELP" | grep 'desk (.|go)' >/dev/null
ensure $? "Desk help doesn't contain go"
echo "$HELP" | grep 'desk run' >/dev/null
ensure $? "Desk help doesn't contain run"
echo "$HELP" | grep 'desk help' >/dev/null
ensure $? "Desk help doesn't contain help"
echo "$HELP" | grep 'desk version' >/dev/null
ensure $? "Desk help doesn't contain version"
desk init <<ANSWER
ANSWER
LIST=$(DESK_DESKS_DIR=${HOME}/examples desk list)
echo "$LIST" | grep "desk the desk I use to work on desk :)" >/dev/null
ensure $? "Desk list missing desk (with DESK_DESKS_DIR)"
echo "$LIST" | grep "python_project desk for working on a Python project" >/dev/null
ensure $? "Desk list missing python_project (with DESK_DESKS_DIR)"
echo "$LIST" | grep "terraform desk for doing work on a terraform-based repository" >/dev/null
ensure $? "Desk list missing terraform (with DESK_DESKS_DIR)"
echo "$LIST" | grep "hello simple desk that says hello" >/dev/null
ensure $? "Desk list missing hello (with DESK_DESKS_DIR)"
rm -rf "$HOME/.desk/desks"
ln -s "$HOME/examples" "$HOME/.desk/desks"
## `desk list`
# --no-format
LIST=$(desk list --no-format)
echo "$LIST" | grep "desk - the desk I use to work on desk :)" >/dev/null
ensure $? "Desk list missing desk with --no-format option (with symlink)"
echo "$LIST" | grep "python_project - desk for working on a Python project" >/dev/null
ensure $? "Desk list missing python_project with --no-format option (with symlink)"
echo "$LIST" | grep "terraform - desk for doing work on a terraform-based repository" >/dev/null
ensure $? "Desk list missing terraform with --no-format option (with symlink)"
echo "$LIST" | grep "hello - simple desk that says hello" >/dev/null
ensure $? "Desk list missing hello (with symlink)"
# --only-names
LIST=$(desk list --only-names)
echo "$LIST" | grep "the desk I use to work on desk :)" >/dev/null
ensure_not $? "Desk list --only-names contains 'desk' description (with symlink)"
echo "$LIST" | grep -e '^desk$' >/dev/null
ensure $? "Desk list --only-names missing 'desk' (with symlink)"
# without options
LIST=$(desk list)
echo "$LIST" | grep "desk the desk I use to work on desk :)" >/dev/null
ensure $? "Desk list did not align 'desk' (with symlink)"
echo "$LIST" | grep "python_project desk for working on a Python project" >/dev/null
ensure $? "Desk list did not align 'python_project' (with symlink)"
echo "$LIST" | grep "terraform desk for doing work on a terraform-based repository" >/dev/null
ensure $? "Desk list did not align 'terraform' (with symlink)"
# DESK_DESKS_DIR=...
rm -rf "$HOME/.desk/desks"
LIST=$(DESK_DESKS_DIR=$HOME/examples desk list)
echo "$LIST" | grep "desk the desk I use to work on desk :)" >/dev/null
ensure $? "Desk list missing desk (with DESK_DESKS_DIR)"
echo "$LIST" | grep "python_project desk for working on a Python project" >/dev/null
ensure $? "Desk list missing python_project (with DESK_DESKS_DIR)"
echo "$LIST" | grep "terraform desk for doing work on a terraform-based repository" >/dev/null
ensure $? "Desk list missing terraform (with DESK_DESKS_DIR)"
ln -s "$HOME/examples" "$HOME/.desk/desks"
mkdir ~/terraform-repo
## `desk`
# without options
CURRENT=$(DESK_ENV=$HOME/.desk/desks/terraform.sh desk)
echo "$CURRENT" | grep 'set_aws_env Set up AWS env variables: <key id> <secret>' >/dev/null
ensure $? "Desk current terraform missing set_aws_env"
echo "$CURRENT" | grep 'plan Run `terraform plan` with proper AWS var config' >/dev/null
ensure $? "Desk current terraform missing plan"
echo "$CURRENT" | grep 'apply Run `terraform apply` with proper AWS var config' >/dev/null
ensure $? "Desk current terraform missing apply"
echo "$CURRENT" | grep 'config Set up terraform config: <config_key>' >/dev/null
ensure $? "Desk current terraform missing config"
# --no-format
CURRENT=$(DESK_ENV=$HOME/.desk/desks/terraform.sh desk --no-format)
echo "$CURRENT" | grep 'set_aws_env - Set up AWS env variables: <key id> <secret>' >/dev/null
ensure $? "Desk current terraform missing set_aws_env"
echo "$CURRENT" | grep 'plan - Run `terraform plan` with proper AWS var config' >/dev/null
ensure $? "Desk current terraform missing plan"
echo "$CURRENT" | grep 'apply - Run `terraform apply` with proper AWS var config' >/dev/null
ensure $? "Desk current terraform missing apply"
echo "$CURRENT" | grep 'config - Set up terraform config: <config_key>' >/dev/null
ensure $? "Desk current terraform missing config"
# testing for exported variables
CURRENT=$(DESK_ENV=$HOME/.desk/desks/hello.sh desk)
echo "$CURRENT" | grep 'MyName Why should I always type my name' >/dev/null
ensure $? "Desk current hello missing exported environment variable"
RAN=$(desk run hello 'howdy james!')
echo "$RAN" | grep 'howdy y'"'"'all james!' >/dev/null
ensure $? "Run in desk 'hello' didn't work with howdy alias"
RAN=$(desk run hello 'hi j')
echo "$RAN" | grep 'hi, j!' >/dev/null
ensure $? "Run in desk 'hello' didn't work with hi function"
RAN=$(desk run hello 'echo $MyName')
echo "$RAN" | grep 'James' >/dev/null
ensure $? "Run in desk 'hello' didn't work with MyName exported variable"
RAN=$(desk run hello echo ahoy matey)
echo "$RAN" | grep 'ahoy matey' >/dev/null
ensure $? "Run in desk 'hello' didn't work with argument vector"
## `desk go`
RAN=$(desk go example-project/Deskfile -c 'desk ; exit')
echo "$RAN" | grep "example-project - simple desk that says hello" >/dev/null
ensure $? "Deskfile invocation didn't work (example-project/)"
echo "$RAN" | grep -E "hi\s+" >/dev/null
ensure $? "Deskfile invocation didn't work (example-project/)"
echo "$RAN" | grep -E "howdy\s+" >/dev/null
ensure $? "Deskfile invocation didn't work (example-project/)"
RAN=$(desk go example-project/ -c 'desk ; exit')
echo "$RAN" | grep "example-project - simple desk that says hello" >/dev/null
ensure $? "Deskfile invocation didn't work (example-project/)"
echo "$RAN" | grep -E "hi\s+" >/dev/null
ensure $? "Deskfile invocation didn't work (example-project/)"
echo "$RAN" | grep -E "howdy\s+" >/dev/null
ensure $? "Deskfile invocation didn't work (example-project/)"
pushd example-project
RAN=$(desk go . -c 'desk ; exit')
echo "$RAN" | grep "example-project - simple desk that says hello" >/dev/null
ensure $? "Deskfile invocation didn't work (./)"
echo "$RAN" | grep -E "hi\s+" >/dev/null
ensure $? "Deskfile invocation didn't work (example-project/)"
echo "$RAN" | grep -E "howdy\s+" >/dev/null
ensure $? "Deskfile invocation didn't work (example-project/)"
popd
echo "tests pass."