github.com/jdhenke/godel@v0.0.0-20161213181855-abeb3861bf0d/apps/gunit/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 "fmt" 19 "strings" 20 "testing" 21 22 "github.com/palantir/pkg/matcher" 23 "github.com/stretchr/testify/assert" 24 "github.com/stretchr/testify/require" 25 26 "github.com/palantir/godel/apps/gunit/config" 27 ) 28 29 func TestLoadConfig(t *testing.T) { 30 for i, currCase := range []struct { 31 yml string 32 json string 33 want func() config.GUnit 34 }{ 35 { 36 yml: ` 37 tags: 38 integration: 39 names: 40 - "integration_tests" 41 paths: 42 - "test" 43 exclude: 44 names: 45 - ".*test" 46 - "m?cks" 47 paths: 48 - "vendor" 49 `, 50 json: `{"exclude":{"names":["gunit"],"paths":["generated_src"]}}`, 51 want: func() config.GUnit { 52 return config.GUnit{ 53 Tags: map[string]matcher.NamesPathsCfg{ 54 "integration": { 55 Names: []string{`integration_tests`}, 56 Paths: []string{`test`}, 57 }, 58 }, 59 Exclude: matcher.NamesPathsCfg{ 60 Names: []string{`.*test`, `m?cks`, `gunit`}, 61 Paths: []string{`vendor`, `generated_src`}, 62 }, 63 } 64 }, 65 }, 66 } { 67 got, err := config.LoadRawConfig(unindent(currCase.yml), currCase.json) 68 require.NoError(t, err, "Case %d", i) 69 p := got.ToParams() 70 err = p.Validate() 71 require.NoError(t, err, "Case %d", i) 72 assert.Equal(t, currCase.want(), got, "Case %d", i) 73 } 74 } 75 76 func TestLoadInvalidConfig(t *testing.T) { 77 for i, currCase := range []struct { 78 yml string 79 wantError string 80 }{ 81 { 82 yml: ` 83 tags: 84 integration: 85 names: 86 - "integration_tests" 87 foo-bar: 88 paths: 89 - "foo-bar" 90 foo_bar: 91 names: 92 - "foo_bar" 93 "invalid,entry": 94 names: 95 - "invalid" 96 "another bad": 97 names: 98 - "another bad" 99 `, 100 wantError: "invalid tag names: [another bad invalid,entry]", 101 }, 102 } { 103 got, err := config.LoadRawConfig(unindent(currCase.yml), "") 104 require.NoError(t, err, fmt.Sprintf("Case %d", i)) 105 p := got.ToParams() 106 err = p.Validate() 107 require.Error(t, err, fmt.Sprintf("Case %d", i)) 108 assert.Equal(t, currCase.wantError, err.Error(), "Case %d", i) 109 } 110 } 111 112 func unindent(input string) string { 113 return strings.Replace(input, "\n\t\t\t", "\n", -1) 114 }