mirror of
https://github.com/rqlite/rqlite.git
synced 2026-01-25 04:16:26 +00:00
Fix unit tests
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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"}}},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user