File: bigdata.bats

package info (click to toggle)
golang-github-containers-storage 1.24.8%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,324 kB
  • sloc: sh: 812; ansic: 319; makefile: 175; awk: 12
file content (176 lines) | stat: -rw-r--r-- 5,775 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env bats

load helpers

@test "image-data" {
	# Bail if "sha256sum" isn't available.
	if test -z "$(which sha256sum 2> /dev/null)" ; then
		skip "need sha256sum"
	fi

	# 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%%	*}

	# Make sure the image can be located.
	storage exists -i $image

	# Make sure the image has no big data items associated with it.
	run storage --debug=false list-image-data $image
	[ "$status" -eq 0 ]
	[ "$output" = "" ]

	# Create two random files.
	createrandom $TESTDIR/big-item-1 1234
	createrandom $TESTDIR/big-item-2 5678

	# Set each of those files as a big data item named after the file.
	storage set-image-data -f $TESTDIR/big-item-1 $image big-item-1
	storage set-image-data -f $TESTDIR/big-item-2 $image big-item-2

	# Get a list of the items.  Make sure they're both listed.
	run storagewithsorting --debug=false list-image-data $image
	[ "$status" -eq 0 ]
	[ "${#lines[*]}" -eq 2 ]
	[ "${lines[0]}" = "big-item-1" ]
	[ "${lines[1]}" = "big-item-2" ]

	# Check that the recorded sizes of the items match what we decided above.
	run storage get-image-data-size $image no-such-item
	[ "$status" -ne 0 ]
	run storage --debug=false get-image-data-size $image big-item-1
	[ "$status" -eq 0 ]
	[ "$output" -eq 1234 ]
	run storage --debug=false get-image-data-size $image big-item-2
	[ "$status" -eq 0 ]
	[ "$output" -eq 5678 ]

	# Check that we can distinguish between no-such-image and no-such-item.
	run storage --debug=false get-image-data nosuchimage big-item
	[ "$status" -ne 0 ]
	echo "$output"
	[[ "$output" =~ "image not known" ]]
	run storage --debug=false get-image-data $image no-such-big-item
	[ "$status" -ne 0 ]
	echo "$output"
	[[ "$output" =~ "does not exist" ]]

	# Save the contents of the big data items to disk and compare them with the originals.
	run storage --debug=false get-image-data $image no-such-item
	[ "$status" -ne 0 ]
	storage get-image-data -f $TESTDIR/big-item-1.2 $image big-item-1
	cmp $TESTDIR/big-item-1 $TESTDIR/big-item-1.2
	storage get-image-data -f $TESTDIR/big-item-2.2 $image big-item-2
	cmp $TESTDIR/big-item-2 $TESTDIR/big-item-2.2

	# Read the recorded digests of the items and compare them with the digests of the originals.
	run storage get-image-data-digest $image no-such-item
	[ "$status" -ne 0 ]
	run storage --debug=false get-image-data-digest $image big-item-1
	[ "$status" -eq 0 ]
	sum=$(sha256sum $TESTDIR/big-item-1)
	sum=sha256:"${sum%% *}"
	echo output:"$output":
	echo sum:"$sum":
	[ "$output" = "$sum" ]
	run storage --debug=false get-image-data-digest $image big-item-2
	[ "$status" -eq 0 ]
	sum=$(sha256sum $TESTDIR/big-item-2)
	sum=sha256:"${sum%% *}"
	echo output:"$output":
	echo sum:"$sum":
	[ "$output" = "$sum" ]
}

@test "container-data" {
	# Bail if "sha256sum" isn't available.
	if test -z "$(which sha256sum 2> /dev/null)" ; then
		skip "need sha256sum"
	fi

	# 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" != "" ]
	container=${output%%	*}

	# Make sure the container can be located.
	storage exists -c $container

	# Make sure the container has no big data items associated with it.
	run storage --debug=false list-container-data $container
	[ "$status" -eq 0 ]
	[ "$output" = "" ]

	# Create two random files.
	createrandom $TESTDIR/big-item-1 1234
	createrandom $TESTDIR/big-item-2 5678

	# Set each of those files as a big data item named after the file.
	storage set-container-data -f $TESTDIR/big-item-1 $container big-item-1
	storage set-container-data -f $TESTDIR/big-item-2 $container big-item-2

	# Get a list of the items.  Make sure they're both listed.
	run storage --debug=false list-container-data $container
	[ "$status" -eq 0 ]
	[ "${#lines[*]}" -eq 2 ]
	[ "${lines[0]}" = "big-item-1" ]
	[ "${lines[1]}" = "big-item-2" ]

	# Check that the recorded sizes of the items match what we decided above.
	run storage get-container-data-size $container no-such-item
	[ "$status" -ne 0 ]
	run storage --debug=false get-container-data-size $container big-item-1
	echo "$output"
	[ "$status" -eq 0 ]
	[ "$output" -eq 1234 ]
	run storage --debug=false get-container-data-size $container big-item-2
	[ "$status" -eq 0 ]
	[ "$output" -eq 5678 ]

	# Save the contents of the big data items to disk and compare them with the originals.
	run storage --debug=false get-container-data $container no-such-item
	[ "$status" -ne 0 ]
	storage get-container-data -f $TESTDIR/big-item-1.2 $container big-item-1
	cmp $TESTDIR/big-item-1 $TESTDIR/big-item-1.2
	storage get-container-data -f $TESTDIR/big-item-2.2 $container big-item-2
	cmp $TESTDIR/big-item-2 $TESTDIR/big-item-2.2

	# Read the recorded digests of the items and compare them with the digests of the originals.
	run storage get-container-data-digest $container no-such-item
	[ "$status" -ne 0 ]
	run storage --debug=false get-container-data-digest $container big-item-1
	[ "$status" -eq 0 ]
	sum=$(sha256sum $TESTDIR/big-item-1)
	sum=sha256:"${sum%% *}"
	echo output:"$output":
	echo sum:"$sum":
	[ "$output" = "$sum" ]
	run storage --debug=false get-container-data-digest $container big-item-2
	[ "$status" -eq 0 ]
	sum=$(sha256sum $TESTDIR/big-item-2)
	sum=sha256:"${sum%% *}"
	echo output:"$output":
	echo sum:"$sum":
	[ "$output" = "$sum" ]
}