Add options support (#24)
<!-- 1. Did you add documentation? 2. Did you add tests? 3. Do you need to re-run formatting? 4. Do you need to re-run docs.go? --> Co-authored-by: jolheiser <john.olheiser@gmail.com> Reviewed-on: #24pull/26/head v0.3.0
parent
c348255c37
commit
d02502078f
@ -0,0 +1,17 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"go.jolheiser.com/tmpl/schema"
|
||||
|
||||
"github.com/matryer/is"
|
||||
)
|
||||
|
||||
func TestInitSchema(t *testing.T) {
|
||||
assert := is.New(t)
|
||||
|
||||
err := schema.Lint(strings.NewReader(initConfig))
|
||||
assert.NoErr(err) // Init config should conform to schema
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/matryer/is"
|
||||
)
|
||||
|
||||
//go:embed testdata
|
||||
var testdata embed.FS
|
||||
|
||||
func TestSchema(t *testing.T) {
|
||||
tt := []struct {
|
||||
Name string
|
||||
NumErr int
|
||||
}{
|
||||
{Name: "good", NumErr: 0},
|
||||
{Name: "bad", NumErr: 10},
|
||||
{Name: "empty", NumErr: 1},
|
||||
}
|
||||
|
||||
for _, tc := range tt {
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
assert := is.New(t)
|
||||
|
||||
fi, err := testdata.Open(fmt.Sprintf("testdata/%s.yaml", tc.Name))
|
||||
assert.NoErr(err) // Should open test file
|
||||
|
||||
err = Lint(fi)
|
||||
if tc.NumErr > 0 {
|
||||
var rerrs ResultErrors
|
||||
assert.True(errors.As(err, &rerrs)) // Error should be ResultErrors
|
||||
assert.True(len(rerrs) == tc.NumErr) // Number of errors should match test case
|
||||
} else {
|
||||
assert.NoErr(err) // Good schemas shouldn't return errors
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
prompts:
|
||||
- label: Bar
|
||||
default: baz
|
||||
help: |
|
||||
This is a foobar!
|
||||
options:
|
||||
- "1"
|
||||
- bonk
|
||||
- "false"
|
||||
- id: test
|
||||
label: 1234
|
||||
- id: test123
|
||||
options: []
|
||||
- label: 1234
|
||||
default: false
|
||||
help: # nil
|
||||
options:
|
||||
- 1
|
||||
- 2
|
||||
- true
|
@ -0,0 +1,10 @@
|
||||
prompts:
|
||||
- id: foo
|
||||
label: Bar
|
||||
default: baz
|
||||
help: |
|
||||
This is a foobar!
|
||||
options:
|
||||
- "1"
|
||||
- bonk
|
||||
- "false"
|
Loading…
Reference in New Issue