Kong tag PR fixes (#12)
* Removed bubbling errors in favour of panic * Added a test for Parse with a bad build and an arg. * Removed is() function in favour of a switch with strings * Collect key and value in parseCSV, reducing complexity. * Fix in global to not use parser instance on error.
This commit is contained in:
committed by
Alec Thomas
parent
31e1ffaa3b
commit
ecd369e622
@@ -0,0 +1,31 @@
|
||||
package kong
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestParseHandlingBadBuild(t *testing.T) {
|
||||
var cli struct {
|
||||
Enabled bool `kong:"unknown"`
|
||||
}
|
||||
|
||||
args := os.Args
|
||||
defer func() {
|
||||
os.Args = args
|
||||
}()
|
||||
|
||||
os.Args = []string{os.Args[0], "hi"}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
require.Equal(t, Error{msg: "unknown is an unknown kong key"}, r)
|
||||
}
|
||||
}()
|
||||
|
||||
Parse(&cli, ExitFunction(func(_ int) { panic("exiting") }))
|
||||
|
||||
require.Fail(t, "we were expecting a panic")
|
||||
}
|
||||
Reference in New Issue
Block a user