|
| 1 | +package vars |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | +) |
| 8 | + |
| 9 | +func TestVarsProcess(t *testing.T) { |
| 10 | + t.Parallel() |
| 11 | + |
| 12 | + tests := []struct { |
| 13 | + name string |
| 14 | + vars map[string]string |
| 15 | + input string |
| 16 | + contains []string |
| 17 | + excludes []string |
| 18 | + }{ |
| 19 | + { |
| 20 | + name: "replaces known vars", |
| 21 | + vars: map[string]string{"ID": "af248b4b-a0e1-4e0f-94c6-4f0b4e0c7c42"}, |
| 22 | + input: "curl http://do.the.thing/pie/{{.ID}}", |
| 23 | + contains: []string{"af248b4b-a0e1-4e0f-94c6-4f0b4e0c7c42"}, |
| 24 | + excludes: []string{"{{.ID}}"}, |
| 25 | + }, |
| 26 | + { |
| 27 | + name: "leaves unknown vars untouched", |
| 28 | + vars: map[string]string{"ID": "af248b4b-a0e1-4e0f-94c6-4f0b4e0c7c42"}, |
| 29 | + input: "curl http://do.the.thing/pie/{{.ID}}/{{.Subid}}", |
| 30 | + contains: []string{"af248b4b-a0e1-4e0f-94c6-4f0b4e0c7c42", "{{.Subid}}"}, |
| 31 | + excludes: []string{"{{.ID}}"}, |
| 32 | + }, |
| 33 | + } |
| 34 | + |
| 35 | + for _, tt := range tests { |
| 36 | + tt := tt |
| 37 | + t.Run(tt.name, func(t *testing.T) { |
| 38 | + t.Parallel() |
| 39 | + |
| 40 | + v := Vars(tt.vars) |
| 41 | + out := v.Process(tt.input) |
| 42 | + |
| 43 | + for _, s := range tt.contains { |
| 44 | + assert.Contains(t, out, s) |
| 45 | + } |
| 46 | + for _, s := range tt.excludes { |
| 47 | + assert.NotContains(t, out, s) |
| 48 | + } |
| 49 | + }) |
| 50 | + } |
| 51 | +} |
0 commit comments