Skip to content

Commit

Permalink
feat(export): Test case for unpack endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
dustmop committed Oct 10, 2018
1 parent 185c01a commit 54aa3ee
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@ func runHandlerTestCases(t *testing.T, name string, h http.HandlerFunc, cases []
}
}

// runHandlerZipPostTestCases executes a slice of handlerTestCase against a handler using zip content-type
func runHandlerZipPostTestCases(t *testing.T, name string, h http.HandlerFunc, cases []handlerTestCase) {
for i, c := range cases {
name := fmt.Sprintf("%s %s case %d: %s %s", t.Name(), name, i, c.method, c.endpoint)
req := httptest.NewRequest(c.method, c.endpoint, bytes.NewBuffer(c.body))
req.Header.Set("Content-Type", "application/zip")
w := httptest.NewRecorder()

h(w, req)

res := w.Result()
abide.AssertHTTPResponse(t, name, res)
}
}

// mustFile reads file bytes, calling t.Fatalf if the file doesn't exist
func mustFile(t *testing.T, filename string) []byte {
data, err := ioutil.ReadFile(filename)
Expand Down
8 changes: 8 additions & 0 deletions api/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ func TestDatasetHandlers(t *testing.T) {
}
runHandlerTestCases(t, "export", h.ZipDatasetHandler, exportCases)

// TODO: Perhaps add an option to runHandlerTestCases to set Content-Type, then combine
// `runHandlerZipPostTestCases` with `runHandlerTestCases`.
unpackCases := []handlerTestCase{
{"OPTIONS", "/", nil},
{"POST", "/unpack/", mustFile(t, "testdata/exported.zip")},
}
runHandlerZipPostTestCases(t, "unpack", h.UnpackHandler, unpackCases)

diffCases := []handlerTestCase{
{"OPTIONS", "/", nil},
{"GET", "/", mustFile(t, "testdata/diffRequest.json")},
Expand Down
Binary file modified api/testdata/api.snapshot
Binary file not shown.
Binary file added api/testdata/exported.zip
Binary file not shown.

0 comments on commit 54aa3ee

Please sign in to comment.