func TestFileActionsHandler(t *testing.T) { fileActions, _ := boxtools.GenerateSliceOfRandomFileActions(1, 1, 2) var bothfileActions []structs.FileAction for _, value := range fileActions { bothfileActions = append(bothfileActions, value) bothfileActions = append(bothfileActions, value) } jsonBytes, _ := json.Marshal(bothfileActions) resp, _ := http.Post( "http://localhost:8000/file-actions/?sessionKey="+client.SessionKey, "application/json", bytes.NewBuffer(jsonBytes), ) contents, _ := ioutil.ReadAll(resp.Body) if resp.StatusCode != http.StatusOK { fmt.Println(resp) t.Fail() } _ = contents // var responseSlice []string // json.Unmarshal(contents, &responseSlice) // if len(responseSlice) != 2 { // fmt.Println(len(responseSlice)) // fmt.Println(responseSlice) // t.Fail() // } }
func TestSendFileActionsToServer(t *testing.T) { fileActions, _ := boxtools.GenerateSliceOfRandomFileActions(1, 1, 1) var hashesToUpload []string var err error hashesToUpload, err = apiClient.SendFileActionsToServer(fileActions) if err != nil { t.Error(err) } if fileActions[0].File.Hash != hashesToUpload[0] { t.Error(fmt.Errorf("Wrong hash returned")) } }
func TestClientsFileActionsHandler(t *testing.T) { _, _ = boxtools.NewClient(user, "test", false) fileActions, _ := boxtools.GenerateSliceOfRandomFileActions(1, 1, 10) for _, value := range fileActions { model.DB.Create(&value) } resp, _ := http.PostForm( "http://localhost:8000/clients/", url.Values{ "sessionKey": {client.SessionKey}, "lastId": {"0"}, }, ) contents, _ := ioutil.ReadAll(resp.Body) if resp.StatusCode != 200 { t.Fail() } var incomingFileActions structs.ClientFileActionsResponse json.Unmarshal(contents, &incomingFileActions) if len(incomingFileActions.FileActions) != 10 { t.Fail() } }