Beispiel #1
0
func init() {
	model.DB, _ = gorm.Open("postgres", "dbname=goboxtest sslmode=disable")

	model.DB.DropTableIfExists(&structs.User{})
	model.DB.DropTableIfExists(&structs.Client{})
	model.DB.DropTableIfExists(&structs.FileAction{})
	model.DB.DropTableIfExists(&structs.File{})
	model.DB.DropTableIfExists(&structs.FileSystemFile{})
	model.DB.AutoMigrate(
		&structs.User{},
		&structs.Client{},
		&structs.FileAction{},
		&structs.File{},
		&structs.FileSystemFile{},
	)

	user, _ = boxtools.NewUser("max.t.mcdonnell@gmail", "password")

	var err error
	client, err = boxtools.NewClient(user, "test", false)
	if err != nil {
		fmt.Println(err)
	}

	go ServeServerRoutes("8000")
}
Beispiel #2
0
func LoginHandler(w http.ResponseWriter, req *http.Request) {
	httpError := httpError{responseWriter: w}
	httpError.code = http.StatusInternalServerError

	var user structs.User
	model.DB.First(&user)
	client, err := boxtools.NewClient(user, "stephen", false)
	httpError.err = err
	if httpError.check() {
		return
	}

	w.Write([]byte(client.SessionKey))
}
Beispiel #3
0
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()
	}
}