summaryrefslogtreecommitdiff
path: root/.config/fisher/github.com/matchai/spacefish/tests/__sf_section_docker.test.fish
blob: 4321afc7f45521918979800c0307ab1969fb7ee4 (plain)
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
source $DIRNAME/spacefish_test_setup.fish
set -l LOCAL_DOCKER_VERSION 18.06.1

function setup
	spacefish_test_setup
	mock docker version 0 "echo \"18.06.1\""
	mkdir -p /tmp/tmp-spacefish
	cd /tmp/tmp-spacefish
end

function teardown
	rm -rf /tmp/tmp-spacefish
	if test "$COMPOSE_FILE"
		set -e COMPOSE_FILE
	end
	if test "$DOCKER_MACHINE_NAME"
		set -e DOCKER_MACHINE_NAME
	end
end

test "Prints section when only Dockerfile is present"
	(
		touch Dockerfile

		set_color --bold
		echo -n "is "
		set_color normal
		set_color --bold cyan
		echo -n "🐳 v$LOCAL_DOCKER_VERSION"
		set_color normal
		set_color --bold
		echo -n " "
		set_color normal
	) = (__sf_section_docker)
end

test "Prints section when only docker-compose.yml is present"
	(
		touch docker-compose.yml

		set_color --bold
		echo -n "is "
		set_color normal
		set_color --bold cyan
		echo -n "🐳 v$LOCAL_DOCKER_VERSION"
		set_color normal
		set_color --bold
		echo -n " "
		set_color normal
	) = (__sf_section_docker)
end

test "Prints section when both Dockerfile and docker-compose.yml are present"
	(
		touch Dockerfile
		touch docker-compose.yml

		set_color --bold
		echo -n "is "
		set_color normal
		set_color --bold cyan
		echo -n "🐳 v$LOCAL_DOCKER_VERSION"
		set_color normal
		set_color --bold
		echo -n " "
		set_color normal
	) = (__sf_section_docker)
end

test "Prints Docker section when COMPOSE_FILE is set and the $COMPOSE_FILE exists"
	(
		set -g COMPOSE_FILE /tmp/some-compose-file.yml
		touch /tmp/some-compose-file.yml

		set_color --bold
		echo -n "is "
		set_color normal
		set_color --bold cyan
		echo -n "🐳 v$LOCAL_DOCKER_VERSION"
		set_color normal
		set_color --bold
		echo -n " "
		set_color normal
	) = (__sf_section_docker)
end

test "Prints section when only Dockerfile is present with DOCKER_MACHINE_NAME set"
	(
		rm /tmp/some-compose-file.yml
		touch Dockerfile
		set -g DOCKER_MACHINE_NAME some-machine-name

		set_color --bold
		echo -n "is "
		set_color normal
		set_color --bold cyan
		echo -n "🐳 v$LOCAL_DOCKER_VERSION via $DOCKER_MACHINE_NAME"
		set_color normal
		set_color --bold
		echo -n " "
		set_color normal
	) = (__sf_section_docker)
end

test "Prints section when only docker-compose.yml is present with DOCKER_MACHINE_NAME set"
	(
		touch docker-compose.yml
		set -g DOCKER_MACHINE_NAME some-machine-name

		set_color --bold
		echo -n "is "
		set_color normal
		set_color --bold cyan
		echo -n "🐳 v$LOCAL_DOCKER_VERSION via $DOCKER_MACHINE_NAME"
		set_color normal
		set_color --bold
		echo -n " "
		set_color normal
	) = (__sf_section_docker)
end

test "Prints section when both Dockerfile and docker-compose.yml are present with DOCKER_MACHINE_NAME set"
	(
		touch Dockerfile
		touch docker-compose.yml
		set -g DOCKER_MACHINE_NAME some-machine-name

		set_color --bold
		echo -n "is "
		set_color normal
		set_color --bold cyan
		echo -n "🐳 v$LOCAL_DOCKER_VERSION via $DOCKER_MACHINE_NAME"
		set_color normal
		set_color --bold
		echo -n " "
		set_color normal
	) = (__sf_section_docker)
end

test "Prints Docker section when COMPOSE_FILE is set with DOCKER_MACHINE_NAME set"
		(
		set -g COMPOSE_FILE /tmp/some-compose-file.yml
		touch /tmp/some-compose-file.yml
		set -g DOCKER_MACHINE_NAME some-machine-name

		set_color --bold
		echo -n "is "
		set_color normal
		set_color --bold cyan
		echo -n "🐳 v$LOCAL_DOCKER_VERSION via $DOCKER_MACHINE_NAME"
		set_color normal
		set_color --bold
		echo -n " "
		set_color normal
	) = (__sf_section_docker)
end

test "Changing SPACEFISH_DOCKER_SYMBOL changes the displayed character"
	(
		rm /tmp/some-compose-file.yml
		set SPACEFISH_DOCKER_SYMBOL "· "
		touch Dockerfile

		set_color --bold
		echo -n "is "
		set_color normal
		set_color --bold cyan
		echo -n "· v$LOCAL_DOCKER_VERSION"
		set_color normal
		set_color --bold
		echo -n " "
		set_color normal
	) = (__sf_section_docker)
end

test "Changing SPACEFISH_DOCKER_PREFIX changes the character prefix"
	(
		set sf_exit_code 0
		set SPACEFISH_DOCKER_PREFIX ·
		touch Dockerfile

		set_color --bold
		echo -n "·"
		set_color normal
		set_color --bold cyan
		echo -n "🐳 v$LOCAL_DOCKER_VERSION"
		set_color normal
		set_color --bold
		echo -n " "
		set_color normal
	) = (__sf_section_docker)
end


# Negative
test "Doesn't display section when SPACEFISH_DOCKER_SHOW is set to 'false'"
	(
		set SPACEFISH_DOCKER_SHOW false
		touch Dockerfile

	) = (__sf_section_docker)
end

test "Doesn't print section if docker is not installed"
	(
		touch Dockerfile
		mock docker version 127
	) = (__sf_section_docker)
end

# This case can be checked only by bringing down the docker deamon
test "Doesn't print section if docker deamon is not running"
		() = (__sf_section_docker)
end

test "Doesn't print section when not in a directory with Dockerfile or docker-compose.yml"
	() = (__sf_section_docker)
end