Skip to content

Commit

Permalink
test: e2e test for rpm maintainer scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
tympanix authored and caarlos0 committed Apr 9, 2018
1 parent ee5a988 commit b3e51e1
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 16 deletions.
6 changes: 6 additions & 0 deletions acceptance/testdata/rpm.386.complex.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ RUN test -f /usr/share/whatever/folder/file2
RUN test -d /usr/share/whatever/folder/folder2
RUN test -f /usr/share/whatever/folder/folder2/file1
RUN test -f /usr/share/whatever/folder/folder2/file2
RUN test -f /tmp/preinstall-proof
RUN test -f /tmp/postinstall-proof
RUN test ! -f /tmp/preremove-proof
RUN test ! -f /tmp/postremove-proof
RUN echo wat >> /etc/foo/whatever.conf
RUN rpm -e foo
RUN test -f /etc/foo/whatever.conf.rpmsave
RUN test ! -f /usr/local/bin/fake
RUN test -f /tmp/preremove-proof
RUN test -f /tmp/postremove-proof
6 changes: 6 additions & 0 deletions acceptance/testdata/rpm.complex.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ RUN test -f /usr/share/whatever/folder/file2
RUN test -d /usr/share/whatever/folder/folder2
RUN test -f /usr/share/whatever/folder/folder2/file1
RUN test -f /usr/share/whatever/folder/folder2/file2
RUN test -f /tmp/preinstall-proof
RUN test -f /tmp/postinstall-proof
RUN test ! -f /tmp/preremove-proof
RUN test ! -f /tmp/postremove-proof
RUN echo wat >> /etc/foo/whatever.conf
RUN rpm -e foo
RUN test -f /etc/foo/whatever.conf.rpmsave
RUN test ! -f /usr/local/bin/fake
RUN test -f /tmp/preremove-proof
RUN test -f /tmp/postremove-proof
2 changes: 1 addition & 1 deletion deb/deb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestControl(t *testing.T) {
func TestScripts(t *testing.T) {
var w bytes.Buffer
var out = tar.NewWriter(&w)
path := "../testdata/script.sh"
path := "../testdata/scripts/preinstall.sh"
assert.Error(t, newScriptInsideTarGz(out, "doesnotexit", "preinst"))
assert.NoError(t, newScriptInsideTarGz(out, path, "preinst"))
var in = tar.NewReader(&w)
Expand Down
22 changes: 22 additions & 0 deletions rpm/rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ func exampleInfo() nfpm.Info {
ConfigFiles: map[string]string{
"../testdata/whatever.conf": "/etc/fake/fake.conf",
},
Scripts: nfpm.Scripts{
PreInstall: "../testdata/scripts/preinstall.sh",
PostInstall: "../testdata/scripts/postinstall.sh",
PreRemove: "../testdata/scripts/preremove.sh",
PostRemove: "../testdata/scripts/postremove.sh",
},
})
}

Expand Down Expand Up @@ -84,6 +90,22 @@ func TestRPMVersionWithDash(t *testing.T) {
assert.NoError(t, err)
}

func TestRPMScripts(t *testing.T) {
info := exampleInfo()
scripts, err := readScripts(info)
assert.NoError(t, err)
for actual, src := range map[string]string{
scripts.Pre: info.Scripts.PreInstall,
scripts.Post: info.Scripts.PostInstall,
scripts.Preun: info.Scripts.PreRemove,
scripts.Postun: info.Scripts.PostRemove,
} {
data, err := ioutil.ReadFile(src)
assert.NoError(t, err)
assert.Equal(t, string(data), actual)
}
}

func TestRPMNoFiles(t *testing.T) {
info := exampleInfo()
info.Files = map[string]string{}
Expand Down
20 changes: 16 additions & 4 deletions rpm/testdata/spec_4.12.x.golden
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,28 @@ rm -rf %{buildroot}


%pre
# noop
#!/bin/bash

echo "Preinstall" > /dev/null


%post
# noop
#!/bin/bash

echo "Postinstall" > /dev/null


%preun
# noop
#!/bin/bash

echo "Preremove" > /dev/null


%postun
# noop
#!/bin/bash

echo "Postremove" > /dev/null


%changelog
# noop
20 changes: 16 additions & 4 deletions rpm/testdata/spec_4.13.x.golden
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,28 @@ rm -rf %{buildroot}


%pre
# noop
#!/bin/bash

echo "Preinstall" > /dev/null


%post
# noop
#!/bin/bash

echo "Postinstall" > /dev/null


%preun
# noop
#!/bin/bash

echo "Preremove" > /dev/null


%postun
# noop
#!/bin/bash

echo "Postremove" > /dev/null


%changelog
# noop
20 changes: 16 additions & 4 deletions rpm/testdata/spec_4.14.x.golden
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,28 @@ rm -rf %{buildroot}


%pre
# noop
#!/bin/bash

echo "Preinstall" > /dev/null


%post
# noop
#!/bin/bash

echo "Postinstall" > /dev/null


%preun
# noop
#!/bin/bash

echo "Preremove" > /dev/null


%postun
# noop
#!/bin/bash

echo "Postremove" > /dev/null


%changelog
# noop
3 changes: 0 additions & 3 deletions testdata/script.sh

This file was deleted.

3 changes: 3 additions & 0 deletions testdata/scripts/postinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "Postinstall" > /dev/null
3 changes: 3 additions & 0 deletions testdata/scripts/postremove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "Postremove" > /dev/null
3 changes: 3 additions & 0 deletions testdata/scripts/preinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "Preinstall" > /dev/null
3 changes: 3 additions & 0 deletions testdata/scripts/preremove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "Preremove" > /dev/null

0 comments on commit b3e51e1

Please sign in to comment.