File: 102-list.bats

package info (click to toggle)
golang-github-containers-toolbox 0.0.99.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,616 kB
  • sloc: sh: 3,195; ansic: 40; makefile: 36; python: 33
file content (166 lines) | stat: -rw-r--r-- 4,576 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
#!/usr/bin/env bats
#
# Copyright © 2019 – 2022 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

load 'libs/bats-support/load'
load 'libs/bats-assert/load'
load 'libs/helpers'

setup() {
  _setup_environment
  cleanup_all
}

teardown() {
  cleanup_all
}


@test "list: Run 'list' with zero containers and zero images (the list should be empty)" {
  run --keep-empty-lines $TOOLBOX list

  assert_success
  assert_output ""
}

@test "list: Run 'list -c' with zero containers (the list should be empty)" {
  run --keep-empty-lines $TOOLBOX list -c

  assert_success
  assert_output ""
}

@test "list: Run 'list -i' with zero images (the list should be empty)" {
  run --keep-empty-lines $TOOLBOX list -i

  assert_success
  assert_output ""
}

@test "list: Run 'list' with zero toolbox's containers and images, but other image (the list should be empty)" {
  pull_distro_image busybox

  run podman images

  assert_output --partial "$BUSYBOX_IMAGE"

  run --keep-empty-lines $TOOLBOX list

  assert_success
  assert_output ""
}

@test "list: List an image without a name" {
  build_image_without_name >/dev/null

  run --keep-empty-lines --separate-stderr $TOOLBOX list

  assert_success
  assert_line --index 1 --partial "<none>"
  assert [ ${#lines[@]} -eq 3 ]
  if check_bats_version 1.7.0; then
    assert [ ${#stderr_lines[@]} -eq 0 ]
  fi
}

@test "list: Image and its copy" {
  local default_image
  default_image="$(get_default_image)"

  pull_default_image_and_copy

  local num_of_images
  num_of_images="$(list_images)"
  assert_equal "$num_of_images" 2

  run --keep-empty-lines --separate-stderr "$TOOLBOX" list

  assert_success
  assert_line --index 1 --partial "$default_image"
  assert_line --index 2 --partial "$default_image-copy"
  assert [ ${#lines[@]} -eq 4 ]
  if check_bats_version 1.7.0; then
    assert [ ${#stderr_lines[@]} -eq 0 ]
  fi
}

@test "list: Try to list images and containers (no flag) with 3 containers and 2 images (the list should have 3 images and 2 containers)" {
  # Pull the two images
  pull_default_image
  pull_distro_image fedora 34

  # Create three containers
  create_default_container
  create_container non-default-one
  create_container non-default-two

  # Check images
  run --keep-empty-lines --separate-stderr $TOOLBOX list --images

  assert_success
  assert_line --index 1 --partial "fedora-toolbox:34"
  assert_line --index 2 --partial "$(get_system_id)-toolbox:$(get_system_version)"
  assert [ ${#lines[@]} -eq 4 ]
  if check_bats_version 1.7.0; then
    assert [ ${#stderr_lines[@]} -eq 0 ]
  fi

  # Check containers
  run --keep-empty-lines --separate-stderr $TOOLBOX list --containers

  assert_success
  assert_line --index 1 --partial "$(get_system_id)-toolbox-$(get_system_version)"
  assert_line --index 2 --partial "non-default-one"
  assert_line --index 3 --partial "non-default-two"
  assert [ ${#lines[@]} -eq 5 ]
  if check_bats_version 1.7.0; then
    assert [ ${#stderr_lines[@]} -eq 0 ]
  fi

  # Check all together
  run --keep-empty-lines --separate-stderr $TOOLBOX list

  assert_success
  assert_line --index 1 --partial "fedora-toolbox:34"
  assert_line --index 2 --partial "$(get_system_id)-toolbox:$(get_system_version)"
  assert_line --index 5 --partial "$(get_system_id)-toolbox-$(get_system_version)"
  assert_line --index 6 --partial "non-default-one"
  assert_line --index 7 --partial "non-default-two"
  assert [ ${#lines[@]} -eq 9 ]
  if check_bats_version 1.7.0; then
    assert [ ${#stderr_lines[@]} -eq 0 ]
  fi
}

@test "list: Images with and without names" {
  local default_image
  default_image="$(get_default_image)"

  pull_default_image
  pull_distro_image fedora 34
  build_image_without_name >/dev/null

  run --keep-empty-lines --separate-stderr "$TOOLBOX" list --images

  assert_success
  assert_line --index 1 --partial "<none>"
  assert_line --index 2 --partial "fedora-toolbox:34"
  assert_line --index 3 --partial "$default_image"
  assert [ ${#lines[@]} -eq 5 ]
  if check_bats_version 1.7.0; then
    assert [ ${#stderr_lines[@]} -eq 0 ]
  fi
}