File: test-summary-update.sh

package info (click to toggle)
ostree 2025.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,996 kB
  • sloc: ansic: 70,831; sh: 15,652; xml: 5,007; yacc: 1,236; javascript: 531; makefile: 247; python: 155
file content (134 lines) | stat: -rwxr-xr-x 4,915 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
#!/bin/bash
#
# Copyright © 2017 Endless Mobile, Inc.
#
# SPDX-License-Identifier: LGPL-2.0+
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <https://www.gnu.org/licenses/>.
#
# Authors:
#  - Philip Withnall <withnall@endlessm.com>

set -euo pipefail

. $(dirname $0)/libtest.sh

echo "1..2"

COMMIT_SIGN=""
if has_ostree_feature gpgme; then
    COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
fi


cd ${test_tmpdir}
mkdir repo
ostree_repo_init repo

mkdir -p tree/root
touch tree/root/a

# Add a few commits
seq 5 | while read i; do
    echo a >> tree/root/a
    ${CMD_PREFIX} ostree --repo=repo commit --branch=test-$i -m test -s test tree
done

# Generate a plain summary file.
${CMD_PREFIX} ostree --repo=repo summary --update

# Generate a signed summary file.
${CMD_PREFIX} ostree --repo=repo summary --update ${COMMIT_SIGN}

# If the signature file was created, it should have the same
# modification time as the summary file.
if [ -n "${COMMIT_SIGN}" ]; then
    stat -c '%y' repo/summary > summary-mtime
    stat -c '%y' repo/summary.sig > summary.sig-mtime
    assert_files_equal summary-mtime summary.sig-mtime
fi

# Try various ways of adding additional data.
${CMD_PREFIX} ostree --repo=repo summary --update --add-metadata key="'value'" --add-metadata=key2=true
${CMD_PREFIX} ostree --repo=repo summary --update -m some-int='@t 123'
${CMD_PREFIX} ostree --repo=repo summary --update --add-metadata=map='@a{sv} {}'

# Check the additional metadata turns up in the output.
${CMD_PREFIX} ostree --repo=repo summary --view > summary
assert_file_has_content summary "^map: {}$"
${CMD_PREFIX} ostree --repo=repo summary --list-metadata-keys > metadata
assert_file_has_content metadata "^map$"
${CMD_PREFIX} ostree --repo=repo summary --print-metadata-key=map > metadata
assert_file_has_content metadata "^@a{sv} {}$"

echo "ok 1 update summary"

# Test again, but with collections enabled in the repository.
cd ${test_tmpdir}
rm -rf repo
ostree_repo_init repo --collection-id org.example.Collection1

mkdir -p tree/root
touch tree/root/a

# Add a few commits
seq 5 | while read i; do
    echo a >> tree/root/a
    ${CMD_PREFIX} ostree --repo=repo commit --branch=test-$i -m test -s test tree
    ${CMD_PREFIX} ostree --repo=repo refs --collections --create=org.example.Collection2:test-$i test-$i
done

# Generate a plain summary file.
${CMD_PREFIX} ostree --repo=repo summary --update

# Generate a signed summary file.
${CMD_PREFIX} ostree --repo=repo summary --update ${COMMIT_SIGN}

# If the signature file was created, it should have the same
# modification time as the summary file.
if [ -n "${COMMIT_SIGN}" ]; then
    stat -c '%y' repo/summary > summary-mtime
    stat -c '%y' repo/summary.sig > summary.sig-mtime
    assert_files_equal summary-mtime summary.sig-mtime
fi

# Try various ways of adding additional data.
${CMD_PREFIX} ostree --repo=repo summary --update --add-metadata key="'value'" --add-metadata=key2=true
${CMD_PREFIX} ostree --repo=repo summary --update -m some-int='@t 123'
${CMD_PREFIX} ostree --repo=repo summary --update --add-metadata=map='@a{sv} {}'

# Check the additional metadata turns up in the output.
${CMD_PREFIX} ostree --repo=repo summary --view > summary
assert_file_has_content summary "^map: {}$"

# Check the ostree-metadata ref has also been created with the same content and appropriate bindings.
${CMD_PREFIX} ostree --repo=repo refs --collections > refs
assert_file_has_content refs "^(org\.example\.Collection1, ostree-metadata)$"

${CMD_PREFIX} ostree --repo=repo show ostree-metadata --raw > metadata
assert_file_has_content metadata "'map': <@a{sv} {}>"
assert_file_has_content metadata "'ostree\.ref-binding': <\['ostree-metadata'\]>"
assert_file_has_content metadata "'ostree\.collection-binding': <'org\.example\.Collection1'>"

# There should be 5 commits in the ostree-metadata branch, since we’ve updated the summary 5 times.
${CMD_PREFIX} ostree --repo=repo log ostree-metadata | grep 'commit ' | wc -l > commit-count
assert_file_has_content commit-count "^5$"

# The ostree-metadata commits should not contain any files
${CMD_PREFIX} ostree --repo=repo ls ostree-metadata > files
assert_file_has_content files " /$"
cat files | wc -l > files-count
assert_file_has_content files-count "^1$"

echo "ok 2 update summary with collections"