Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
labkode committed May 8, 2016
1 parent 95f6f02 commit 362b9f4
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@ import (
"github.com/stretchr/testify/require"
)

const (
initURL = defaultMetaDataBaseURL + "init"
examineURL = defaultMetaDataBaseURL + "examine/"
listURL = defaultMetaDataBaseURL + "list/"
deleteURL = defaultMetaDataBaseURL + "delete/"
moveURL = defaultMetaDataBaseURL + "move/"
)

func (suite *TestSuite) TestInit() {
suite.Router.HandleFunc(defaultMetaDataBaseURL+"init", func(w http.ResponseWriter, r *http.Request) {
suite.Router.HandleFunc(initURL, func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
})
resp, err := suite.SDK.Meta.Init()
require.Nil(suite.T(), err)
require.Equal(suite.T(), http.StatusOK, resp.StatusCode)
}
func (suite *TestSuite) TestInit_withError() {
suite.Router.HandleFunc(defaultMetaDataBaseURL+"init", func(w http.ResponseWriter, r *http.Request) {
suite.Router.HandleFunc(initURL, func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(400)
fmt.Fprint(w, `{"code":99, "message":""}`)
})
Expand All @@ -27,7 +35,7 @@ func (suite *TestSuite) TestInit_withError() {
}

func (suite *TestSuite) TestExamineObject() {
suite.Router.HandleFunc(defaultMetaDataBaseURL+"examine/myblob", func(w http.ResponseWriter, r *http.Request) {
suite.Router.HandleFunc(examineURL+"myblob", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
fmt.Fprint(w, `{"pathspec":"myblob", "size": 100, "type": 1, "mime": "", "checksum": ""}`)
})
Expand All @@ -41,7 +49,7 @@ func (suite *TestSuite) TestExamineObject() {
require.Equal(suite.T(), "", info.Checksum)
}
func (suite *TestSuite) TestExamineObject_withError() {
suite.Router.HandleFunc(defaultMetaDataBaseURL+"examine/myblob", func(w http.ResponseWriter, r *http.Request) {
suite.Router.HandleFunc(examineURL+"myblob", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(400)
fmt.Fprint(w, `{"code":99, "message":""}`)
})
Expand All @@ -51,7 +59,7 @@ func (suite *TestSuite) TestExamineObject_withError() {
}

func (suite *TestSuite) TestListTree() {
suite.Router.HandleFunc(defaultMetaDataBaseURL+"listtree/tree", func(w http.ResponseWriter, r *http.Request) {
suite.Router.HandleFunc(listURL+"tree", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
fmt.Fprint(w, `[{"pathspec":"myblob", "size": 100, "type": 1, "mime": "", "checksum": ""}]`)
})
Expand All @@ -61,7 +69,7 @@ func (suite *TestSuite) TestListTree() {
require.Equal(suite.T(), 1, len(infos))
}
func (suite *TestSuite) TestListTree_withError() {
suite.Router.HandleFunc(defaultMetaDataBaseURL+"listtree/tree", func(w http.ResponseWriter, r *http.Request) {
suite.Router.HandleFunc(listURL+"tree", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(400)
fmt.Fprint(w, `{"code":99, "message":""}`)
})
Expand All @@ -70,31 +78,31 @@ func (suite *TestSuite) TestListTree_withError() {
require.Equal(suite.T(), http.StatusBadRequest, resp.StatusCode)
}
func (suite *TestSuite) TestDeleteObject() {
suite.Router.HandleFunc(defaultMetaDataBaseURL+"delete/tree", func(w http.ResponseWriter, r *http.Request) {
suite.Router.HandleFunc(deleteURL+"tree", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
})
resp, err := suite.SDK.Meta.DeleteObject("tree")
require.Nil(suite.T(), err)
require.Equal(suite.T(), http.StatusOK, resp.StatusCode)
}
func (suite *TestSuite) TestDeleteObject_withError() {
suite.Router.HandleFunc(defaultMetaDataBaseURL+"delete/tree", func(w http.ResponseWriter, r *http.Request) {
suite.Router.HandleFunc(deleteURL+"tree", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
})
resp, err := suite.SDK.Meta.DeleteObject("tree")
require.NotNil(suite.T(), err)
require.Equal(suite.T(), http.StatusInternalServerError, resp.StatusCode)
}
func (suite *TestSuite) TestMoveObject() {
suite.Router.HandleFunc(defaultMetaDataBaseURL+"move/tree", func(w http.ResponseWriter, r *http.Request) {
suite.Router.HandleFunc(moveURL+"tree", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
})
resp, err := suite.SDK.Meta.MoveObject("tree", "newtree")
require.Nil(suite.T(), err)
require.Equal(suite.T(), http.StatusOK, resp.StatusCode)
}
func (suite *TestSuite) TestMoveObject_withError() {
suite.Router.HandleFunc(defaultMetaDataBaseURL+"move/tree", func(w http.ResponseWriter, r *http.Request) {
suite.Router.HandleFunc(moveURL+"tree", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
})
resp, err := suite.SDK.Meta.MoveObject("tree", "newtree")
Expand Down

0 comments on commit 362b9f4

Please sign in to comment.