Exemplo n.º 1
0
func TestReadJSON(t *testing.T) {
	for _, test := range readTests {
		qr := NewReader(strings.NewReader(test.input))
		got, err := quad.ReadAll(qr)
		qr.Close()
		if fmt.Sprint(err) != fmt.Sprint(test.err) {
			t.Errorf("Failed to %v with unexpected error, got:%v expected %v", test.message, err, test.err)
		}
		if !reflect.DeepEqual(got, test.expect) {
			t.Errorf("Failed to %v, got:%v expect:%v", test.message, got, test.expect)
		}
	}
}
Exemplo n.º 2
0
func TestRead(t *testing.T) {
	for i, c := range testReadCases {
		r := NewReader(strings.NewReader(c.data))
		quads, err := quad.ReadAll(r)
		if err != nil {
			t.Errorf("case %d failed: %v", i, err)
		}
		sort.Sort(ByQuad(quads))
		sort.Sort(ByQuad(c.expect))
		if !reflect.DeepEqual(quads, c.expect) {
			for _, q := range quads {
				t.Errorf("%+v (%T %T %T %T)", q, q.Subject, q.Predicate, q.Object, q.Label)
			}
			t.Errorf("case %d failed: wrong quads returned:\n%v\n%v", i, quads, c.expect)
		}
		r.Close()
	}
}
Exemplo n.º 3
0
func (api *API) ServeV1Delete(w http.ResponseWriter, r *http.Request, params httprouter.Params) int {
	if api.config.ReadOnly {
		return jsonResponse(w, 400, "Database is read-only.")
	}
	qr := quadReaderFromRequest(r)
	quads, err := quad.ReadAll(qr)
	qr.Close()
	if err != nil {
		return jsonResponse(w, 400, err)
	}
	h, err := api.GetHandleForRequest(r)
	if err != nil {
		return jsonResponse(w, 400, err)
	}
	count := 0
	for _, q := range quads {
		h.QuadWriter.RemoveQuad(q)
		count++
	}
	fmt.Fprintf(w, "{\"result\": \"Successfully deleted %d quads.\"}", count)
	return 200
}