Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,12 @@ func updatePatchCmd(zypperCmd string, ctx *cli.Context) {
"replacefiles"}
toIgnore := []string{"author", "message"}

cmd := formatZypperCommand("ref", fmt.Sprintf("-n %v", zypperCmd))
clean := formatZypperCommand("clean -a")
makeTemp := "temp=$(mktemp -d)"
rmTemp := "rm -rf $temp"
cacheDir := "--cache-dir=$temp"
cmd := formatZypperCommand(fmt.Sprintf("%s ref", cacheDir), fmt.Sprintf("%s -n %v", cacheDir, zypperCmd))
cmd = cmdWithFlags(cmd, ctx, boolFlags, toIgnore)
cmd += " && " + clean
cmd = makeTemp + " && " + cmd + " && " + rmTemp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some comments. It's really hard to read, which is not your fault (given all the function calls), but some explanations would be a big help.


newImgID, err := runCommandAndCommitToImage(
img,
Expand Down
2 changes: 1 addition & 1 deletion patches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestPatchCommand(t *testing.T) {
{"Cannot inspect", &mockClient{inspectFail: true}, 1, []string{"opensuse:13.2", "new:1.0.0"}, true, "could not inspect image 'opensuse:13.2': inspect fail", ""},
{"Patch success", &mockClient{listReturnOneImage: true}, 0, []string{"opensuse:13.2", "new:1.0.0"}, true, "new:1.0.0 successfully created", ""},
}
cases.run(t, patchCmd, "zypper -n patch", "")
cases.run(t, patchCmd, "zypper --cache-dir=$temp ref", "")
}

// LIST PATCHES
Expand Down
15 changes: 15 additions & 0 deletions test/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,18 @@ function remove_container() {
docker rm -f $CONTAINER_ID > /dev/null
CONTAINER_ID=""
}

function check_cache() {
container_id=$(docker run -t -d $TESTIMAGE:$TAG)
docker exec $container_id zypper ref
cache_before=$(docker exec $container_id find /var/cache/zypp/ -type f -exec md5sum {} \; | md5sum)
docker exec $container_id zypper --non-interactive --cache-dir=$(mktemp -d) in tar
cache_after=$(docker exec $container_id find /var/cache/zypp/ -type f -exec md5sum {} \; | md5sum)

if [[ $cache_before == $cache_after ]]; then
echo "Cache check successful"
else
echo "Cache check failed"
fi
docker rm -f $container_id > /dev/null
}
8 changes: 8 additions & 0 deletions test/updates.bats
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ load helpers
docker rmi -f $TESTIMAGE:updated
}

# This test is currently disabled due to a bug with zypper:
# https://github.com/openSUSE/zypper/issues/180
# It will be reactivated once this is fixed
# @test "Check zypper cache" {
# sane_run check_cache
# [[ "$output" =~ "Cache check successful"+ ]]
# }

@test "zypper-docker list-updates" {
zypperdocker lu $TESTIMAGE:$TAG
[ "$status" -eq 0 ]
Expand Down
2 changes: 1 addition & 1 deletion updates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestUpdateCommand(t *testing.T) {
{"Start fail on commit", &mockClient{startFail: true}, 1, []string{"ori", "new:1.0.0"}, true, "Could not commit to the new image: Start failed", ""},
{"Update success", &mockClient{listReturnOneImage: true}, 0, []string{"opensuse:13.2", "new:1.0.0"}, true, "new:1.0.0 successfully created", ""},
}
cases.run(t, updateCmd, "zypper -n up", "")
cases.run(t, updateCmd, "zypper --cache-dir=$temp ref", "")
}

// LIST UPDATES
Expand Down