Skip to content

Commit

Permalink
delete tests
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeweb committed Dec 5, 2016
1 parent 1bbdf14 commit 115a403
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions adapters/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,11 @@ func TestInsert(t *testing.T) {
So(len(json), ShouldBeGreaterThan, 0)
})
}

func TestDelete(t *testing.T) {
Convey("Delete data from table", t, func() {
json, err := Delete("prest", "public", "test", "name='nuveo'")
So(err, ShouldBeNil)
So(len(json), ShouldBeGreaterThan, 0)
})
}
13 changes: 13 additions & 0 deletions controllers/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,16 @@ func TestInsertInTables(t *testing.T) {
doValidPostRequest(server.URL+"/prest/public/test", r)
})
}

func TestDeleteFromTable(t *testing.T) {
router := mux.NewRouter()
router.HandleFunc("/{database}/{schema}/{table}", DeleteFromTable).Methods("DELETE")
server := httptest.NewServer(router)
defer server.Close()
Convey("excute delete in a table without where clause", t, func() {
doValidDeleteRequest(server.URL + "/prest/public/test")
})
Convey("excute delete in a table with where clause", t, func() {
doValidDeleteRequest(server.URL + "/prest/public/test?name=nuveo")
})
}
11 changes: 11 additions & 0 deletions controllers/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,14 @@ func doValidPostRequest(url string, r api.Request) {
_, err = ioutil.ReadAll(resp.Body)
So(err, ShouldBeNil)
}

func doValidDeleteRequest(url string) {
req, err := http.NewRequest("DELETE", url, nil)
So(err, ShouldBeNil)
client := &http.Client{}
resp, err := client.Do(req)
So(err, ShouldBeNil)
So(resp.StatusCode, ShouldEqual, 200)
_, err = ioutil.ReadAll(resp.Body)
So(err, ShouldBeNil)
}

0 comments on commit 115a403

Please sign in to comment.