github.com/joshdk/godel@v0.0.0-20170529232908-862138a45aee/apps/gonform/config/config_test.go (about) 1 // Copyright 2016 Palantir Technologies, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package config_test 16 17 import ( 18 "strings" 19 "testing" 20 21 "github.com/palantir/pkg/matcher" 22 "github.com/stretchr/testify/assert" 23 "github.com/stretchr/testify/require" 24 25 "github.com/palantir/godel/apps/gonform/config" 26 ) 27 28 func TestLoad(t *testing.T) { 29 for i, currCase := range []struct { 30 yml string 31 json string 32 want func() config.Gonform 33 }{ 34 { 35 yml: ` 36 formatters: 37 gofmt: 38 args: 39 - "-s" 40 exclude: 41 names: 42 - ".*test" 43 - "m?cks" 44 paths: 45 - "vendor" 46 `, 47 json: `{"exclude":{"names":["gonform"],"paths":["generated_src"]}}`, 48 want: func() config.Gonform { 49 return config.Gonform{ 50 Formatters: map[string]config.Formatter{ 51 "gofmt": { 52 Args: []string{ 53 "-s", 54 }, 55 }, 56 }, 57 Exclude: matcher.NamesPathsCfg{ 58 Names: []string{`.*test`, `m?cks`, `gonform`}, 59 Paths: []string{`vendor`, `generated_src`}, 60 }, 61 } 62 }, 63 }, 64 } { 65 got, err := config.LoadRawConfig(unindent(currCase.yml), currCase.json) 66 require.NoError(t, err, "Case %d", i) 67 assert.Equal(t, currCase.want(), got, "Case %d", i) 68 } 69 } 70 71 func unindent(input string) string { 72 return strings.Replace(input, "\n\t\t\t", "\n", -1) 73 }