|
|
|
|
@ -337,6 +337,292 @@ func TestParsingName(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestWorkerTags(t *testing.T) {
|
|
|
|
|
defaultStateFn := func(t *testing.T, tags string) {
|
|
|
|
|
t.Setenv("BOUNDARY_WORKER_TAGS", tags)
|
|
|
|
|
}
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
in string
|
|
|
|
|
stateFn func(t *testing.T, tags string)
|
|
|
|
|
actualTags string
|
|
|
|
|
expWorkerTags map[string][]string
|
|
|
|
|
expErr bool
|
|
|
|
|
expErrStr string
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
name: "tags in HCL",
|
|
|
|
|
in: `
|
|
|
|
|
worker {
|
|
|
|
|
tags {
|
|
|
|
|
type = ["dev", "local"]
|
|
|
|
|
typetwo = "devtwo"
|
|
|
|
|
}
|
|
|
|
|
}`,
|
|
|
|
|
expWorkerTags: map[string][]string{
|
|
|
|
|
"type": {"dev", "local"},
|
|
|
|
|
"typetwo": {"devtwo"},
|
|
|
|
|
},
|
|
|
|
|
expErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "tags in HCL key=value",
|
|
|
|
|
in: `
|
|
|
|
|
worker {
|
|
|
|
|
tags = ["type=dev", "type=local", "typetwo=devtwo"]
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
expWorkerTags: map[string][]string{
|
|
|
|
|
"type": {"dev", "local"},
|
|
|
|
|
"typetwo": {"devtwo"},
|
|
|
|
|
},
|
|
|
|
|
expErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "no tags",
|
|
|
|
|
in: `
|
|
|
|
|
worker {
|
|
|
|
|
name = "testworker"
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
expWorkerTags: nil,
|
|
|
|
|
expErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "empty tags",
|
|
|
|
|
in: `
|
|
|
|
|
worker {
|
|
|
|
|
name = "testworker"
|
|
|
|
|
tags = {}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
expWorkerTags: map[string][]string{},
|
|
|
|
|
expErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "empty tags 2",
|
|
|
|
|
in: `
|
|
|
|
|
worker {
|
|
|
|
|
name = "testworker"
|
|
|
|
|
tags = []
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
expWorkerTags: map[string][]string{},
|
|
|
|
|
expErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "empty str",
|
|
|
|
|
in: `
|
|
|
|
|
worker {
|
|
|
|
|
tags = ""
|
|
|
|
|
}`,
|
|
|
|
|
expWorkerTags: map[string][]string{},
|
|
|
|
|
expErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "empty env var",
|
|
|
|
|
in: `
|
|
|
|
|
worker {
|
|
|
|
|
tags = "env://BOUNDARY_WORKER_TAGS"
|
|
|
|
|
}`,
|
|
|
|
|
expWorkerTags: map[string][]string{},
|
|
|
|
|
expErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "not a url - entire tags block",
|
|
|
|
|
in: `
|
|
|
|
|
worker {
|
|
|
|
|
tags = "\x00"
|
|
|
|
|
}`,
|
|
|
|
|
expWorkerTags: map[string][]string{},
|
|
|
|
|
expErr: true,
|
|
|
|
|
expErrStr: `Error parsing worker tags: error parsing url ("parse \"\\x00\": net/url: invalid control character in URL"): not a url`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "not a url - key's value set to string",
|
|
|
|
|
in: `
|
|
|
|
|
worker {
|
|
|
|
|
tags {
|
|
|
|
|
type = "\x00"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
expWorkerTags: map[string][]string{
|
|
|
|
|
"type": {"\x00"},
|
|
|
|
|
},
|
|
|
|
|
expErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "one tag key",
|
|
|
|
|
in: `
|
|
|
|
|
worker {
|
|
|
|
|
tags = "env://BOUNDARY_WORKER_TAGS"
|
|
|
|
|
}`,
|
|
|
|
|
stateFn: defaultStateFn,
|
|
|
|
|
actualTags: `type = ["dev", "local"]`,
|
|
|
|
|
expWorkerTags: map[string][]string{
|
|
|
|
|
"type": {"dev", "local"},
|
|
|
|
|
},
|
|
|
|
|
expErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "multiple tag keys",
|
|
|
|
|
in: `
|
|
|
|
|
worker {
|
|
|
|
|
tags = "env://BOUNDARY_WORKER_TAGS"
|
|
|
|
|
}`,
|
|
|
|
|
stateFn: defaultStateFn,
|
|
|
|
|
actualTags: `
|
|
|
|
|
type = ["dev", "local"]
|
|
|
|
|
typetwo = ["devtwo", "localtwo"]
|
|
|
|
|
`,
|
|
|
|
|
expWorkerTags: map[string][]string{
|
|
|
|
|
"type": {"dev", "local"},
|
|
|
|
|
"typetwo": {"devtwo", "localtwo"},
|
|
|
|
|
},
|
|
|
|
|
expErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "json tags - entire tags block",
|
|
|
|
|
in: `
|
|
|
|
|
worker {
|
|
|
|
|
tags = "env://BOUNDARY_WORKER_TAGS"
|
|
|
|
|
}`,
|
|
|
|
|
stateFn: defaultStateFn,
|
|
|
|
|
actualTags: `
|
|
|
|
|
{
|
|
|
|
|
"type": ["dev", "local"],
|
|
|
|
|
"typetwo": ["devtwo", "localtwo"]
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
expWorkerTags: map[string][]string{
|
|
|
|
|
"type": {"dev", "local"},
|
|
|
|
|
"typetwo": {"devtwo", "localtwo"},
|
|
|
|
|
},
|
|
|
|
|
expErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "json tags - keys specified in the HCL file, values point to env/file",
|
|
|
|
|
in: `
|
|
|
|
|
worker {
|
|
|
|
|
tags = {
|
|
|
|
|
type = "env://BOUNDARY_WORKER_TAGS"
|
|
|
|
|
typetwo = "env://BOUNDARY_WORKER_TAGS_TWO"
|
|
|
|
|
}
|
|
|
|
|
}`,
|
|
|
|
|
stateFn: func(t *testing.T, tags string) {
|
|
|
|
|
defaultStateFn(t, tags)
|
|
|
|
|
t.Setenv("BOUNDARY_WORKER_TAGS_TWO", `["devtwo", "localtwo"]`)
|
|
|
|
|
},
|
|
|
|
|
actualTags: `["dev","local"]`,
|
|
|
|
|
expWorkerTags: map[string][]string{
|
|
|
|
|
"type": {"dev", "local"},
|
|
|
|
|
"typetwo": {"devtwo", "localtwo"},
|
|
|
|
|
},
|
|
|
|
|
expErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "json tags - mix n' match",
|
|
|
|
|
in: `
|
|
|
|
|
worker {
|
|
|
|
|
name = "web-prod-us-east-1"
|
|
|
|
|
tags {
|
|
|
|
|
type = "env://BOUNDARY_WORKER_TYPE_TAGS"
|
|
|
|
|
typetwo = "file://type_two_tags.json"
|
|
|
|
|
typethree = ["devthree", "localthree"]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
stateFn: func(t *testing.T, tags string) {
|
|
|
|
|
workerTypeTags := `["dev", "local"]`
|
|
|
|
|
t.Setenv("BOUNDARY_WORKER_TYPE_TAGS", workerTypeTags)
|
|
|
|
|
|
|
|
|
|
filepath := "./type_two_tags.json"
|
|
|
|
|
err := os.WriteFile(filepath, []byte(`["devtwo", "localtwo"]`), 0o666)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
err := os.Remove(filepath)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
expWorkerTags: map[string][]string{
|
|
|
|
|
"type": {"dev", "local"},
|
|
|
|
|
"typetwo": {"devtwo", "localtwo"},
|
|
|
|
|
"typethree": {"devthree", "localthree"},
|
|
|
|
|
},
|
|
|
|
|
expErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "bad json tags",
|
|
|
|
|
in: `
|
|
|
|
|
worker {
|
|
|
|
|
tags = {
|
|
|
|
|
type = "env://BOUNDARY_WORKER_TAGS"
|
|
|
|
|
typetwo = "env://BOUNDARY_WORKER_TAGS"
|
|
|
|
|
}
|
|
|
|
|
}`,
|
|
|
|
|
stateFn: defaultStateFn,
|
|
|
|
|
actualTags: `
|
|
|
|
|
{
|
|
|
|
|
"type": ["dev", "local"],
|
|
|
|
|
"typetwo": ["devtwo", "localtwo"]
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
expWorkerTags: nil,
|
|
|
|
|
expErr: true,
|
|
|
|
|
expErrStr: "Error unmarshalling env var/file contents: json: cannot unmarshal object into Go value of type []string",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "no clean mapping to internal structures",
|
|
|
|
|
in: `
|
|
|
|
|
worker {
|
|
|
|
|
tags = "env://BOUNDARY_WORKER_TAGS"
|
|
|
|
|
}`,
|
|
|
|
|
stateFn: defaultStateFn,
|
|
|
|
|
actualTags: `
|
|
|
|
|
worker {
|
|
|
|
|
tags {
|
|
|
|
|
type = "indeed"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
expErr: true,
|
|
|
|
|
expErrStr: "Error decoding the worker's tags: 1 error(s) decoding:\n\n* '[0][worker][0]' expected type 'string', got unconvertible type 'map[string]interface {}', value: 'map[tags:[map[type:indeed]]]'",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "not HCL",
|
|
|
|
|
in: `worker {
|
|
|
|
|
tags = "env://BOUNDARY_WORKER_TAGS"
|
|
|
|
|
}`,
|
|
|
|
|
stateFn: defaultStateFn,
|
|
|
|
|
actualTags: `not_hcl`,
|
|
|
|
|
expErr: true,
|
|
|
|
|
expErrStr: "Error decoding raw worker tags: At 1:9: key 'not_hcl' expected start of object ('{') or assignment ('=')",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
if tt.stateFn != nil {
|
|
|
|
|
tt.stateFn(t, tt.actualTags)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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.expWorkerTags, c.Worker.Tags)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestController_EventingConfig(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
|