Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 2.51 KB | None | 0 0
  1.  
  2. func TestServer_FindByID(t *testing.T) {
  3.     t.Parallel()
  4.  
  5.     accServer := accountsservice.NewService(charactersServer.logger, charactersServer.pool)
  6.     testAccount, testAccountPassword := utils_test.MustCreateTestAccount(charactersServer.pool, accServer, "", "")
  7.     authServer := authservice.NewService(charactersServer.logger, charactersServer.pool)
  8.     userTokens := utils_test.MustLogin(authServer, testAccount.Name, testAccountPassword)
  9.  
  10.     testCharacter := utils_test.MustCreateTestCharacter(
  11.         context.Background(), charactersServer.pool, testAccount.ID, "Bobert",
  12.     )
  13.  
  14.     type args struct {
  15.         ctx context.Context
  16.         req *characters.FindByIDRequest
  17.     }
  18.     tests := []struct {
  19.         name    string
  20.         s       *Server
  21.         args    args
  22.         want    *characters.Character
  23.         wantErr bool
  24.     }{
  25.         {
  26.             name: "Find character by id",
  27.             s:    charactersServer,
  28.             args: args{
  29.                 ctx: context.Background(),
  30.                 req: &characters.FindByIDRequest{
  31.                     Auth: &auth.AuthData{
  32.                         Token: userTokens.GetAccessToken(),
  33.                     },
  34.                     Id: testCharacter.ID,
  35.                 },
  36.             },
  37.             want: &characters.Character{
  38.                 Id:          testCharacter.ID,
  39.                 OwnerId:     testAccount.ID,
  40.                 CreatedAt:   int32(testCharacter.CreatedAt.Unix()),
  41.                 LastLoginAt: int32(testCharacter.LastLoginAt.Unix()),
  42.                 PersonInfo: &characters.PersonInfo{
  43.                     FirstName: testCharacter.FirstName,
  44.                     LastName:  testCharacter.LastName,
  45.                     Bio:       testCharacter.Bio,
  46.                 },
  47.                 SpawnLocation: &characters.SpawnLocation{
  48.                     X:       testCharacter.SpawnX,
  49.                     Y:       testCharacter.SpawnZ,
  50.                     Z:       testCharacter.SpawnY,
  51.                     Heading: testCharacter.SpawnHeading,
  52.                 },
  53.             },
  54.         },
  55.         {
  56.             name: "Find non-existent character by id",
  57.             s:    charactersServer,
  58.             args: args{
  59.                 ctx: context.Background(),
  60.                 req: &characters.FindByIDRequest{
  61.                     Auth: &auth.AuthData{
  62.                         Token: userTokens.GetAccessToken(),
  63.                     },
  64.                     Id: 1337,
  65.                 },
  66.             },
  67.             wantErr: true,
  68.         },
  69.     }
  70.     for _, tt := range tests {
  71.         t.Run(tt.name, func(t *testing.T) {
  72.             got, err := tt.s.FindByID(tt.args.ctx, tt.args.req)
  73.             if (err != nil) != tt.wantErr {
  74.                 t.Errorf("Server.FindByID() error = %v, wantErr %v", err, tt.wantErr)
  75.                 return
  76.             }
  77.             if !reflect.DeepEqual(got, tt.want) {
  78.                 t.Errorf("Server.FindByID() = %v, want %v", got, tt.want)
  79.             }
  80.         })
  81.     }
  82.  
  83.     conn, _ := charactersServer.pool.Acquire(context.Background())
  84.     defer conn.Release()
  85.     testAccount.Delete(conn.Conn(), testAccount.ID)
  86.     testCharacter.Delete(context.Background(), conn.Conn(), testCharacter.ID)
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement