Commit 81f36df9 authored by Taylor Gerring's avatar Taylor Gerring

CompileArgs

parent ddcc8e16
...@@ -617,14 +617,18 @@ type CompileArgs struct { ...@@ -617,14 +617,18 @@ type CompileArgs struct {
func (args *CompileArgs) UnmarshalJSON(b []byte) (err error) { func (args *CompileArgs) UnmarshalJSON(b []byte) (err error) {
var obj []interface{} var obj []interface{}
r := bytes.NewReader(b) if err := json.Unmarshal(b, &obj); err != nil {
if err := json.NewDecoder(r).Decode(&obj); err != nil {
return NewDecodeParamError(err.Error()) return NewDecodeParamError(err.Error())
} }
if len(obj) > 0 { if len(obj) < 1 {
args.Source = obj[0].(string) return NewInsufficientParamsError(len(obj), 1)
}
argstr, ok := obj[0].(string)
if !ok {
return NewInvalidTypeError("arg0", "is not a string")
} }
args.Source = argstr
return nil return nil
} }
......
...@@ -1126,6 +1126,36 @@ func TestCompileArgs(t *testing.T) { ...@@ -1126,6 +1126,36 @@ func TestCompileArgs(t *testing.T) {
} }
} }
func TestCompileArgsInvalid(t *testing.T) {
input := `{}`
args := new(CompileArgs)
str := ExpectDecodeParamError(json.Unmarshal([]byte(input), args))
if len(str) > 0 {
t.Error(str)
}
}
func TestCompileArgsEmpty(t *testing.T) {
input := `[]`
args := new(CompileArgs)
str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), args))
if len(str) > 0 {
t.Error(str)
}
}
func TestCompileArgsBool(t *testing.T) {
input := `[false]`
args := new(CompileArgs)
str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), args))
if len(str) > 0 {
t.Error(str)
}
}
func TestFilterStringArgs(t *testing.T) { func TestFilterStringArgs(t *testing.T) {
input := `["pending"]` input := `["pending"]`
expected := new(FilterStringArgs) expected := new(FilterStringArgs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment