Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link roles to users in user service #86

Merged
merged 9 commits into from
Oct 10, 2020

Conversation

codegold79
Copy link
Collaborator

@codegold79 codegold79 commented Jun 5, 2020

Closes #79

Changes

  • update migration to include user_role join table
  • update user query to pull in role information

Todo

  • add roles for every user added
  • update db.Prepare() queries ot use db.Query()

@codegold79 codegold79 self-assigned this Jun 5, 2020
Signed-off-by: codegold79 <codegold79@gmail.com>
Signed-off-by: codegold79 <codegold79@gmail.com>
Signed-off-by: codegold79 <codegold79@gmail.com>
Signed-off-by: codegold79 <codegold79@gmail.com>
@codegold79 codegold79 force-pushed the Link-roles-to-users-in-User-Service branch from 5056aca to c25d599 Compare July 14, 2020 05:26
Signed-off-by: codegold79 <codegold79@gmail.com>
Signed-off-by: codegold79 <codegold79@gmail.com>
@codegold79 codegold79 changed the title WIP: Link roles to users in user service Link roles to users in user service Jul 23, 2020
@codegold79 codegold79 changed the title Link roles to users in user service WIP: Link roles to users in user service Aug 11, 2020
Signed-off-by: codegold79 <codegold79@gmail.com>
Signed-off-by: codegold79 <codegold79@gmail.com>
@codegold79 codegold79 changed the title WIP: Link roles to users in user service Link roles to users in user service Aug 27, 2020
@codegold79 codegold79 requested a review from daved August 27, 2020 03:56
@daved
Copy link
Member

daved commented Sep 10, 2020

@codegold79 Are the TODOs either covered here or by new issues?

got.Roles[i].Id = ""
got.Roles[i].XXX_unrecognized = []byte{}
got.Roles[i].XXX_sizecache = 0
unsetUntestedFields(got.Roles[i])
}

if reflect.DeepEqual(got, tc.want) {
Copy link
Member

Choose a reason for hiding this comment

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

Should the boolean logic here be flipped?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great catch, @daved! I flipped it and I got something unexpected. Why is it that the got and tc.want are not considered equal?
Screenshot from 2020-09-21 22-37-46

Copy link
Member

Choose a reason for hiding this comment

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

Because *pb.User implements the fmt.Stringer interface, the string formatting provided by Fatalf results in output that deceptively looks identical (likely anyway). You can try dereferencing the values or using the %#v verb in the formatting as demoed here: https://play.golang.org/p/UkGo7MVxbRQ

@@ -526,3 +506,33 @@ func postSvcDelPostFn(ctx context.Context, conn *grpc.ClientConn, clnt pb.PostCl
}
}
}

func unsetUntestedFields(item interface{}) {
Copy link
Member

Choose a reason for hiding this comment

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

I suggest using a type switch. Example: https://play.golang.org/p/9QxbVKyAZz0

Also, please consider alternately using reflection for setting fields when present (use exceptional caution); and I'll defer to your preference of changing this: https://play.golang.org/p/J54OCQ6e_Xq

The Slug field is the only field below that is not common. I think it makes sense to set that within the test itself since any given test may require it to be different values, but the XXX_ prefixed, timestamp, and Id fields will likely always need handling.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The type switch makes so much more sense than what I was doing.

I'm not sure what you mean by using the reflect.ValueOf(). It seems like I'm using a lot more characters to do the same thing:
Screenshot from 2020-09-21 23-13-58

I must be missing something.

Copy link
Member

Choose a reason for hiding this comment

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

As per chat during meeting: https://play.golang.org/p/4Yz_xNLM5kZ

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I liked your hunch that protobuf was messing with the formatting with a String() method when I was outputting using t.Fatalf(). I tried out your advice to pass in pointers so the String() method won't be called, but I see the want and got are still identical. I have no idea why reflect.DeepEqual() still shows as not being equal. I was wondering if you would pull the branch and see if you can find anything @daved? Much thanks in advance.

Copy link
Member

Choose a reason for hiding this comment

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

Regarding unsetting, here is some logic that might help: https://play.golang.org/p/GoJvQwi5f-h

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you again, @daved. I used what you showed to unset several fields of two different types. This PR is ready for review again.

- Flip the boolean logic in reflect.DeepEqual()
- Use reflect to unset fields instead of switch by type

Signed-off-by: codegold79 <codegold79@gmail.com>
@codegold79 codegold79 force-pushed the Link-roles-to-users-in-User-Service branch from 0e0d0c1 to 6633e1e Compare October 10, 2020 18:45
@codegold79 codegold79 requested a review from daved October 10, 2020 18:46
@daved daved closed this Oct 10, 2020
@daved daved reopened this Oct 10, 2020
@daved daved merged commit 73e3bf4 into master Oct 10, 2020
@daved daved deleted the Link-roles-to-users-in-User-Service branch October 10, 2020 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

back: link roles to users in User Service
2 participants