|
1 | 1 | package jail |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "fmt" |
4 | 5 | "io/ioutil" |
| 6 | + "path/filepath" |
5 | 7 | "testing" |
6 | 8 |
|
7 | 9 | "github.com/stretchr/testify/assert" |
8 | 10 | ) |
9 | 11 |
|
10 | | -func TestRenderConfigBasic(t *testing.T) { |
11 | | - const ( |
12 | | - id = "basic" |
13 | | - path = "/tmp/test/basic/root" |
14 | | - ) |
15 | | - expected, err := ioutil.ReadFile("testdata/basic.conf") |
16 | | - assert.NoError(t, err, "test data") |
17 | | - actual, err := renderConfig(&Config{Name: id, Root: path}) |
18 | | - assert.NoError(t, err, "render") |
19 | | - assert.Equal(t, string(expected), actual) |
| 12 | +func TestRenderConfigGolden(t *testing.T) { |
| 13 | + tests := []struct { |
| 14 | + // name is both used as the subtest name and is the name of the golden data file in testdata |
| 15 | + name string |
| 16 | + config Config |
| 17 | + }{{ |
| 18 | + "basic", |
| 19 | + Config{ |
| 20 | + Name: "basic", |
| 21 | + Root: "/tmp/test/basic/root", |
| 22 | + }, |
| 23 | + }, { |
| 24 | + "hostname", |
| 25 | + Config{ |
| 26 | + Name: "hostname", |
| 27 | + Root: "/tmp/test/hostname/root", |
| 28 | + Hostname: "test.hostname.example.com", |
| 29 | + }, |
| 30 | + }} |
| 31 | + for _, tc := range tests { |
| 32 | + t.Run(tc.name, func(t *testing.T) { |
| 33 | + expected, err := ioutil.ReadFile(filepath.Join("testdata", fmt.Sprintf("%s.conf", tc.name))) |
| 34 | + assert.NoError(t, err, "test data") |
| 35 | + actual, err := renderConfig(&tc.config) |
| 36 | + assert.NoError(t, err, "render") |
| 37 | + assert.Equal(t, string(expected), actual) |
| 38 | + }) |
| 39 | + } |
20 | 40 | } |
0 commit comments