1
1
Fork 0
mirror of https://github.com/goreleaser/nfpm synced 2024-05-10 00:16:13 +02:00
nfpm/apk/apk_test.go

720 lines
17 KiB
Go
Raw Normal View History

feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
package apk
import (
"archive/tar"
"bytes"
"compress/gzip"
"crypto/sha1" // nolint:gosec
"crypto/sha256"
"errors"
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
"flag"
"fmt"
"io"
"io/ioutil"
"path"
"path/filepath"
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
"testing"
"github.com/goreleaser/nfpm/v2"
"github.com/goreleaser/nfpm/v2/files"
"github.com/goreleaser/nfpm/v2/internal/sign"
"github.com/stretchr/testify/require"
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
)
// nolint: gochecknoglobals
var update = flag.Bool("update", false, "update apk .golden files")
func exampleInfo() *nfpm.Info {
return nfpm.WithDefaults(&nfpm.Info{
Name: "foo",
Arch: "amd64",
Description: "Foo does things",
Priority: "extra",
Maintainer: "Carlos A Becker <pkg@carlosbecker.com>",
Version: "v1.0.0",
Release: "r1",
Section: "default",
Homepage: "http://carlosbecker.com",
Vendor: "nope",
Overridables: nfpm.Overridables{
Depends: []string{
"bash",
"foo",
},
Recommends: []string{
"git",
"bar",
},
Suggests: []string{
"bash",
"lala",
},
Replaces: []string{
"svn",
"subversion",
},
Provides: []string{
"bzr",
"zzz",
},
Conflicts: []string{
"zsh",
"foobarsh",
},
Contents: []*files.Content{
{
Source: "../testdata/fake",
Destination: "/usr/local/bin/fake",
},
{
Source: "../testdata/whatever.conf",
Destination: "/usr/share/doc/fake/fake.txt",
},
{
Source: "../testdata/whatever.conf",
Destination: "/etc/fake/fake.conf",
Type: "config",
},
{
Destination: "/var/log/whatever",
Type: "dir",
},
{
Destination: "/usr/share/whatever",
Type: "dir",
},
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
},
},
})
}
func TestCreateBuilderData(t *testing.T) {
info := exampleInfo()
err := info.Validate()
require.NoError(t, err)
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
size := int64(0)
builderData := createBuilderData(info, &size)
var buf bytes.Buffer
tw := tar.NewWriter(&buf)
require.NoError(t, builderData(tw))
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
require.Equal(t, 11784, buf.Len())
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
}
func TestCombineToApk(t *testing.T) {
var bufData bytes.Buffer
bufData.Write([]byte{1})
var bufControl bytes.Buffer
bufControl.Write([]byte{2})
var bufTarget bytes.Buffer
require.NoError(t, combineToApk(&bufTarget, &bufData, &bufControl))
require.Equal(t, 2, bufTarget.Len())
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
}
func TestPathsToCreate(t *testing.T) {
for pathToTest, parts := range map[string][]string{
"/usr/share/doc/whatever/foo.md": {"usr", "usr/share", "usr/share/doc", "usr/share/doc/whatever"},
"/var/moises": {"var"},
"/": {},
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
} {
parts := parts
pathToTest := pathToTest
t.Run(fmt.Sprintf("pathToTest: '%s'", pathToTest), func(t *testing.T) {
require.Equal(t, parts, pathsToCreate(pathToTest))
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
})
}
}
func TestDefaultWithArch(t *testing.T) {
expectedChecksums := map[string]string{
"usr/share/doc/fake/fake.txt": "96c335dc28122b5f09a4cef74b156cd24c23784c",
"usr/local/bin/fake": "f46cece3eeb7d9ed5cb244d902775427be71492d",
"etc/fake/fake.conf": "96c335dc28122b5f09a4cef74b156cd24c23784c",
}
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
for _, arch := range []string{"386", "amd64"} {
arch := arch
t.Run(arch, func(t *testing.T) {
info := exampleInfo()
info.Arch = arch
var f bytes.Buffer
require.NoError(t, Default.Package(info, &f))
gz, err := gzip.NewReader(&f)
require.NoError(t, err)
defer gz.Close()
tr := tar.NewReader(gz)
for {
hdr, err := tr.Next()
if errors.Is(err, io.EOF) {
break // End of archive
}
require.NoError(t, err)
require.Equal(t, expectedChecksums[hdr.Name], hdr.PAXRecords["APK-TOOLS.checksum.SHA1"], hdr.Name)
}
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
})
}
}
func TestNoInfo(t *testing.T) {
err := Default.Package(nfpm.WithDefaults(&nfpm.Info{}), ioutil.Discard)
require.Error(t, err)
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
}
func TestFileDoesNotExist(t *testing.T) {
abs, err := filepath.Abs("../testdata/whatever.confzzz")
require.NoError(t, err)
err = Default.Package(
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
nfpm.WithDefaults(&nfpm.Info{
Name: "foo",
Arch: "amd64",
Description: "Foo does things",
Priority: "extra",
Maintainer: "Carlos A Becker <pkg@carlosbecker.com>",
Version: "1.0.0",
Section: "default",
Homepage: "http://carlosbecker.com",
Vendor: "nope",
Overridables: nfpm.Overridables{
Depends: []string{
"bash",
},
Contents: []*files.Content{
{
Source: "../testdata/fake",
Destination: "/usr/local/bin/fake",
},
{
Source: "../testdata/whatever.confzzz",
Destination: "/etc/fake/fake.conf",
Type: "config",
},
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
},
},
}),
ioutil.Discard,
)
require.EqualError(t, err, fmt.Sprintf("matching \"%s\": file does not exist", filepath.ToSlash(abs)))
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
}
func TestNoFiles(t *testing.T) {
err := Default.Package(
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
nfpm.WithDefaults(&nfpm.Info{
Name: "foo",
Arch: "amd64",
Description: "Foo does things",
Priority: "extra",
Maintainer: "Carlos A Becker <pkg@carlosbecker.com>",
Version: "1.0.0",
Section: "default",
Homepage: "http://carlosbecker.com",
Vendor: "nope",
Overridables: nfpm.Overridables{
Depends: []string{
"bash",
},
},
}),
ioutil.Discard,
)
require.NoError(t, err)
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
}
func TestCreateBuilderControl(t *testing.T) {
info := exampleInfo()
size := int64(12345)
err := info.Validate()
require.NoError(t, err)
builderControl := createBuilderControl(info, size, sha256.New().Sum(nil))
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
var w bytes.Buffer
tw := tar.NewWriter(&w)
require.NoError(t, builderControl(tw))
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
control := string(extractFromTar(t, w.Bytes(), ".PKGINFO"))
golden := "testdata/TestCreateBuilderControl.golden"
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
if *update {
require.NoError(t, ioutil.WriteFile(golden, []byte(control), 0o655)) // nolint: gosec
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
}
bts, err := ioutil.ReadFile(golden) //nolint:gosec
require.NoError(t, err)
require.Equal(t, string(bts), control)
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
}
func TestCreateBuilderControlScripts(t *testing.T) {
info := exampleInfo()
info.Scripts = nfpm.Scripts{
PreInstall: "../testdata/scripts/preinstall.sh",
PostInstall: "../testdata/scripts/postinstall.sh",
PreRemove: "../testdata/scripts/preremove.sh",
PostRemove: "../testdata/scripts/postremove.sh",
}
info.APK.Scripts = nfpm.APKScripts{
PreUpgrade: "../testdata/scripts/preupgrade.sh",
PostUpgrade: "../testdata/scripts/postupgrade.sh",
}
err := info.Validate()
require.NoError(t, err)
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
size := int64(12345)
builderControl := createBuilderControl(info, size, sha256.New().Sum(nil))
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
var w bytes.Buffer
tw := tar.NewWriter(&w)
require.NoError(t, builderControl(tw))
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
control := string(extractFromTar(t, w.Bytes(), ".PKGINFO"))
golden := "testdata/TestCreateBuilderControlScripts.golden"
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
if *update {
require.NoError(t, ioutil.WriteFile(golden, []byte(control), 0o655)) // nolint: gosec
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
}
bts, err := ioutil.ReadFile(golden) //nolint:gosec
require.NoError(t, err)
require.Equal(t, string(bts), control)
// Validate scripts are correct
script := string(extractFromTar(t, w.Bytes(), ".pre-install"))
require.Contains(t, script, `echo "Preinstall" > /dev/null`)
script = string(extractFromTar(t, w.Bytes(), ".post-install"))
require.Contains(t, script, `echo "Postinstall" > /dev/null`)
script = string(extractFromTar(t, w.Bytes(), ".pre-upgrade"))
require.Contains(t, script, `echo "PreUpgrade" > /dev/null`)
script = string(extractFromTar(t, w.Bytes(), ".post-upgrade"))
require.Contains(t, script, `echo "PostUpgrade" > /dev/null`)
script = string(extractFromTar(t, w.Bytes(), ".pre-deinstall"))
require.Contains(t, script, `echo "Preremove" > /dev/null`)
script = string(extractFromTar(t, w.Bytes(), ".post-deinstall"))
require.Contains(t, script, `echo "Postremove" > /dev/null`)
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
}
func TestControl(t *testing.T) {
var w bytes.Buffer
require.NoError(t, writeControl(&w, controlData{
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
Info: exampleInfo(),
InstalledSize: 10,
}))
golden := "testdata/TestControl.golden"
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
if *update {
require.NoError(t, ioutil.WriteFile(golden, w.Bytes(), 0o655)) // nolint: gosec
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
}
bts, err := ioutil.ReadFile(golden) //nolint:gosec
require.NoError(t, err)
require.Equal(t, string(bts), w.String())
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
}
func TestSignature(t *testing.T) {
info := exampleInfo()
info.APK.Signature.KeyFile = "../internal/sign/testdata/rsa.priv"
info.APK.Signature.KeyName = "testkey.rsa.pub"
info.APK.Signature.KeyPassphrase = "hunter2"
err := info.Validate()
require.NoError(t, err)
digest := sha1.New().Sum(nil) // nolint:gosec
var signatureTarGz bytes.Buffer
tw := tar.NewWriter(&signatureTarGz)
require.NoError(t, createSignatureBuilder(digest, info)(tw))
signature := extractFromTar(t, signatureTarGz.Bytes(), ".SIGN.RSA.testkey.rsa.pub")
err = sign.RSAVerifySHA1Digest(digest, signature, "../internal/sign/testdata/rsa.pub")
require.NoError(t, err)
err = Default.Package(info, ioutil.Discard)
require.NoError(t, err)
}
func TestSignatureError(t *testing.T) {
info := exampleInfo()
info.APK.Signature.KeyFile = "../internal/sign/testdata/rsa.priv"
info.APK.Signature.KeyName = "testkey.rsa.pub"
info.APK.Signature.KeyPassphrase = "hunter2"
err := info.Validate()
require.NoError(t, err)
// wrong hash format
digest := sha256.New().Sum(nil)
var signatureTarGz bytes.Buffer
err = createSignature(&signatureTarGz, info, digest)
require.Error(t, err)
var expectedError *nfpm.ErrSigningFailure
require.True(t, errors.As(err, &expectedError))
info.APK.Signature.KeyName = ""
info.Maintainer = ""
digest = sha1.New().Sum(nil) // nolint:gosec
err = createSignature(&signatureTarGz, info, digest)
require.True(t, errors.As(err, &expectedError))
}
func TestDisableGlobbing(t *testing.T) {
info := exampleInfo()
info.DisableGlobbing = true
info.Contents = []*files.Content{
{
Source: "../testdata/{file}[",
Destination: "/test/{file}[",
},
}
err := info.Validate()
require.NoError(t, err)
size := int64(0)
var dataTarGz bytes.Buffer
_, err = createData(&dataTarGz, info, &size)
require.NoError(t, err)
gzr, err := gzip.NewReader(&dataTarGz)
require.NoError(t, err)
dataTar, err := ioutil.ReadAll(gzr)
require.NoError(t, err)
extractedContent := extractFromTar(t, dataTar, "test/{file}[")
actualContent, err := ioutil.ReadFile("../testdata/{file}[")
require.NoError(t, err)
require.Equal(t, actualContent, extractedContent)
}
func extractFromTar(t *testing.T, tarFile []byte, fileName string) []byte {
t.Helper()
tr := tar.NewReader(bytes.NewReader(tarFile))
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
for {
hdr, err := tr.Next()
if errors.Is(err, io.EOF) {
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
break
}
require.NoError(t, err)
if hdr.Name != fileName {
continue
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
}
data, err := ioutil.ReadAll(tr)
require.NoError(t, err)
return data
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
}
t.Fatalf("file %q not found in tar file", fileName)
return nil
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
}
func tarContents(tb testing.TB, tarFile []byte) []string {
tb.Helper()
contents := []string{}
tr := tar.NewReader(bytes.NewReader(tarFile))
for {
hdr, err := tr.Next()
if errors.Is(err, io.EOF) {
break // End of archive
}
require.NoError(tb, err)
contents = append(contents, hdr.Name)
}
return contents
}
func TestAPKConventionalFileName(t *testing.T) {
apkName := "default"
testCases := []struct {
Arch string
Version string
Meta string
Release string
Prerelease string
Expect string
}{
{
Arch: "amd64", Version: "1.2.3",
Expect: "default_1.2.3_x86_64.apk",
},
{
Arch: "386", Version: "1.2.3", Meta: "git",
Expect: "default_1.2.3+git_x86.apk",
},
{
Arch: "386", Version: "1.2.3", Meta: "git", Release: "1",
Expect: "default_1.2.3-1+git_x86.apk",
},
{
Arch: "all", Version: "1.2.3",
Expect: "default_1.2.3_all.apk",
},
{
Arch: "386", Version: "1.2.3", Release: "1", Prerelease: "5",
Expect: "default_1.2.3-1~5_x86.apk",
},
}
for _, testCase := range testCases {
info := &nfpm.Info{
Name: apkName,
Arch: testCase.Arch,
Version: testCase.Version,
VersionMetadata: testCase.Meta,
Release: testCase.Release,
Prerelease: testCase.Prerelease,
}
require.Equal(t, testCase.Expect, Default.ConventionalFileName(info))
}
}
func TestPackageSymlinks(t *testing.T) {
info := exampleInfo()
info.Contents = []*files.Content{
{
Source: "../testdata/fake",
Destination: "fake",
Type: "symlink",
},
}
require.NoError(t, Default.Package(info, ioutil.Discard))
}
func TestDirectories(t *testing.T) {
info := exampleInfo()
info.Contents = []*files.Content{
{
Source: "../testdata/whatever.conf",
Destination: "/etc/foo/file",
},
{
Source: "../testdata/whatever.conf",
Destination: "/etc/bar/file",
},
{
Destination: "/etc/bar",
Type: "dir",
FileInfo: &files.ContentFileInfo{
Owner: "test",
Mode: 0o700,
},
},
{
Destination: "/etc/baz",
Type: "dir",
},
{
Destination: "/usr/lib/something/somethingelse",
Type: "dir",
},
}
require.NoError(t, info.Validate())
var buf bytes.Buffer
size := int64(0)
err := createFilesInsideTarGz(info, tar.NewWriter(&buf), make(map[string]bool), &size)
require.NoError(t, err)
require.Equal(t, []string{
"etc/",
"etc/bar/",
"etc/baz/",
"usr/",
"usr/lib/",
"usr/lib/something/",
"usr/lib/something/somethingelse/",
"etc/bar/file",
"etc/foo/",
"etc/foo/file",
}, getTree(t, buf.Bytes()))
// for apks all implicit or explicit directories are created in the tarball
h := extractFileHeaderFromTar(t, buf.Bytes(), "/etc")
require.Equal(t, h.Typeflag, byte(tar.TypeDir))
h = extractFileHeaderFromTar(t, buf.Bytes(), "/etc/foo")
require.Equal(t, h.Typeflag, byte(tar.TypeDir))
h = extractFileHeaderFromTar(t, buf.Bytes(), "/etc/bar")
require.Equal(t, h.Typeflag, byte(tar.TypeDir))
require.Equal(t, h.Mode, int64(0o700))
require.Equal(t, h.Uname, "test")
h = extractFileHeaderFromTar(t, buf.Bytes(), "/etc/baz")
require.Equal(t, h.Typeflag, byte(tar.TypeDir))
}
func TestNoDuplicateAutocreatedDirectories(t *testing.T) {
info := exampleInfo()
info.DisableGlobbing = true
info.Contents = []*files.Content{
{
Source: "../testdata/fake",
Destination: "/etc/foo/bar",
},
{
Type: "dir",
Destination: "/etc/foo",
},
}
require.NoError(t, info.Validate())
expected := map[string]bool{
"etc/": true,
"etc/foo/": true,
"etc/foo/bar": true,
}
var buf bytes.Buffer
size := int64(0)
err := createFilesInsideTarGz(info, tar.NewWriter(&buf), make(map[string]bool), &size)
require.NoError(t, err)
contents := tarContents(t, buf.Bytes())
if len(expected) != len(contents) {
t.Fatalf("contents has %d entries instead of %d: %#v", len(contents), len(expected), contents)
}
for _, entry := range contents {
if !expected[entry] {
t.Fatalf("unexpected content: %q", entry)
}
}
}
func TestNoDuplicateDirectories(t *testing.T) {
info := exampleInfo()
info.DisableGlobbing = true
info.Contents = []*files.Content{
{
Type: "dir",
Destination: "/etc/foo",
},
{
Type: "dir",
Destination: "/etc/foo/",
},
}
require.NoError(t, info.Validate())
var buf bytes.Buffer
size := int64(0)
err := createFilesInsideTarGz(info, tar.NewWriter(&buf), make(map[string]bool), &size)
require.Error(t, err)
}
func TestNoDuplicateContents(t *testing.T) {
info := exampleInfo()
info.Contents = []*files.Content{
{
Source: "../testdata/whatever.conf",
Destination: "/etc/foo/file",
},
{
Source: "../testdata/whatever.conf",
Destination: "/etc/bar/file",
},
{
Destination: "/etc/bar",
Type: "dir",
FileInfo: &files.ContentFileInfo{
Owner: "test",
Mode: 0o700,
},
},
{
Destination: "/etc/baz",
Type: "dir",
},
}
require.NoError(t, info.Validate())
var buf bytes.Buffer
size := int64(0)
err := createFilesInsideTarGz(info, tar.NewWriter(&buf), make(map[string]bool), &size)
require.NoError(t, err)
exists := map[string]bool{}
tr := tar.NewReader(bytes.NewReader(buf.Bytes()))
for {
hdr, err := tr.Next()
if errors.Is(err, io.EOF) {
break // End of archive
}
require.NoError(t, err)
_, ok := exists[hdr.Name]
if ok {
t.Fatalf("%s exists more than once in tarball", hdr.Name)
}
exists[hdr.Name] = true
}
}
func extractFileHeaderFromTar(tb testing.TB, tarFile []byte, filename string) *tar.Header {
tb.Helper()
tr := tar.NewReader(bytes.NewReader(tarFile))
for {
hdr, err := tr.Next()
if errors.Is(err, io.EOF) {
break // End of archive
}
require.NoError(tb, err)
if path.Join("/", hdr.Name) != path.Join("/", filename) { // nolint:gosec
continue
}
return hdr
}
tb.Fatalf("file %q does not exist in tar", filename)
return nil
}
func getTree(tb testing.TB, tarFile []byte) []string {
tb.Helper()
var result []string
tr := tar.NewReader(bytes.NewReader(tarFile))
for {
hdr, err := tr.Next()
if errors.Is(err, io.EOF) {
break // End of archive
}
require.NoError(tb, err)
result = append(result, hdr.Name)
}
return result
}
func TestArches(t *testing.T) {
for k := range archToAlpine {
t.Run(k, func(t *testing.T) {
info := exampleInfo()
info.Arch = k
info = ensureValidArch(info)
require.Equal(t, archToAlpine[k], info.Arch)
})
}
t.Run("override", func(t *testing.T) {
info := exampleInfo()
info.APK.Arch = "foo64"
info = ensureValidArch(info)
require.Equal(t, "foo64", info.Arch)
})
}