Skip to content

Commit

Permalink
Add tag filtering unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0verbyte committed Sep 12, 2023
1 parent 02161e1 commit 326dcb3
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions internal/mold/mold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,88 @@ func TestTagsAll(t *testing.T) {
}
}
}

func TestTagFiltering(t *testing.T) {
var moldTemplate = `
- name: foo
value: "bar"
type: string
required: true
tags: ["test"]
- name: debug
value: true
type: boolean
required: false
tags:
- debug
- local
`

m, err := New(strings.NewReader(moldTemplate), &[]string{"test"})
if err != nil {
t.Errorf("Failed to create new mold: %v", err)
return
}

specs := []struct {
envVar string
err error
}{
{envVar: "foo", err: nil},
{envVar: "debug", err: ErrEnvironmentVariableDoesNotExist},
}

for _, spec := range specs {
if _, err := m.GetVariable(spec.envVar); err != spec.err {
t.Errorf("Expected %+v, got %+v", spec.err, err)
}
}
}

func TestMultiTagFiltering(t *testing.T) {
var moldTemplate = `
- name: foo
value: "bar"
type: string
required: true
tags: ["test"]
- name: debug
value: true
type: boolean
required: false
tags:
- debug
- local
- name: log_type
value: stdout
type: string
required: false
tags:
- staging
- local
`

m, err := New(strings.NewReader(moldTemplate), &[]string{"test", "debug"})
if err != nil {
t.Errorf("Failed to create new mold: %v", err)
return
}

specs := []struct {
envVar string
err error
}{
{envVar: "foo", err: nil},
{envVar: "debug", err: nil},
{envVar: "log_type", err: ErrEnvironmentVariableDoesNotExist},
}

for _, spec := range specs {
if _, err := m.GetVariable(spec.envVar); err != spec.err {
t.Errorf("Expected %+v, got %+v", spec.err, err)
}
}
}

0 comments on commit 326dcb3

Please sign in to comment.