1
1
Fork 0
mirror of https://github.com/goreleaser/nfpm synced 2024-05-20 14:26:39 +02:00
nfpm/apk/apk_test.go

468 lines
11 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/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/stretchr/testify/assert"
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
"github.com/stretchr/testify/require"
"github.com/goreleaser/nfpm/v2"
"github.com/goreleaser/nfpm/v2/files"
"github.com/goreleaser/nfpm/v2/internal/sign"
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",
},
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
},
EmptyFolders: []string{
"/var/log/whatever",
"/usr/share/whatever",
},
},
})
}
func TestArchToAlpine(t *testing.T) {
verifyArch(t, "", "x86_64")
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
verifyArch(t, "abc", "abc")
verifyArch(t, "386", "x86")
verifyArch(t, "amd64", "x86_64")
verifyArch(t, "arm", "armhf")
verifyArch(t, "arm6", "armhf")
verifyArch(t, "arm7", "armhf")
verifyArch(t, "arm64", "aarch64")
}
func verifyArch(t *testing.T, nfpmArch, expectedArch string) {
t.Helper()
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()
info.Arch = nfpmArch
assert.NoError(t, Default.Package(info, ioutil.Discard))
assert.Equal(t, expectedArch, info.Arch)
}
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)
assert.NoError(t, builderData(tw))
assert.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
assert.NoError(t, combineToApk(&bufTarget, &bufData, &bufControl))
assert.Equal(t, 2, bufTarget.Len())
}
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"},
"/": []string(nil),
} {
parts := parts
pathToTest := pathToTest
t.Run(fmt.Sprintf("pathToTest: '%s'", pathToTest), func(t *testing.T) {
assert.Equal(t, parts, pathsToCreate(pathToTest))
})
}
}
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)
assert.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,
)
assert.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,
)
assert.NoError(t, err)
}
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)
assert.NoError(t, builderControl(tw))
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
assert.NoError(t, err)
assert.Equal(t, string(bts), control)
}
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",
}
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)
assert.NoError(t, builderControl(tw))
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
assert.NoError(t, err)
assert.Equal(t, string(bts), control)
}
func TestControl(t *testing.T) {
var w bytes.Buffer
assert.NoError(t, writeControl(&w, controlData{
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
assert.NoError(t, err)
assert.Equal(t, string(bts), w.String())
}
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 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,
}
assert.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",
},
}
assert.NoError(t, Default.Package(info, ioutil.Discard))
}