...
1 package main
2
3 import (
4 "bytes"
5 "strings"
6 "testing"
7
8 "github.com/stretchr/testify/assert"
9 "github.com/stretchr/testify/require"
10 )
11
12 func TestConvert(t *testing.T) {
13 examples := []struct {
14 name string
15 input string
16 expected string
17 errors bool
18 }{
19 {
20 name: "valid json",
21 input: `
22 {
23 "mytoml": {
24 "a": 42
25 }
26 }`,
27 expected: `[mytoml]
28 a = 42.0
29 `,
30 },
31 {
32 name: "invalid json",
33 input: `{ foo`,
34 errors: true,
35 },
36 }
37
38 for _, e := range examples {
39 b := new(bytes.Buffer)
40 err := convert(strings.NewReader(e.input), b)
41 if e.errors {
42 require.Error(t, err)
43 } else {
44 assert.NoError(t, err)
45 assert.Equal(t, e.expected, b.String())
46 }
47 }
48 }
49
View as plain text