summaryrefslogtreecommitdiff
path: root/test/system/120-load.bats
blob: 86b396c4ae82b630a58749c22b285a0137f68509 (plain)
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
#!/usr/bin/env bats   -*- bats -*-
#
# tests for podman load
#

load helpers

# Custom helpers for this test only. These just save us having to duplicate
# the same thing four times (two tests, each with -i and stdin).
#
# initialize, read image ID and name
get_iid_and_name() {
    run_podman images -a --format '{{.ID}} {{.Repository}}:{{.Tag}}'
    read iid img_name < <(echo "$output")

    archive=$PODMAN_TMPDIR/myimage-$(random_string 8).tar
}

# Simple verification of image ID and name
verify_iid_and_name() {
    run_podman images -a --format '{{.ID}} {{.Repository}}:{{.Tag}}'
    read new_iid new_img_name < <(echo "$output")

    # Verify
    is "$new_iid"      "$iid" "Image ID of loaded image == original"
    is "$new_img_name" "$1"   "Name & tag of restored image"
}

@test "podman save to pipe and load" {
    get_iid_and_name

    # We can't use run_podman because that uses the BATS 'run' function
    # which redirects stdout and stderr. Here we need to guarantee
    # that podman's stdout is a pipe, not any other form of redirection
    $PODMAN save --format oci-archive $IMAGE | cat >$archive
    if [ "$status" -ne 0 ]; then
        die "Command failed: podman save ... | cat"
    fi

    # Make sure we can reload it
    # FIXME: when/if 7337 gets fixed, add a random tag instead of rmi'ing
    # FIXME: when/if 7371 gets fixed, use verify_iid_and_name()
    run_podman rmi $iid
    run_podman load -i $archive

    # FIXME: cannot compare IID, see #7371
    run_podman images -a --format '{{.Repository}}:{{.Tag}}'
    is "$output" "$IMAGE" "image preserves name across save/load"
}


@test "podman load - by image ID" {
    # FIXME: how to build a simple archive instead?
    get_iid_and_name

    # Save image by ID, and remove it.
    run_podman save $iid -o $archive
    run_podman rmi $iid

    # Load using -i; IID should be preserved, but name is not.
    run_podman load -i $archive
    verify_iid_and_name "<none>:<none>"

    # Same as above, using stdin
    run_podman rmi $iid
    run_podman load < $archive
    verify_iid_and_name "<none>:<none>"

    # Same as above, using stdin but with `podman image load`
    run_podman rmi $iid
    run_podman image load < $archive
    verify_iid_and_name "<none>:<none>"

    # Cleanup: since load-by-iid doesn't preserve name, re-tag it;
    # otherwise our global teardown will rmi and re-pull our standard image.
    run_podman tag $iid $img_name
}

@test "podman load - by image name" {
    get_iid_and_name
    run_podman save $img_name -o $archive
    run_podman rmi $iid

    # Load using -i; this time the image should be tagged.
    run_podman load -i $archive
    verify_iid_and_name $img_name
    run_podman rmi $iid

    # Also make sure that `image load` behaves the same.
    run_podman image load -i $archive
    verify_iid_and_name $img_name
    run_podman rmi $iid

    # Same as above, using stdin
    run_podman load < $archive
    verify_iid_and_name $img_name
}

@test "podman load - NAME and NAME:TAG arguments work" {
    get_iid_and_name
    run_podman save $iid -o $archive
    run_podman rmi $iid

    # Load with just a name (note: names must be lower-case)
    random_name=$(random_string 20 | tr A-Z a-z)
    run_podman load -i $archive $random_name
    verify_iid_and_name "localhost/$random_name:latest"

    # Load with NAME:TAG arg
    run_podman rmi $iid
    random_tag=$(random_string 10 | tr A-Z a-z)
    run_podman load -i $archive $random_name:$random_tag
    verify_iid_and_name "localhost/$random_name:$random_tag"

    # Cleanup: restore desired image name
    run_podman tag $iid $img_name
    run_podman rmi "$random_name:$random_tag"
}


@test "podman load - will not read from tty" {
    if [ ! -t 0 ]; then
        skip "STDIN is not a tty"
    fi

    run_podman 125 load
    is "$output" \
       "Error: cannot read from terminal. Use command-line redirection" \
       "Diagnostic from 'podman load' without redirection or -i"
}

# vim: filetype=sh