-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support AND and OR queries with a more programmer friendly API
- Loading branch information
Showing
2 changed files
with
73 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package record | ||
|
||
import ( | ||
"encoding/json" | ||
_ "fmt" | ||
_ "regexp" | ||
"testing" | ||
) | ||
|
||
func TestListQuery(t *testing.T) { | ||
qt := QueryTerm{ | ||
Path: "foo", | ||
Op: Equal, | ||
Value: "a", | ||
} | ||
p := qt.asUrlQuery() | ||
exp := "foo%3Aa" | ||
if exp != p { | ||
t.Errorf("expected '%s', but got '%s'", exp, p) | ||
} | ||
} | ||
|
||
func TestListQuery2(t *testing.T) { | ||
qt := QueryTerm{ | ||
Path: "foo", | ||
Op: Equal, | ||
Value: "a:b", | ||
} | ||
p := qt.asUrlQuery() | ||
exp := "foo%3Aa%253Ab" | ||
if exp != p { | ||
t.Errorf("expected '%s', but got '%s'", exp, p) | ||
} | ||
} | ||
|
||
func TestListQueryJson(t *testing.T) { | ||
j := `{ | ||
"path": "asp.foo", | ||
"op": "=", | ||
"value": "a:b" | ||
}` | ||
qt := QueryTerm{} | ||
err := json.Unmarshal([]byte(j), &qt) | ||
if err != nil { | ||
t.Errorf("while unmarshal query - %v", err) | ||
return | ||
} | ||
|
||
p := qt.asUrlQuery() | ||
exp := "asp.foo%3Aa%253Ab" | ||
if exp != p { | ||
t.Errorf("expected '%s', but got '%s'", exp, p) | ||
} | ||
} |