Skip to content

Conversation

hiranya911
Copy link
Contributor

@hiranya911 hiranya911 commented May 29, 2018

The existing test suite is essentially one big test case composed of many helper functions. It also keeps a lot of intermediate state (fixtures), and tends to leave the Firebase project in an inconsistent state on failures. This PR:

  1. splits the test suite into multiple top-level test cases
  2. uses random user IDs in each test case to avoid keeping state, and prevent collisions between different runs
  3. uses the defer keyword to ensure graceful tear down

Resolves #145

}

func deleteUser(uid string) {
client.DeleteUser(context.Background(), uid)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we should at least check the error state and print out a warning or something.

I'm not sure if it would make sense, but we could maybe pass a *testing.T into this function and fail the test if the delete fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intended to be a best effort delete operation. I don't think we want to fail a test because the clean up operation failed. Added a comment stating this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think it would be good to print out a warning when it fails.

func randomString(length int) string {
b := make([]byte, length)
func randomUID() string {
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be const?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arrays cannot be const in Go.

}

func randomPhoneNumber() string {
var letters = []rune("0123456789")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would maybe name this digits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

func TestCustomTokenWithClaims(t *testing.T) {
ct, err := client.CustomTokenWithClaims(context.Background(), "user2", map[string]interface{}{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to use random UIDs on all these other tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@hiranya911 hiranya911 assigned hiranya911 and unassigned bklimt May 30, 2018
@hiranya911 hiranya911 merged commit 8721506 into dev May 30, 2018
@hiranya911 hiranya911 deleted the hkj-user-mgt branch May 30, 2018 22:25
hiranya911 added a commit that referenced this pull request Jun 12, 2018
* Adding new user mgt integ tests

* Reimplemented user mgt integ tests

* Fixed update test

* Minor updates for clarity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants