Fix unit tests

This commit is contained in:
Philip O'Toole
2022-11-29 20:05:08 -05:00
parent b46d87363b
commit 1b9e8e097d
2 changed files with 16 additions and 10 deletions

View File

@@ -25,16 +25,14 @@ var (
type ConflictPolicy string
func (cp *ConflictPolicy) Unmarshal(b []byte) error {
func (cp *ConflictPolicy) UnmarshalJSON(b []byte) error {
var c string
if err := json.Unmarshal(b, &c); err != nil {
return err
}
cU := strings.ToUpper(c)
fmt.Println(">>>>>>>", c, cU)
if cU == "IGNORE" || cU == "REPLACE" || cU == "FAIL" {
*cp = ConflictPolicy(cU)
panic("XXXX")
return nil
}
return fmt.Errorf("invalid conflict")

View File

@@ -249,18 +249,26 @@ func Test_SingleInvalidParameterizedRequest(t *testing.T) {
}
}
func Test_ParseAssociativeRequest(t *testing.T) {
func Test_ParseAssociativeRequestOK(t *testing.T) {
tests := []struct {
j string
exp AssociativeRequest
}{
{
j: `{"table": "foo", "conflict": "ignore", "rows": [{"id": 1, "name": "fiona"}]}`,
exp: AssociativeRequest{
Table: "foo",
Conflict: "ignore",
Rows: []map[string]interface{}{{"id": 1, "name": "fiona"}},
},
j: `{"table": "foo", "conflict": "ignore", "rows": [{"name": "fiona"}]}`,
exp: AssociativeRequest{Table: "foo", Conflict: "IGNORE", Rows: []map[string]interface{}{{"name": "fiona"}}},
},
{
j: `{"table": "foo", "conflict": "fail", "rows": [{"name": "fiona"}]}`,
exp: AssociativeRequest{Table: "foo", Conflict: "FAIL", Rows: []map[string]interface{}{{"name": "fiona"}}},
},
{
j: `{"table": "foo", "conflict": "replace", "rows": [{"name": "fiona"}]}`,
exp: AssociativeRequest{Table: "foo", Conflict: "REPLACE", Rows: []map[string]interface{}{{"name": "fiona"}}},
},
{
j: `{"table": "foo", "conflict": "ignore", "rows": [{"first": "bob", "last": "smith"}]}`,
exp: AssociativeRequest{Table: "foo", Conflict: "IGNORE", Rows: []map[string]interface{}{{"first": "bob", "last": "smith"}}},
},
}