Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func TestServer_FindByID(t *testing.T) {
- t.Parallel()
- accServer := accountsservice.NewService(charactersServer.logger, charactersServer.pool)
- testAccount, testAccountPassword := utils_test.MustCreateTestAccount(charactersServer.pool, accServer, "", "")
- authServer := authservice.NewService(charactersServer.logger, charactersServer.pool)
- userTokens := utils_test.MustLogin(authServer, testAccount.Name, testAccountPassword)
- testCharacter := utils_test.MustCreateTestCharacter(
- context.Background(), charactersServer.pool, testAccount.ID, "Bobert",
- )
- type args struct {
- ctx context.Context
- req *characters.FindByIDRequest
- }
- tests := []struct {
- name string
- s *Server
- args args
- want *characters.Character
- wantErr bool
- }{
- {
- name: "Find character by id",
- s: charactersServer,
- args: args{
- ctx: context.Background(),
- req: &characters.FindByIDRequest{
- Auth: &auth.AuthData{
- Token: userTokens.GetAccessToken(),
- },
- Id: testCharacter.ID,
- },
- },
- want: &characters.Character{
- Id: testCharacter.ID,
- OwnerId: testAccount.ID,
- CreatedAt: int32(testCharacter.CreatedAt.Unix()),
- LastLoginAt: int32(testCharacter.LastLoginAt.Unix()),
- PersonInfo: &characters.PersonInfo{
- FirstName: testCharacter.FirstName,
- LastName: testCharacter.LastName,
- Bio: testCharacter.Bio,
- },
- SpawnLocation: &characters.SpawnLocation{
- X: testCharacter.SpawnX,
- Y: testCharacter.SpawnZ,
- Z: testCharacter.SpawnY,
- Heading: testCharacter.SpawnHeading,
- },
- },
- },
- {
- name: "Find non-existent character by id",
- s: charactersServer,
- args: args{
- ctx: context.Background(),
- req: &characters.FindByIDRequest{
- Auth: &auth.AuthData{
- Token: userTokens.GetAccessToken(),
- },
- Id: 1337,
- },
- },
- wantErr: true,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- got, err := tt.s.FindByID(tt.args.ctx, tt.args.req)
- if (err != nil) != tt.wantErr {
- t.Errorf("Server.FindByID() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("Server.FindByID() = %v, want %v", got, tt.want)
- }
- })
- }
- conn, _ := charactersServer.pool.Acquire(context.Background())
- defer conn.Release()
- testAccount.Delete(conn.Conn(), testAccount.ID)
- testCharacter.Delete(context.Background(), conn.Conn(), testCharacter.ID)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement