Ejemplo n.º 1
0
func TestCreateComment(t *testing.T) {
	tests.ResetLog()
	defer tests.DisplayLog()

	db := db.NewMGO()
	defer db.CloseMGO()

	var CommentID string
	defer func() {
		if err := removeComment(db, CommentID); err != nil {
			t.Fatalf("\t%s\tShould be able to remove the test comment : %v", tests.Failed, err)
		}
		t.Logf("\t%s\tShould be able to remove the test comment.", tests.Success)
	}()

	c1 := comment.Comment{
		UserId: "4",
		Body:   "Wonderful story!  The world is going in the right direction!",
	}

	if err := comment.CreateComment(tests.Context, db, &c1); err != nil {
		t.Fatalf("\t%s\tShould be able to create a comment : %v", tests.Failed, err)
	}
	t.Logf("\t%s\tShould be able to create a comment", tests.Success)

	CommentID = c1.CommentID

	t.Logf("\t%s\tYeah, ok, this works.", tests.Success)
}
Ejemplo n.º 2
0
func TestCreateUser(t *testing.T) {
	tests.ResetLog()
	defer tests.DisplayLog()

	db := db.NewMGO()
	defer db.CloseMGO()

	var ID string
	defer func() {
		if err := removeUser(db, ID); err != nil {
			t.Fatalf("\t%s\tShould be able to remove the test user : %v", tests.Failed, err)
		}
		t.Logf("\t%s\tShould be able to remove the test user.", tests.Success)
	}()

	u1 := comment.User{
		UserName: "******",
		Avatar:   "https://picture.of/david.jpg",
	}

	if err := comment.CreateUser(tests.Context, db, &u1); err != nil {
		t.Fatalf("\t%s\tShould be able to create a user : %v", tests.Failed, err)
	}
	t.Logf("\t%s\tShould be able to create a user", tests.Success)

	// set ID for the deferred removeUser method
	ID = u1.UserID

	if err := comment.CreateUser(tests.Context, db, &u1); err == nil {
		t.Fatalf("\t%s\tShould not be able to create a duplicate user", tests.Failed)
	}
	t.Logf("\t%s\tShould not be able to create a duplicate user", tests.Success)

}