-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
67 lines (57 loc) · 1.76 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
#!/usr/bin/env bats
CONTAINER_NAME=bitnami-memcached-test
IMAGE_NAME=bitnami/memcached
RUBY_CONTAINER_NAME=bitnami-ruby-test
RUBY_IMAGE_NAME=bitnami/ruby
SLEEP_TIME=3
VOL_PREFIX=/bitnami/memcached
MEMCACHED_PASSWORD=test_password123
cleanup_running_containers() {
if [ "$(docker ps -a | grep $CONTAINER_NAME)" ]; then
docker rm -fv $CONTAINER_NAME
fi
if [ "$(docker ps -a | grep $RUBY_CONTAINER_NAME)" ]; then
docker rm -fv $RUBY_CONTAINER_NAME
fi
}
setup() {
cleanup_running_containers
}
teardown() {
cleanup_running_containers
}
create_container() {
if [ $1 ]; then
docker run -d --name $CONTAINER_NAME\
-e MEMCACHED_PASSWORD=$MEMCACHED_PASSWORD $IMAGE_NAME
sleep 15
else
docker run -d --name $CONTAINER_NAME $IMAGE_NAME
sleep $SLEEP_TIME
fi
}
create_ruby_container() {
docker run --name $RUBY_CONTAINER_NAME -id\
--link $CONTAINER_NAME:memcached $RUBY_IMAGE_NAME
docker exec $RUBY_CONTAINER_NAME sudo gem install dalli
}
@test "Auth if no password provided" {
create_container
create_ruby_container
run docker exec $RUBY_CONTAINER_NAME ruby -e "require 'dalli'; Dalli::Client.new('memcached:11211').set('test', 'bitnami')"
[[ "$status" = 0 ]]
}
@test "Auth if password provided" {
create_container with_password
create_ruby_container
run docker exec $RUBY_CONTAINER_NAME ruby -e "require 'dalli'; Dalli::Client.new('memcached:11211').set('test', 'bitnami')"
[[ "$status" = 1 ]]
run docker exec $RUBY_CONTAINER_NAME\
ruby -e "require 'dalli'; Dalli::Client.new('memcached:11211', {username: 'user', password: '$MEMCACHED_PASSWORD'}).set('test', 'bitnami')"
[[ "$status" = 0 ]]
}
@test "All the volumes exposed" {
create_container
run docker inspect $CONTAINER_NAME
[[ "$output" =~ "$VOL_PREFIX/logs" ]]
}