mirror of
https://github.com/goreleaser/nfpm
synced 2024-03-29 07:10:15 +01:00
fix: improve contents.type (#581)
* fix: improve contents.type improved jsonschema and added validations Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: config|noreplace Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
b30373beb0
commit
2918f99b60
|
@ -9,6 +9,7 @@ on:
|
|||
- 'www/*'
|
||||
- 'cmd/*'
|
||||
- 'internal/cmd/*'
|
||||
- 'files/*'
|
||||
|
||||
jobs:
|
||||
docs:
|
||||
|
|
|
@ -88,6 +88,7 @@ tasks:
|
|||
- ./scripts/cmd_docs.sh
|
||||
sources:
|
||||
- cmd/*.go
|
||||
- files/*.go
|
||||
- nfpm.go
|
||||
- ./scripts/cmd_docs.sh
|
||||
- CONTRIBUTING.md
|
||||
|
|
|
@ -76,6 +76,11 @@ func exampleInfo() *nfpm.Info {
|
|||
Destination: "/etc/fake/fake.conf",
|
||||
Type: "config",
|
||||
},
|
||||
{
|
||||
Source: "../testdata/whatever.conf",
|
||||
Destination: "/etc/fake/fake2.conf",
|
||||
Type: "config|noreplace",
|
||||
},
|
||||
{
|
||||
Destination: "/var/log/whatever",
|
||||
Type: "dir",
|
||||
|
@ -105,7 +110,7 @@ func TestCreateBuilderData(t *testing.T) {
|
|||
|
||||
require.NoError(t, builderData(tw))
|
||||
|
||||
require.Equal(t, 11784, buf.Len())
|
||||
require.Equal(t, 13832, buf.Len())
|
||||
}
|
||||
|
||||
func TestCombineToApk(t *testing.T) {
|
||||
|
@ -140,6 +145,7 @@ func TestDefaultWithArch(t *testing.T) {
|
|||
"usr/share/doc/fake/fake.txt": "96c335dc28122b5f09a4cef74b156cd24c23784c",
|
||||
"usr/local/bin/fake": "f46cece3eeb7d9ed5cb244d902775427be71492d",
|
||||
"etc/fake/fake.conf": "96c335dc28122b5f09a4cef74b156cd24c23784c",
|
||||
"etc/fake/fake2.conf": "96c335dc28122b5f09a4cef74b156cd24c23784c",
|
||||
}
|
||||
for _, arch := range []string{"386", "amd64"} {
|
||||
arch := arch
|
||||
|
|
|
@ -73,6 +73,11 @@ func exampleInfo() *nfpm.Info {
|
|||
Destination: "/etc/fake/fake.conf",
|
||||
Type: "config",
|
||||
},
|
||||
{
|
||||
Source: "../testdata/whatever.conf",
|
||||
Destination: "/etc/fake/fake2.conf",
|
||||
Type: "config|noreplace",
|
||||
},
|
||||
{
|
||||
Destination: "/var/log/whatever",
|
||||
Type: "dir",
|
||||
|
|
|
@ -15,8 +15,8 @@ import (
|
|||
// of one file to copy into a package.
|
||||
type Content struct {
|
||||
Source string `yaml:"src,omitempty" json:"src,omitempty"`
|
||||
Destination string `yaml:"dst,omitempty" json:"dst,omitempty"`
|
||||
Type string `yaml:"type,omitempty" json:"type,omitempty"`
|
||||
Destination string `yaml:"dst" json:"dst"`
|
||||
Type string `yaml:"type,omitempty" json:"type,omitempty" jsonschema:"enum=symlink,enum=ghost,enum=config,enum=config|noreplace,enum=dir,enum=,default="`
|
||||
Packager string `yaml:"packager,omitempty" json:"packager,omitempty"`
|
||||
FileInfo *ContentFileInfo `yaml:"file_info,omitempty" json:"file_info,omitempty"`
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ func ExpandContentGlobs(contents Contents, disableGlobbing bool) (files Contents
|
|||
// Ghost, symlinks and dirs need to be in the list, but dont glob
|
||||
// them because they do not really exist
|
||||
files = append(files, f.WithFileInfoDefaults())
|
||||
default:
|
||||
case "config", "config|noreplace", "file", "":
|
||||
globbed, err = glob.Glob(f.Source, f.Destination, disableGlobbing)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -160,6 +160,8 @@ func ExpandContentGlobs(contents Contents, disableGlobbing bool) (files Contents
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
return files, fmt.Errorf("invalid file type: %s", f.Type)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -382,3 +382,48 @@ func TestDestEndsWithSlash(t *testing.T) {
|
|||
require.Len(t, result, 1)
|
||||
require.Equal(t, "foo/a.txt", result[0].Destination)
|
||||
}
|
||||
|
||||
func TestInvalidFileType(t *testing.T) {
|
||||
var config testStruct
|
||||
dec := yaml.NewDecoder(strings.NewReader(`---
|
||||
contents:
|
||||
- src: testdata/globtest/**/*
|
||||
dst: /bla
|
||||
type: filr
|
||||
`))
|
||||
dec.KnownFields(true)
|
||||
require.NoError(t, dec.Decode(&config))
|
||||
_, err := files.ExpandContentGlobs(config.Contents, false)
|
||||
require.EqualError(t, err, "invalid file type: filr")
|
||||
}
|
||||
|
||||
func TestValidFileTypes(t *testing.T) {
|
||||
var config testStruct
|
||||
dec := yaml.NewDecoder(strings.NewReader(`---
|
||||
contents:
|
||||
- src: testdata/globtest/a.txt
|
||||
dst: /f1.txt
|
||||
- src: testdata/globtest/a.txt
|
||||
dst: /f2.txt
|
||||
type: file
|
||||
- src: testdata/globtest/a.txt
|
||||
dst: /f3.txt
|
||||
type: config
|
||||
- src: testdata/globtest/a.txt
|
||||
dst: /f4.txt
|
||||
type: config|noreplace
|
||||
- src: testdata/globtest/a.txt
|
||||
dst: /f5.txt
|
||||
type: symlink
|
||||
- src: testdata/globtest/a.txt
|
||||
dst: /f6.txt
|
||||
type: dir
|
||||
- src: testdata/globtest/a.txt
|
||||
dst: /f7.txt
|
||||
type: ghost
|
||||
`))
|
||||
dec.KnownFields(true)
|
||||
require.NoError(t, dec.Decode(&config))
|
||||
_, err := files.ExpandContentGlobs(config.Contents, false)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
|
|
@ -317,7 +317,16 @@
|
|||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"symlink",
|
||||
"ghost",
|
||||
"config",
|
||||
"config|noreplace",
|
||||
"dir",
|
||||
""
|
||||
],
|
||||
"default": ""
|
||||
},
|
||||
"packager": {
|
||||
"type": "string"
|
||||
|
@ -327,7 +336,10 @@
|
|||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"type": "object"
|
||||
"type": "object",
|
||||
"required": [
|
||||
"dst"
|
||||
]
|
||||
},
|
||||
"ContentFileInfo": {
|
||||
"properties": {
|
||||
|
|
Loading…
Reference in New Issue