github.com/snyk/vervet/v6@v6.2.4/config/config_test.go (about) 1 package config_test 2 3 import ( 4 "bytes" 5 "testing" 6 7 qt "github.com/frankban/quicktest" 8 9 "github.com/snyk/vervet/v6/config" 10 ) 11 12 func TestLoad(t *testing.T) { 13 c := qt.New(t) 14 conf := bytes.NewBufferString(` 15 version: "1" 16 apis: 17 test: 18 resources: 19 - path: testdata/resources 20 excludes: 21 - testdata/resources/schemas/** 22 - path: testdata/resources 23 excludes: 24 - testdata/resources/schemas/** 25 overlays: 26 - inline: |- 27 servers: 28 - url: ${API_BASE_URL} 29 description: Test API 30 output: 31 path: testdata/output 32 `) 33 proj, err := config.Load(conf) 34 c.Assert(err, qt.IsNil) 35 c.Assert(proj, qt.DeepEquals, &config.Project{ 36 Version: "1", 37 Generators: config.Generators{}, 38 APIs: config.APIs{ 39 "test": { 40 Name: "test", 41 Resources: []*config.ResourceSet{{ 42 Path: "testdata/resources", 43 Excludes: []string{"testdata/resources/schemas/**"}, 44 }, { 45 Path: "testdata/resources", 46 Excludes: []string{"testdata/resources/schemas/**"}, 47 }}, 48 Overlays: []*config.Overlay{{ 49 Inline: ` 50 servers: 51 - url: ${API_BASE_URL} 52 description: Test API`[1:], 53 }}, 54 Output: &config.Output{ 55 Path: "testdata/output", 56 }, 57 }, 58 }, 59 }) 60 } 61 62 func TestLoadErrors(t *testing.T) { 63 c := qt.New(t) 64 tests := []struct { 65 conf string 66 err string 67 }{{ 68 conf: `version: "2"`, 69 err: `unsupported version "2"`, 70 }, { 71 conf: `version: "1"`, 72 err: `no apis defined`, 73 }, { 74 conf: ` 75 version: "1" 76 apis: 77 testapi: 78 resources: []`[1:], 79 err: `no resources defined \(apis\.testapi\.resources\)`, 80 }, { 81 conf: ` 82 version: "1" 83 apis: 84 testapi: 85 resources: 86 - path: resources 87 output: 88 path: /somewhere/else 89 paths: 90 - /another/place 91 - /and/another 92 `[1:], 93 err: `output should specify one of 'path' or 'paths', not both \(apis\.testapi\.output\)`, 94 }, { 95 err: `no apis defined`, 96 }} 97 for i := range tests { 98 c.Logf("test#%d: %s", i, tests[i].conf) 99 _, err := config.Load(bytes.NewBufferString(tests[i].conf)) 100 c.Assert(err, qt.ErrorMatches, tests[i].err) 101 } 102 }