...

Source file src/github.com/peterbourgon/ff/v3/json_test.go

Documentation: github.com/peterbourgon/ff/v3

     1  package ff_test
     2  
     3  import (
     4  	"io"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/peterbourgon/ff/v3"
     9  	"github.com/peterbourgon/ff/v3/fftest"
    10  )
    11  
    12  func TestJSONParser(t *testing.T) {
    13  	t.Parallel()
    14  
    15  	for _, testcase := range []struct {
    16  		name string
    17  		args []string
    18  		file string
    19  		want fftest.Vars
    20  	}{
    21  		{
    22  			name: "empty input",
    23  			args: []string{},
    24  			file: "testdata/empty.json",
    25  			want: fftest.Vars{},
    26  		},
    27  		{
    28  			name: "basic KV pairs",
    29  			args: []string{},
    30  			file: "testdata/basic.json",
    31  			want: fftest.Vars{S: "s", I: 10, B: true, D: 5 * time.Second},
    32  		},
    33  		{
    34  			name: "value arrays",
    35  			args: []string{},
    36  			file: "testdata/value_arrays.json",
    37  			want: fftest.Vars{S: "bb", I: 12, B: true, D: 5 * time.Second, X: []string{"a", "B", "👍"}},
    38  		},
    39  		{
    40  			name: "bad JSON file",
    41  			args: []string{},
    42  			file: "testdata/bad.json",
    43  			want: fftest.Vars{WantParseErrorIs: io.ErrUnexpectedEOF},
    44  		},
    45  	} {
    46  		t.Run(testcase.name, func(t *testing.T) {
    47  			fs, vars := fftest.Pair()
    48  			vars.ParseError = ff.Parse(fs, testcase.args,
    49  				ff.WithConfigFile(testcase.file),
    50  				ff.WithConfigFileParser(ff.JSONParser),
    51  			)
    52  			fftest.Compare(t, &testcase.want, vars)
    53  		})
    54  	}
    55  }
    56  

View as plain text