Example #1
0
func TestGetUserById(t *testing.T) {
	storages, err := storage.NewTestStorages()
	if err != nil {
		t.Fatalf("Creating storages should not fail. Error: %v", err)
	}

	u, err := NewUser(storages, "*****@*****.**", "password", "password")
	if err != nil {
		t.Errorf("Creating user should not fail. Error: %v", err)
	}

	err = u.Save()
	if err != nil {
		t.Fatalf("Saving user should work because Name and Password is not empty.")
	}

	userFromStorage, err := GetUserById(storages, u.ID)
	if err != nil {
		t.Fatalf("Getting user should work. Error: %v", err)
	}

	if u.ID != userFromStorage.ID {
		t.Error("Got the wrong user.")
	}
	if u.Email != userFromStorage.Email {
		t.Error("Got the wrong user.")
	}
	if u.Password != userFromStorage.Password {
		t.Error("Got the wrong user.")
	}

	storages.RemoveAll()
}
Example #2
0
func TestNewUser(t *testing.T) {
	storages, err := storage.NewTestStorages()
	if err != nil {
		t.Fatalf("Creating storages should not fail. Error: %v", err)
	}

	u, err := NewUser(storages, "*****@*****.**", "password", "password")
	if err != nil {
		t.Errorf("Creating user should not fail. Error: %v", err)
	}
	if u == nil {
		t.Error("Creating user should not fail.")
	}
	if u.storages == nil {
		t.Error("storages should not be empty.")
	}
	if u.bucketName == "" {
		t.Error("bucketName should not be empty.")
	}
	if u.ID == "" {
		t.Error("User ID should not be empty.")
	}

	err = storages.RemoveAll()
	if err != nil {
		t.Fatalf("Wiping storage should work. Error: %v", err)
	}
}
Example #3
0
func TestHashedPassword(t *testing.T) {
	storages, err := storage.NewTestStorages()
	if err != nil {
		t.Fatalf("Creating storages should not fail. Error: %v", err)
	}

	u, err := NewUser(storages, "*****@*****.**", "password", "password")
	if err != nil {
		t.Errorf("Creating user should not fail. Error: %v", err)
	}

	if u.Password == "password" {
		t.Fatal("Hashing password should work.")
	}

	storages.RemoveAll()
}
Example #4
0
func TestUserSave(t *testing.T) {
	storages, err := storage.NewTestStorages()
	if err != nil {
		t.Fatalf("Creating storages should not fail. Error: %v", err)
	}

	u, err := NewUser(storages, "*****@*****.**", "password", "password")
	if err != nil {
		t.Errorf("Creating user should not fail. Error: %v", err)
	}

	err = u.Save()
	if err != nil {
		t.Fatalf("Saving user should work because Email and Password is not empty.")
	}

	storages.RemoveAll()
}
Example #5
0
func TestValidateBeforeSave(t *testing.T) {
	storages, err := storage.NewTestStorages()
	if err != nil {
		t.Fatalf("Creating storages should not fail. Error: %v", err)
	}

	u, err := NewUser(storages, "*****@*****.**", "password", "password")
	if err != nil {
		t.Errorf("Creating user should not fail. Error: %v", err)
	}

	err = u.ValidateBeforeSave()
	if err != nil {
		t.Fatalf("Validation should pass because Email or Password is not empty. Error: %v", err)
	}

	storages.RemoveAll()
}
Example #6
0
func TestCreateAndDeleteUserAlbums(t *testing.T) {
	storages, err := storage.NewTestStorages()
	if err != nil {
		t.Fatalf("Creating storages should not fail. Error: %v", err)
	}

	u, err := NewUser(storages, "*****@*****.**", "password", "password")
	if err != nil {
		t.Errorf("Creating user should not fail. Error: %v", err)
	}

	err = u.CreateAlbum("programming")
	if err != nil {
		t.Errorf("Creating a album should not fail. Error: %v", err)
	}

	album := u.GetAlbumByName("programming")
	if album == nil {
		t.Error("Album 'programming' should exist.")
	}

	err = u.DeleteAlbum("programming")
	if err != nil {
		t.Errorf("Deleting a album should not fail. Error: %v", err)
	}

	err = u.DeleteAlbum("aaa")
	if err != nil {
		t.Errorf("Deleting non-existing album should not fail. Error: %v", err)
	}

	err = storages.RemoveAll()
	if err != nil {
		t.Errorf("Remove all storage failed. Error: %v", err)
	}
}