-
Notifications
You must be signed in to change notification settings - Fork 172
/
test.sh
100 lines (84 loc) · 2.5 KB
/
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
#!/usr/bin/env bats
CONTAINER_NAME=bitnami-redis-test
IMAGE_NAME=bitnami/redis
SLEEP_TIME=3
VOL_PREFIX=/bitnami/redis
REDIS_PASSWORD=test_password123
HOST_VOL_PREFIX=/tmp/$VOL_PREFIX
cleanup_running_containers() {
if [ "$(docker ps -a | grep $CONTAINER_NAME)" ]; then
docker rm -fv $CONTAINER_NAME
fi
}
cleanup_volumes_content() {
docker run --rm\
-v $HOST_VOL_PREFIX/data:$VOL_PREFIX/data\
$IMAGE_NAME rm -rf $VOL_PREFIX/data/
}
setup() {
cleanup_running_containers
}
teardown() {
cleanup_running_containers
}
create_container(){
docker run -d --name $CONTAINER_NAME "$@" $IMAGE_NAME
sleep $SLEEP_TIME
}
redis_client(){
docker exec $CONTAINER_NAME redis-cli "$@"
}
@test "Auth if no password provided" {
create_container
run redis_client ping
[[ "$output" =~ "PONG" ]]
}
@test "Auth if password provided" {
create_container -e REDIS_PASSWORD=$REDIS_PASSWORD
# Longs sleep because of bnconfig password update
sleep 15
# Can't connect without passw
run redis_client ping
[[ "$output" =~ "NOAUTH Authentication required" ]]
run redis_client -a $REDIS_PASSWORD ping
[[ "$output" =~ "PONG" ]]
}
@test "Password settings are preserved after restart" {
create_container -e REDIS_PASSWORD=$REDIS_PASSWORD
sleep 15
run docker logs $CONTAINER_NAME
[[ "$output" =~ "Credentials for redis:" ]]
[[ "$output" =~ "Password: $REDIS_PASSWORD" ]]
docker stop $CONTAINER_NAME
docker start $CONTAINER_NAME
sleep $SLEEP_TIME
run docker logs $CONTAINER_NAME
[[ "$output" =~ "The credentials were set on first boot." ]]
run redis_client -a $REDIS_PASSWORD ping
[[ "$output" =~ "PONG" ]]
}
@test "All the volumes exposed" {
create_container
run docker inspect $CONTAINER_NAME
[[ "$output" =~ "$VOL_PREFIX/logs" ]]
[[ "$output" =~ "$VOL_PREFIX/conf" ]]
[[ "$output" =~ "$VOL_PREFIX/data" ]]
}
@test "dump.rdb is properly created" {
create_container -v $HOST_VOL_PREFIX/data:$VOL_PREFIX/data
docker stop $CONTAINER_NAME
run docker run -v $HOST_VOL_PREFIX/data:$HOST_VOL_PREFIX/data --rm $IMAGE_NAME ls -l $HOST_VOL_PREFIX/data/dump.rdb
[ $status = 0 ]
cleanup_volumes_content
}
@test "Redis db persists if deleted and host mounted" {
create_container -v $HOST_VOL_PREFIX/data:$VOL_PREFIX/data
run redis_client set winter 'is coming'
[[ "$output" =~ "OK" ]]
docker stop $CONTAINER_NAME
docker rm -fv $CONTAINER_NAME
create_container -v $HOST_VOL_PREFIX/data:$VOL_PREFIX/data
run redis_client get winter
[[ "$output" =~ "is coming" ]]
cleanup_volumes_content
}