File: create-container.bats

package info (click to toggle)
golang-github-containers-storage 1.59.1%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,184 kB
  • sloc: sh: 630; ansic: 389; makefile: 143; awk: 12
file content (109 lines) | stat: -rw-r--r-- 3,351 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env bats

load helpers

@test "create-container" {
	# Create a container based on no image.
	run storage --debug=false create-container ""
	[ "$status" -eq 0 ]
	[ "$output" != "" ]
	zerothcontainer=${output%%	*}

	# Create an image using no layer.
	run storage --debug=false create-image ""
	[ "$status" -eq 0 ]
	[ "$output" != "" ]
	image=${output%%	*}

	# Create a container based on that image.
	run storage --debug=false create-container $image
	echo "$output"
	[ "$status" -eq 0 ]
	[ "$output" != "" ]
	thirdcontainer=${output%%	*}

	# Create a layer.
	run storage --debug=false create-layer
	[ "$status" -eq 0 ]
	[ "$output" != "" ]
	layer=$output

	# Create an image using that layer.
	run storage --debug=false create-image $layer
	[ "$status" -eq 0 ]
	[ "$output" != "" ]
	image=${output%%	*}

	# Create a container based on that image.
	run storage --debug=false create-container $image
	[ "$status" -eq 0 ]
	[ "$output" != "" ]
	firstcontainer=${output%%	*}

	firstwriter=$(cat ${TESTDIR}/${CONTAINERS_LOCK_ROOT}/${STORAGE_DRIVER}-containers/containers.lock)
	[ "$firstwriter" != "" ]

	# Check that the container can be found.
	storage exists -c $firstcontainer

	# Create another container based on the same image.
	run storage --debug=false create-container $image
	[ "$status" -eq 0 ]
	[ "$output" != "" ]
	secondcontainer=${output%%	*}

	secondwriter=$(cat ${TESTDIR}/${CONTAINERS_LOCK_ROOT}/${STORAGE_DRIVER}-containers/containers.lock)
	[ "$secondwriter" != "" ]
	[ "$firstwriter" != "$secondwriter" ]

	# Check that *that* container can be found.
	storage exists -c $secondcontainer

	# Check that a list of containers lists both of them.
	run storage --debug=false containers
	echo :"$output":
	[ "$status" -eq 0 ]
	[ "${#lines[*]}" -eq 4 ]
	[ "${lines[0]}" != "${lines[1]}" ]
	[ "${lines[0]}" != "${lines[2]}" ]
	[ "${lines[0]}" != "${lines[3]}" ]
	[ "${lines[1]}" != "${lines[2]}" ]
	[ "${lines[1]}" != "${lines[3]}" ]
	[ "${lines[2]}" != "${lines[3]}" ]
	[ "${lines[0]}" = "$zerothcontainer" ] || [ "${lines[0]}" = "$firstcontainer" ] || [ "${lines[0]}" = "$secondcontainer" ] || [ "${lines[0]}" = "$thirdcontainer" ]
	[ "${lines[1]}" = "$zerothcontainer" ] || [ "${lines[1]}" = "$firstcontainer" ] || [ "${lines[1]}" = "$secondcontainer" ] || [ "${lines[1]}" = "$thirdcontainer" ]
	[ "${lines[2]}" = "$zerothcontainer" ] || [ "${lines[2]}" = "$firstcontainer" ] || [ "${lines[2]}" = "$secondcontainer" ] || [ "${lines[2]}" = "$thirdcontainer" ]
	[ "${lines[3]}" = "$zerothcontainer" ] || [ "${lines[3]}" = "$firstcontainer" ] || [ "${lines[3]}" = "$secondcontainer" ] || [ "${lines[3]}" = "$thirdcontainer" ]
}

@test "create-and-mount-volatile-container" {
	# Create a container based on no image.
	run storage --debug=false create-container --volatile ""
	[ "$status" -eq 0 ]
	[ "$output" != "" ]
	container=${output%%	*}

	run storage --debug=false mount $container
	[ "$status" -eq 0 ]
	[ "$output" != "" ]
	path=${output%%	*}

	echo test > $path/newfile

	run storage --debug=false unmount $container
	[ "$status" -eq 0 ]
	[ "$output" != "" ]

	run storage --debug=false mount $container
	[ "$status" -eq 0 ]
	[ "$output" != "" ]
	path=${output%%	*}

	run cat $path/newfile
	[ "$status" -eq 0 ]
	[ "$output" == "test" ]

	run storage --debug=false unmount $container
	[ "$status" -eq 0 ]
	[ "$output" != "" ]
}