summaryrefslogtreecommitdiff
path: root/imag-store/tests/002-retrieve_test.sh
blob: e7ba59624f27231c9d14da9eeed6fed629503938 (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
#!/usr/bin/env bash

source $(dirname ${BASH_SOURCE[0]})/../../tests/utils.sh
source $(dirname ${BASH_SOURCE[0]})/utils.sh

std_header() {
    cat <<EOS
---
[imag]
links = []
version = "0.4.0"
---
EOS
}

retrieve() {
    silent imag-store retrieve $*
}

test_retrieve_nothing() {
    local id="test-retrieve_nothing"

    imag-store create -p ${id} || { err "create failed"; return 1; }

    out "Going to test the retrieve functionality now"
    local zero_out="$(retrieve --id ${id})" || return 1
    out "Retrieving for zero_out finished"

    if [[ ! -z "$zero_out" ]]; then
        err "Expected zero output, got '$zero_out'"
        return 1
    fi
}

test_retrieve_content() {
    local id="test-retrieve_simple"

    imag-store create -p ${id} || { err "create failed"; return 1; }

    out "Going to test the retrieve functionality now"

    local content_out="$(retrieve --id ${id} --content)" || return 1
    out "Retrieving for content_out finished"

    if [[ ! -z "$content_out" ]]; then
        err "Expected content output == zero output, got '$content_out'"
        return 1
    fi
}

test_retrieve_header() {
    local id="test-retrieve_simple"

    imag-store create -p ${id} || { err "create failed"; return 1; }

    out "Going to test the retrieve functionality now"
    local header_out="$(retrieve --id ${id} --header)"
    out "Retrieving for header_out finished"

    if [[ ! "$header_out" != "$(std_header)" ]]; then
        err "Expected header as output, got '$header_out'"
        return 1
    fi
}

test_retrieve_raw() {
    local id="test-retrieve_simple"

    imag-store create -p ${id} || { err "create failed"; return 1; }

    out "Going to test the retrieve functionality now"
    local both_out="$(retrieve --id ${id} --raw)"
    out "Retrieving for both_out finished"

    if [[ "$both_out" != "$(std_header)" ]]; then
        err "Expected "$(std_header)" as output, got '$both_out'"
        return 1
    fi
}

invoke_tests                            \
    test_retrieve_nothing               \
    test_retrieve_content               \
    test_retrieve_header                \
    test_retrieve_raw