Esempio n. 1
0
// Ensure that creating the same user twice returns an error.
func TestData_CreateUser_ErrUserExists(t *testing.T) {
	var data meta.Data
	if err := data.CreateUser("susy", "", false); err != nil {
		t.Fatal(err)
	}
	if err := data.CreateUser("susy", "", false); err != meta.ErrUserExists {
		t.Fatal(err)
	}
}
Esempio n. 2
0
// Ensure a user can be created.
func TestData_CreateUser(t *testing.T) {
	var data meta.Data
	if err := data.CreateUser("susy", "ABC123", true); err != nil {
		t.Fatal(err)
	} else if !reflect.DeepEqual(data.Users, []meta.UserInfo{
		{Name: "susy", Hash: "ABC123", Admin: true},
	}) {
		t.Fatalf("unexpected users: %#v", data.Users)
	}
}
Esempio n. 3
0
// Ensure a user can be updated.
func TestData_UpdateUser(t *testing.T) {
	var data meta.Data
	if err := data.CreateUser("susy", "", false); err != nil {
		t.Fatal(err)
	} else if err := data.CreateUser("bob", "", false); err != nil {
		t.Fatal(err)
	}

	// Update password hash.
	if err := data.UpdateUser("bob", "XXX"); err != nil {
		t.Fatal(err)
	} else if !reflect.DeepEqual(data.User("bob"), &meta.UserInfo{Name: "bob", Hash: "XXX"}) {
		t.Fatalf("unexpected user: %#v", data.User("bob"))
	}
}
Esempio n. 4
0
// Ensure a user can be removed.
func TestData_DropUser(t *testing.T) {
	var data meta.Data
	if err := data.CreateUser("susy", "", false); err != nil {
		t.Fatal(err)
	} else if err := data.CreateUser("bob", "", false); err != nil {
		t.Fatal(err)
	}

	if err := data.DropUser("bob"); err != nil {
		t.Fatal(err)
	} else if !reflect.DeepEqual(data.Users, []meta.UserInfo{
		{Name: "susy"},
	}) {
		t.Fatalf("unexpected users: %#v", data.Users)
	}
}
Esempio n. 5
0
// Ensure that creating a user with no username returns an error.
func TestData_CreateUser_ErrUsernameRequired(t *testing.T) {
	var data meta.Data
	if err := data.CreateUser("", "", false); err != meta.ErrUsernameRequired {
		t.Fatal(err)
	}
}