feat(config): Env/file support for Worker description
This commit is contained in:
1 parent
baa1d88f1f
commit
5f36057f65
4 files changed
+69
No files matched your search
@@ -376,6 +376,14 @@ func Parse(d string) (*Config, error) {
|
||||
return nil, errors.New("Worker name contains non-printable characters")
|
||||
}
|
||||
|
||||
result.Worker.Description, err = parseutil.ParsePath(result.Worker.Description)
|
||||
if err != nil && !errors.Is(err, parseutil.ErrNotAUrl) {
|
||||
return nil, fmt.Errorf("Error parsing worker description: %w", err)
|
||||
}
|
||||
if !strutil.Printable(result.Worker.Description) {
|
||||
return nil, errors.New("Worker description contains non-printable characters")
|
||||
}
|
||||
|
||||
if result.Worker.TagsRaw != nil {
|
||||
switch t := result.Worker.TagsRaw.(type) {
|
||||
// We allow `tags` to be a simple string containing a URL with schema.
|
||||
|
||||
@@ -1007,6 +1007,61 @@ func TestControllerDescription(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkerDescription(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
in string
|
||||
envDescription string
|
||||
expDescription string
|
||||
expErr bool
|
||||
expErrStr string
|
||||
}{
|
||||
{
|
||||
name: "Valid worker description from env var",
|
||||
in: `
|
||||
worker {
|
||||
description = "env://WORKER_DESCRIPTION"
|
||||
}`,
|
||||
envDescription: "Test worker description",
|
||||
expDescription: "Test worker description",
|
||||
expErr: false,
|
||||
}, {
|
||||
name: "Invalid worker description",
|
||||
in: `
|
||||
worker {
|
||||
description = "\uTest worker description"
|
||||
}`,
|
||||
expErr: true,
|
||||
expErrStr: "At 3:22: illegal char escape",
|
||||
}, {
|
||||
name: "Not a URL, non-printable description",
|
||||
in: `
|
||||
worker {
|
||||
description = "\x00"
|
||||
}`,
|
||||
expErr: true,
|
||||
expErrStr: "Worker description contains non-printable characters",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Setenv("WORKER_DESCRIPTION", tt.envDescription)
|
||||
c, err := Parse(tt.in)
|
||||
if tt.expErr {
|
||||
require.EqualError(t, err, tt.expErrStr)
|
||||
require.Nil(t, c)
|
||||
return
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, c)
|
||||
require.NotNil(t, c.Worker)
|
||||
require.Equal(t, tt.expDescription, c.Worker.Description)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPluginExecutionDir(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in new issue
Block a user