Best Got code snippet using got.NotNil
issue_test.go
Source:issue_test.go
...42func TestShouldCreateAndFetchIssue(t *testing.T) {43 repo := NewMockIssueRepository()44 // don't use cache45 repo.Cache = nil46 assert.NotNil(t, repo.RSess)47 id, err := NewId()48 assert.Nil(t, err)49 uid, err := NewId()50 assert.Nil(t, err)51 author := pb.User{Id: &uid, Name: "test", CreateTime: timestamppb.Now()}52 issue := pb.Issue{Id: &id, Title: "test_title", Desc: "test_desc", Author: &author, CreateTime: timestamppb.Now()}53 ctx, cancel := context.WithTimeout(context.Background(), time.Second)54 defer cancel()55 // clean up Issue56 _ = repo.HardDeleteIssue(ctx, *issue.Id)57 uRet, err := repo.CreateUser(ctx, &author)58 assert.Nil(t, err)59 assert.NotNil(t, uRet)60 assert.Equal(t, author.Id, uRet.Id)61 ret, err := repo.CreateIssue(ctx, &issue)62 assert.Nil(t, err)63 assert.NotNil(t, ret)64 assert.Equal(t, &issue, ret)65 got, err := repo.FetchIssue(ctx, *issue.Id)66 assert.Nil(t, err)67 assert.NotNil(t, got)68 assert.Equal(t, &issue, got)69 assert.Equal(t, issue.Id, got.Id)70 assert.Equal(t, author.Id, got.Author.Id)71 err = repo.HardDeleteIssue(ctx, *issue.Id)72 assert.Nil(t, err)73 err = repo.HardDeleteUser(ctx, *author.Id)74 assert.Nil(t, err)75}76func TestShouldDeleteInternalIssue(t *testing.T) {77 repo := NewMockIssueRepository()78 // don't use cache79 repo.Cache = nil80 assert.NotNil(t, repo.RSess)81 id, err := NewId()82 assert.Nil(t, err)83 uid, err := NewId()84 assert.Nil(t, err)85 bid1, err := NewId()86 assert.Nil(t, err)87 bid2, err := NewId()88 assert.Nil(t, err)89 author := pb.User{Id: &uid, Name: "test", CreateTime: timestamppb.Now()}90 branch1 := pb.Branch{Id: &bid1, Content: "test_branch1"}91 branch2 := pb.Branch{Id: &bid2, Content: "test_branch2"}92 branches := []*pb.Branch{&branch1, &branch2}93 issue := pb.Issue{Id: &id, Title: "test_title", Desc: "test_desc", Author: &author, Branches: branches, CreateTime: timestamppb.Now()}94 ctx, cancel := context.WithTimeout(context.Background(), time.Second)95 defer cancel()96 // clean up Issue97 _ = repo.HardDeleteIssue(ctx, *issue.Id)98 uRet, err := repo.CreateUser(ctx, &author)99 assert.Nil(t, err)100 assert.NotNil(t, uRet)101 assert.Equal(t, author.Id, uRet.Id)102 ret, err := repo.CreateIssue(ctx, &issue)103 assert.Nil(t, err)104 assert.NotNil(t, ret)105 assert.Equal(t, &issue, ret)106 err = repo.DeleteIssueInternal(ctx, *issue.Id, *branch1.Id, "branches")107 assert.Nil(t, err)108 got, err := repo.FetchIssue(ctx, *issue.Id)109 assert.Nil(t, err)110 assert.NotNil(t, got)111 assert.Equal(t, 1, len(got.Branches))112 assert.Equal(t, issue.Branches[1], got.Branches[0])113 assert.Equal(t, issue.Id, got.Id)114 assert.Equal(t, author.Id, got.Author.Id)115 err = repo.HardDeleteIssue(ctx, *issue.Id)116 assert.Nil(t, err)117 err = repo.HardDeleteUser(ctx, *author.Id)118 assert.Nil(t, err)119}120func TestShouldUnDeleteInternalIssue(t *testing.T) {121 repo := NewMockIssueRepository()122 // don't use cache123 repo.Cache = nil124 assert.NotNil(t, repo.RSess)125 id, err := NewId()126 assert.Nil(t, err)127 uid, err := NewId()128 assert.Nil(t, err)129 bid1, err := NewId()130 assert.Nil(t, err)131 bid2, err := NewId()132 assert.Nil(t, err)133 author := pb.User{Id: &uid, Name: "test", CreateTime: timestamppb.Now()}134 branch1 := pb.Branch{Id: &bid1, Content: "test_branch1"}135 branch2 := pb.Branch{Id: &bid2, Content: "test_branch2"}136 branches := []*pb.Branch{&branch1, &branch2}137 issue := pb.Issue{Id: &id, Title: "test_title", Desc: "test_desc", Author: &author, Branches: branches, CreateTime: timestamppb.Now()}138 ctx, cancel := context.WithTimeout(context.Background(), time.Second)139 defer cancel()140 // clean up Issue141 _ = repo.HardDeleteIssue(ctx, *issue.Id)142 uRet, err := repo.CreateUser(ctx, &author)143 assert.Nil(t, err)144 assert.NotNil(t, uRet)145 assert.Equal(t, author.Id, uRet.Id)146 ret, err := repo.CreateIssue(ctx, &issue)147 assert.Nil(t, err)148 assert.NotNil(t, ret)149 assert.Equal(t, &issue, ret)150 err = repo.DeleteIssueInternal(ctx, *issue.Id, *branch1.Id, "branches")151 assert.Nil(t, err)152 got, err := repo.FetchIssue(ctx, *issue.Id)153 assert.Nil(t, err)154 assert.NotNil(t, got)155 assert.Equal(t, 1, len(got.Branches))156 assert.Equal(t, issue.Branches[1], got.Branches[0])157 assert.Equal(t, issue.Id, got.Id)158 assert.Equal(t, author.Id, got.Author.Id)159 err = repo.UnDeleteIssueInternal(ctx, *issue.Id, *branch1.Id, "branches")160 assert.Nil(t, err)161 got2, err := repo.FetchIssue(ctx, *issue.Id)162 assert.Nil(t, err)163 assert.NotNil(t, got2)164 assert.Equal(t, 2, len(got2.Branches))165 assert.Equal(t, issue.Branches[0], got2.Branches[0])166 assert.Equal(t, issue.Id, got2.Id)167 assert.Equal(t, author.Id, got2.Author.Id)168 err = repo.HardDeleteIssue(ctx, *issue.Id)169 assert.Nil(t, err)170 err = repo.HardDeleteUser(ctx, *author.Id)171 assert.Nil(t, err)172}173func TestShouldCreateAndFetchIssueWithCache(t *testing.T) {174 repo := NewMockIssueRepository()175 assert.NotNil(t, repo.RSess)176 assert.NotNil(t, repo.Cache)177 id, err := NewId()178 assert.Nil(t, err)179 uid, err := NewId()180 assert.Nil(t, err)181 author := pb.User{Id: &uid, Name: "test1", CreateTime: timestamppb.Now()}182 issue := pb.Issue{Id: &id, Title: "test1_title", Desc: "test1_desc", Author: &author, CreateTime: timestamppb.Now()}183 ctx, cancel := context.WithTimeout(context.Background(), time.Second)184 defer cancel()185 // clean up Issue186 _ = repo.HardDeleteIssue(ctx, *issue.Id)187 uRet, err := repo.CreateUser(ctx, &author)188 assert.Nil(t, err)189 assert.NotNil(t, uRet)190 assert.Equal(t, author.Id, uRet.Id)191 ret, err := repo.CreateIssue(ctx, &issue)192 assert.Nil(t, err)193 assert.NotNil(t, ret)194 assert.Equal(t, &issue, ret)195 got, err := repo.FetchIssue(ctx, *issue.Id)196 assert.Nil(t, err)197 assert.NotNil(t, got)198 assert.Equal(t, &issue, got)199 assert.Equal(t, issue.Id, got.Id)200 assert.Equal(t, author.Id, got.Author.Id)201 err = repo.HardDeleteIssue(ctx, *issue.Id)202 assert.Nil(t, err)203 err = repo.HardDeleteUser(ctx, *author.Id)204 assert.Nil(t, err)205}206func TestShouldFetchIssues(t *testing.T) {207 repo := NewMockIssueRepository()208 id1, _ := NewId()209 id2, _ := NewId()210 uid, _ := NewId()211 author := pb.User{Id: &uid, Name: "test1", CreateTime: timestamppb.Now()}212 issue1 := pb.Issue{Id: &id1, Title: "test1_title1", Desc: "test1_desc1", Author: &author, CreateTime: timestamppb.Now()}213 issue2 := pb.Issue{Id: &id2, Title: "test1_title2", Desc: "test1_desc2", Author: &author, CreateTime: timestamppb.Now()}214 ctx, cancel := context.WithTimeout(context.Background(), time.Second)215 defer cancel()216 // clean up Issue217 _ = repo.HardDeleteIssue(ctx, *issue1.Id)218 _ = repo.HardDeleteIssue(ctx, *issue2.Id)219 _, err := repo.CreateUser(ctx, &author)220 assert.Nil(t, err)221 _, err = repo.CreateIssue(ctx, &issue1)222 assert.Nil(t, err)223 _, err = repo.CreateIssue(ctx, &issue2)224 assert.Nil(t, err)225 got, err := repo.FetchIssues(ctx, *author.Id)226 assert.Nil(t, err)227 assert.Equal(t, 2, len(got))228 // allow no order229 var acc = map[string]*pb.Issue{}230 for _, v := range got {231 acc[*v.Id] = v232 }233 assert.Equal(t, &issue1, acc[*issue1.Id])234 assert.Equal(t, &issue2, acc[*issue2.Id])235 assert.Equal(t, issue1.Id, acc[*issue1.Id].Id)236 assert.Equal(t, author.Id, acc[*issue1.Id].Author.Id)237 err = repo.HardDeleteIssue(ctx, *issue1.Id)238 assert.Nil(t, err)239 err = repo.HardDeleteIssue(ctx, *issue2.Id)240 assert.Nil(t, err)241 err = repo.HardDeleteUser(ctx, *author.Id)242 assert.Nil(t, err)243}244func TestShouldPutIssue(t *testing.T) {245 repo := NewMockIssueRepository()246 id, _ := NewId()247 uid, _ := NewId()248 author := pb.User{Id: &uid, Name: "test1", CreateTime: timestamppb.Now()}249 issue1 := pb.Issue{Id: &id, Title: "test1_title1", Desc: "test1_desc1", Author: &author, CreateTime: timestamppb.Now()}250 issue2 := pb.Issue{Id: &id, Title: "test1_title2", Desc: "test1_desc2", Author: &author, CreateTime: timestamppb.Now()}251 ctx, cancel := context.WithTimeout(context.Background(), time.Second)252 defer cancel()253 // clean up Issue254 _ = repo.HardDeleteIssue(ctx, *issue1.Id)255 _, err := repo.CreateUser(ctx, &author)256 assert.Nil(t, err)257 _, err = repo.CreateIssue(ctx, &issue1)258 assert.Nil(t, err)259 res, err := repo.PutIssue(ctx, *issue2.Id, &issue2)260 assert.Nil(t, err)261 assert.NotNil(t, res)262 assert.Equal(t, issue2.Title, res.Title)263 got, err := repo.FetchIssue(ctx, *issue2.Id)264 assert.Nil(t, err)265 assert.Equal(t, &issue2, got)266 assert.Equal(t, issue2.Id, got.Id)267 err = repo.HardDeleteIssue(ctx, id)268 assert.Nil(t, err)269 err = repo.HardDeleteUser(ctx, *author.Id)270 assert.Nil(t, err)271}272func TestShouldDeleteIssue(t *testing.T) {273 repo := NewMockIssueRepository()274 id, _ := NewId()275 uid, _ := NewId()276 author := pb.User{Id: &uid, Name: "test1", CreateTime: timestamppb.Now()}277 issue := pb.Issue{Id: &id, Title: "test1_title1", Desc: "test1_desc1", Author: &author, CreateTime: timestamppb.Now()}278 ctx, cancel := context.WithTimeout(context.Background(), time.Second)279 defer cancel()280 // clean up Issue281 _ = repo.HardDeleteIssue(ctx, *issue.Id)282 _, err := repo.CreateUser(ctx, &author)283 assert.Nil(t, err)284 _, err = repo.CreateIssue(ctx, &issue)285 assert.Nil(t, err)286 pre, err := repo.FetchIssue(ctx, *issue.Id)287 assert.Nil(t, err)288 assert.NotNil(t, pre)289 err = repo.DeleteIssue(ctx, *issue.Id)290 assert.Nil(t, err)291 got, err := repo.FetchIssue(ctx, *issue.Id)292 assert.NotNil(t, err)293 assert.Nil(t, got)294 err = repo.HardDeleteIssue(ctx, id)295 assert.Nil(t, err)296 err = repo.HardDeleteUser(ctx, *author.Id)297 assert.Nil(t, err)298}299func TestShouldUnDeleteIssue(t *testing.T) {300 repo := NewMockIssueRepository()301 id, _ := NewId()302 uid, _ := NewId()303 author := pb.User{Id: &uid, Name: "test1", CreateTime: timestamppb.Now()}304 issue := pb.Issue{Id: &id, Title: "test1_title1", Desc: "test1_desc1", Author: &author, CreateTime: timestamppb.Now()}305 ctx, cancel := context.WithTimeout(context.Background(), time.Second)306 defer cancel()307 // clean up Issue308 _ = repo.HardDeleteIssue(ctx, *issue.Id)309 _, err := repo.CreateUser(ctx, &author)310 assert.Nil(t, err)311 _, err = repo.CreateIssue(ctx, &issue)312 assert.Nil(t, err)313 err = repo.DeleteIssue(ctx, *issue.Id)314 assert.Nil(t, err)315 _, err = repo.FetchIssue(ctx, *issue.Id)316 assert.NotNil(t, err)317 err = repo.UnDeleteIssue(ctx, *issue.Id)318 assert.Nil(t, err)319 // expect un deleted issue available320 got, err := repo.FetchIssue(ctx, *issue.Id)321 assert.Nil(t, err)322 assert.NotNil(t, got)323 assert.Equal(t, &issue, got)324 assert.Equal(t, issue.Id, got.Id)325 err = repo.HardDeleteIssue(ctx, id)326 assert.Nil(t, err)327 err = repo.HardDeleteUser(ctx, *author.Id)328 assert.Nil(t, err)329}330func TestShouldCreateAndFetchData(t *testing.T) {331 repo := NewMockIssueRepository()332 // don't use cache333 repo.Cache = nil334 assert.NotNil(t, repo.RSess)335 id, err := NewId()336 assert.Nil(t, err)337 data := pb.Data{Id: &id, Columns: []string{"c1", "c2"}, CreateTime: timestamppb.Now()}338 ctx, cancel := context.WithTimeout(context.Background(), time.Second)339 defer cancel()340 // clean up Issue341 _ = repo.HardDeleteData(ctx, id)342 ret, err := repo.CreateData(ctx, &data)343 assert.Nil(t, err)344 assert.NotNil(t, ret)345 assert.Equal(t, &data, ret)346 got, err := repo.FetchData(ctx, *data.Id)347 assert.Nil(t, err)348 assert.NotNil(t, got)349 assert.Equal(t, &data, got)350 assert.Equal(t, data.Id, got.Id)351 err = repo.HardDeleteData(ctx, *data.Id)352 assert.Nil(t, err)353}354func TestShouldCreateAndFetchDataWithCache(t *testing.T) {355 repo := NewMockIssueRepository()356 assert.NotNil(t, repo.RSess)357 assert.NotNil(t, repo.Cache)358 id, err := NewId()359 assert.Nil(t, err)360 data := pb.Data{Id: &id, Columns: []string{"c1", "c2"}, CreateTime: timestamppb.Now()}361 ctx, cancel := context.WithTimeout(context.Background(), time.Second)362 defer cancel()363 // clean up Issue364 _ = repo.HardDeleteData(ctx, *data.Id)365 ret, err := repo.CreateData(ctx, &data)366 assert.Nil(t, err)367 assert.NotNil(t, ret)368 assert.Equal(t, &data, ret)369 got, err := repo.FetchData(ctx, *data.Id)370 assert.Nil(t, err)371 assert.NotNil(t, got)372 assert.Equal(t, &data, got)373 assert.Equal(t, data.Id, got.Id)374 err = repo.HardDeleteData(ctx, *data.Id)375 assert.Nil(t, err)376}377func TestShouldFetchDataList(t *testing.T) {378 repo := NewMockIssueRepository()379 id1, _ := NewId()380 id2, _ := NewId()381 uid, _ := NewId()382 data1 := pb.Data{Id: &id1, Columns: []string{"c1", "c2"}, Author: uid, CreateTime: timestamppb.Now()}383 data2 := pb.Data{Id: &id2, Columns: []string{"d1", "d2"}, Author: uid, CreateTime: timestamppb.Now()}384 ctx, cancel := context.WithTimeout(context.Background(), time.Second)385 defer cancel()386 // clean up Issue387 _ = repo.HardDeleteData(ctx, *data1.Id)388 _ = repo.HardDeleteData(ctx, *data2.Id)389 var err error390 _, err = repo.CreateData(ctx, &data1)391 assert.Nil(t, err)392 _, err = repo.CreateData(ctx, &data2)393 assert.Nil(t, err)394 got, err := repo.FetchDataList(ctx, uid)395 assert.Nil(t, err)396 assert.Equal(t, 2, len(got))397 // allow no order398 var acc = map[string]*pb.Data{}399 for _, v := range got {400 acc[*v.Id] = v401 }402 assert.Equal(t, &data1, acc[*data1.Id])403 assert.Equal(t, &data2, acc[*data2.Id])404 assert.Equal(t, data1.Id, acc[*data1.Id].Id)405 err = repo.HardDeleteData(ctx, *data1.Id)406 assert.Nil(t, err)407 err = repo.HardDeleteData(ctx, *data2.Id)408 assert.Nil(t, err)409}410func TestShouldPutData(t *testing.T) {411 repo := NewMockIssueRepository()412 id, _ := NewId()413 uid, _ := NewId()414 data1 := pb.Data{Id: &id, Columns: []string{"c1", "c2"}, Author: uid, CreateTime: timestamppb.Now()}415 data2 := pb.Data{Id: &id, Columns: []string{"d1", "d2"}, Author: uid, CreateTime: timestamppb.Now()}416 ctx, cancel := context.WithTimeout(context.Background(), time.Second)417 defer cancel()418 // clean up Data419 _ = repo.HardDeleteData(ctx, *data1.Id)420 _, err := repo.CreateData(ctx, &data1)421 assert.Nil(t, err)422 res, err := repo.PutData(ctx, *data2.Id, &data2)423 assert.Nil(t, err)424 assert.NotNil(t, res)425 assert.Equal(t, data2.Columns, res.Columns)426 got, err := repo.FetchData(ctx, id)427 assert.Nil(t, err)428 assert.Equal(t, &data2, got)429 assert.Equal(t, data2.Id, got.Id)430 err = repo.HardDeleteData(ctx, id)431 assert.Nil(t, err)432}433func TestShouldDeleteData(t *testing.T) {434 repo := NewMockIssueRepository()435 id, _ := NewId()436 uid, _ := NewId()437 data := pb.Data{Id: &id, Columns: []string{"c1", "c2"}, Author: uid, CreateTime: timestamppb.Now()}438 ctx, cancel := context.WithTimeout(context.Background(), time.Second)439 defer cancel()440 // clean up Data441 _ = repo.HardDeleteData(ctx, id)442 _, err := repo.CreateData(ctx, &data)443 assert.Nil(t, err)444 pre, err := repo.FetchData(ctx, id)445 assert.Nil(t, err)446 assert.NotNil(t, pre)447 err = repo.DeleteData(ctx, id)448 assert.Nil(t, err)449 got, err := repo.FetchData(ctx, id)450 assert.NotNil(t, err)451 assert.Nil(t, got)452 err = repo.HardDeleteData(ctx, id)453 assert.Nil(t, err)454}455func TestShouldUnDeleteData(t *testing.T) {456 repo := NewMockIssueRepository()457 id, _ := NewId()458 uid, _ := NewId()459 data := pb.Data{Id: &id, Columns: []string{"c1", "c2"}, Author: uid, CreateTime: timestamppb.Now()}460 ctx, cancel := context.WithTimeout(context.Background(), time.Second)461 defer cancel()462 // clean up Data463 _ = repo.HardDeleteData(ctx, id)464 _, err := repo.CreateData(ctx, &data)465 assert.Nil(t, err)466 err = repo.DeleteData(ctx, id)467 assert.Nil(t, err)468 _, err = repo.FetchData(ctx, id)469 assert.NotNil(t, err)470 err = repo.UnDeleteData(ctx, id)471 assert.Nil(t, err)472 // expect un deleted issue available473 got, err := repo.FetchData(ctx, id)474 assert.Nil(t, err)475 assert.NotNil(t, got)476 assert.Equal(t, &data, got)477 assert.Equal(t, data.Id, got.Id)478 err = repo.HardDeleteData(ctx, id)479 assert.Nil(t, err)480}481func TestIssueServiceCreateIssue(t *testing.T) {482 ctx := context.Background()483 conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(bufDialer), grpc.WithInsecure())484 assert.Nil(t, err)485 defer conn.Close()486 client := pb.NewIssueServiceClient(conn)487 userClient := pb.NewUserServiceClient(conn)488 userResp, err := userClient.CreateUser(ctx, &pb.CreateUserRequest{User: &pb.User{Name: "user1"}})489 assert.Nil(t, err)490 issue := pb.Issue{Title: "title1", Author: userResp.GetUser()}491 resp, err := client.CreateIssue(ctx, &pb.CreateIssueRequest{UserId: *userResp.GetUser().Id, Issue: &pb.Issue{Title: "title1"}})492 assert.Nil(t, err)493 assert.Equal(t, issue.Title, resp.GetIssue().Title)494 assert.Equal(t, issue.Desc, resp.GetIssue().Desc)495 assert.Equal(t, issue.Author.Id, resp.GetIssue().Author.Id)496 assert.Equal(t, issue.Author.Name, resp.GetIssue().Author.Name)497}498func TestIssueServiceGetIssue(t *testing.T) {499 ctx := context.Background()500 conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(bufDialer), grpc.WithInsecure())501 assert.Nil(t, err)502 defer conn.Close()503 client := pb.NewIssueServiceClient(conn)504 userClient := pb.NewUserServiceClient(conn)505 userResp, err := userClient.CreateUser(ctx, &pb.CreateUserRequest{User: &pb.User{Name: "user1"}})506 assert.Nil(t, err)507 issue := pb.Issue{Title: "title1", Author: userResp.GetUser()}508 resp, err := client.CreateIssue(ctx, &pb.CreateIssueRequest{UserId: *userResp.GetUser().Id, Issue: &pb.Issue{Title: "title1"}})509 assert.Nil(t, err)510 got, err := client.GetIssue(ctx, &pb.GetIssueRequest{IssueId: *resp.GetIssue().Id})511 assert.Nil(t, err)512 assert.Equal(t, issue.Title, got.GetIssue().Title)513 assert.Equal(t, issue.Desc, got.GetIssue().Desc)514 assert.Equal(t, issue.Author.Id, got.GetIssue().Author.Id)515 assert.Equal(t, issue.Author.Name, got.GetIssue().Author.Name)516}517func TestIssueServiceUpdateIssue(t *testing.T) {518 ctx := context.Background()519 conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(bufDialer), grpc.WithInsecure())520 assert.Nil(t, err)521 defer conn.Close()522 client := pb.NewIssueServiceClient(conn)523 userClient := pb.NewUserServiceClient(conn)524 userResp, err := userClient.CreateUser(ctx, &pb.CreateUserRequest{User: &pb.User{Name: "user1"}})525 assert.Nil(t, err)526 issue := pb.Issue{Title: "title1", Author: userResp.GetUser()}527 resp, err := client.CreateIssue(ctx, &pb.CreateIssueRequest{UserId: *userResp.GetUser().Id, Issue: &pb.Issue{Title: "title1"}})528 assert.Nil(t, err)529 updateInput := resp.GetIssue()530 updateInput.Title = "titleUpdated"531 updateInput.Desc = "descUpdated"532 fm := fieldmaskpb.FieldMask{Paths: []string{"Title"}}533 updated, err := client.UpdateIssue(ctx, &pb.UpdateIssueRequest{Issue: updateInput, FieldMask: &fm})534 assert.Nil(t, err)535 assert.NotNil(t, updated)536 got, err := client.GetIssue(ctx, &pb.GetIssueRequest{IssueId: *resp.GetIssue().Id})537 assert.Nil(t, err)538 assert.Equal(t, "titleUpdated", got.GetIssue().Title)539 assert.Equal(t, "", got.GetIssue().Desc)540 assert.Equal(t, issue.Author.Id, got.GetIssue().Author.Id)541}542func TestIssueServiceDeleteIssue(t *testing.T) {543 ctx := context.Background()544 conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(bufDialer), grpc.WithInsecure())545 assert.Nil(t, err)546 defer conn.Close()547 client := pb.NewIssueServiceClient(conn)548 userClient := pb.NewUserServiceClient(conn)549 userResp, err := userClient.CreateUser(ctx, &pb.CreateUserRequest{User: &pb.User{Name: "user1"}})550 assert.Nil(t, err)551 resp, err := client.CreateIssue(ctx, &pb.CreateIssueRequest{UserId: *userResp.GetUser().Id, Issue: &pb.Issue{Title: "title1"}})552 assert.Nil(t, err)553 deleted, err := client.DeleteIssue(ctx, &pb.DeleteIssueRequest{IssueId: *resp.GetIssue().Id})554 assert.Nil(t, err)555 assert.NotNil(t, deleted)556 got, err := client.GetIssue(ctx, &pb.GetIssueRequest{IssueId: *resp.GetIssue().Id})557 assert.NotNil(t, err)558 assert.Nil(t, got)559}560func TestIssueServiceUnDeleteIssue(t *testing.T) {561 ctx := context.Background()562 conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(bufDialer), grpc.WithInsecure())563 assert.Nil(t, err)564 defer conn.Close()565 client := pb.NewIssueServiceClient(conn)566 userClient := pb.NewUserServiceClient(conn)567 userResp, err := userClient.CreateUser(ctx, &pb.CreateUserRequest{User: &pb.User{Name: "user1"}})568 assert.Nil(t, err)569 resp, err := client.CreateIssue(ctx, &pb.CreateIssueRequest{UserId: *userResp.GetUser().Id, Issue: &pb.Issue{Title: "title1"}})570 assert.Nil(t, err)571 _, err = client.DeleteIssue(ctx, &pb.DeleteIssueRequest{IssueId: *resp.GetIssue().Id})572 assert.Nil(t, err)573 deleted, _ := client.GetIssue(ctx, &pb.GetIssueRequest{IssueId: *resp.GetIssue().Id})574 assert.Nil(t, deleted)575 unDeleted, err := client.UnDeleteIssue(ctx, &pb.UnDeleteIssueRequest{IssueId: *resp.GetIssue().Id})576 assert.Nil(t, err)577 assert.NotNil(t, unDeleted)578 got, err := client.GetIssue(ctx, &pb.GetIssueRequest{IssueId: *resp.GetIssue().Id})579 assert.Nil(t, err)580 assert.NotNil(t, got)581 assert.Equal(t, *resp.GetIssue().Id, *got.GetIssue().Id)582 assert.Equal(t, resp.GetIssue().Title, got.GetIssue().Title)583}...
hash_test.go
Source:hash_test.go
...33 TesyHashField = []byte("HashField")34)35func Test_newHash(t *testing.T) {36 txn, err := mockDB.Begin()37 assert.NotNil(t, txn)38 assert.NoError(t, err)39 type args struct {40 txn *Transaction41 key []byte42 }43 tests := []struct {44 name string45 args args46 want *Hash47 }{48 {49 name: "TestNewHash",50 args: args{51 txn: txn,52 key: []byte("TestNewHash"),53 },54 want: &Hash{55 meta: &HashMeta{},56 key: []byte("TestNewHash"),57 txn: txn,58 },59 },60 }61 for _, tt := range tests {62 t.Run(tt.name, func(t *testing.T) {63 txn, err := mockDB.Begin()64 assert.NotNil(t, txn)65 assert.NoError(t, err)66 got := newHash(tt.args.txn, tt.args.key)67 txn.Commit(context.TODO())68 if err := compareNewHash(tt.want, got); err != nil {69 t.Errorf("NewHash() = %v, want %v", got, tt.want)70 }71 })72 }73 txn.Commit(context.TODO())74}75func setHashMeta(t *testing.T, txn *Transaction, key []byte, metaSlot int64) error {76 h := newHash(txn, key)77 mkey := MetaKey(txn.db, key)78 hm := &HashMeta{79 Object: h.meta.Object,80 }81 meta := EncodeHashMeta(hm)82 err := txn.t.Set(mkey, meta)83 assert.NoError(t, err)84 assert.NotNil(t, txn)85 return nil86}87func getHashMeta(t *testing.T, txn *Transaction, key []byte) *HashMeta {88 mkey := MetaKey(txn.db, key)89 rawMeta, err := txn.t.Get(mkey)90 assert.NoError(t, err)91 meta, err1 := DecodeHashMeta(rawMeta)92 assert.NoError(t, err1)93 return meta94}95//å é¤è®¾ç½®çmetaä¿¡æ¯96func destoryHashMeta(t *testing.T, txn *Transaction, key []byte) error {97 metakey := MetaKey(txn.db, key)98 if err := txn.t.Delete(metakey); err != nil {99 return err100 }101 return nil102}103func getHash(t *testing.T, key []byte) (*Hash, *Transaction, error) {104 txn, err := mockDB.Begin()105 assert.NotNil(t, txn)106 assert.NoError(t, err)107 hash, err := GetHash(txn, key)108 assert.NotNil(t, hash)109 assert.NoError(t, err)110 return hash, txn, nil111}112func compareKvMap(t *testing.T, get, want map[string][]byte) error {113 switch {114 case !bytes.Equal(want["TestHashdelHashFiled1"], get["TestHashdelHashFiled1"]):115 return fmt.Errorf("set key not equal, want=%s, get=%s", string(want["TestHashdelHashFiled1"]), string(get["TestHashdelHashFiled1"]))116 case !bytes.Equal(want["TestHashdelHashFiled2"], get["TestHashdelHashFiled2"]):117 return fmt.Errorf("set key not equal, want=%s, get=%s", string(want["TestHashdelHashFiled2"]), string(get["Tes tHashdelHashFiled2"]))118 case !bytes.Equal(want["TestHashdelHashFiled3"], get["TestHashdelHashFiled3"]):119 return fmt.Errorf("set key not equal, want=%s, get=%s", string(want["TestHashdelHashFiled3"]), string(get["Tes tHashdelHashFiled3"]))120 }121 return nil122}123func TestGetHash(t *testing.T) {124 txn, err := mockDB.Begin()125 assert.NoError(t, err)126 assert.NotNil(t, txn)127 setHashMeta(t, txn, []byte("TestGetHashExistKey"), 0)128 setHashMeta(t, txn, []byte("TestGetHashSlotKey"), 100)129 type args struct {130 txn *Transaction131 key []byte132 }133 type want struct {134 hash *Hash135 err error136 }137 tests := []struct {138 name string139 args args140 want want141 err error142 wantErr bool143 }{144 {145 name: "TestGetHashNoExistKey",146 args: args{147 txn: txn,148 key: []byte("TestGetHashNoExistKey"),149 },150 want: want{151 hash: &Hash{152 meta: &HashMeta{153 Object: Object{154 Type: ObjectHash,155 },156 },157 key: []byte("TestGetHashNoExistKey"),158 exists: false,159 txn: txn,160 },161 err: nil,162 },163 err: nil,164 wantErr: false,165 },166 {167 name: "TestGetHashExistKey",168 args: args{169 txn: txn,170 key: []byte("TestGetHashExistKey")},171 want: want{172 hash: &Hash{meta: &HashMeta{173 Object: Object{174 Type: ObjectHash,175 },176 },177 key: []byte("TestGetHashExistKey"),178 exists: true,179 txn: txn,180 },181 err: nil,182 },183 err: nil,184 wantErr: false,185 },186 {187 name: "TestGetHashSlotKey",188 args: args{189 txn: txn,190 key: []byte("TestGetHashSlotKey")},191 want: want{192 hash: &Hash{meta: &HashMeta{193 Object: Object{194 Type: ObjectHash,195 },196 },197 key: []byte("TestGetHashSlotKey"),198 exists: true,199 txn: txn,200 },201 err: nil,202 },203 err: nil,204 wantErr: false,205 },206 }207 for _, tt := range tests {208 t.Run(tt.name, func(t *testing.T) {209 txn, err := mockDB.Begin()210 if err != nil {211 t.Errorf("db.Begin error %s", err)212 }213 got, err := GetHash(tt.args.txn, tt.args.key)214 if err = txn.Commit(context.TODO()); err != nil {215 t.Errorf("GetString() txn.Commit error = %v", err)216 return217 }218 if (err != nil) != tt.wantErr {219 t.Errorf("GetHash() error = %v, wantErr %v", err, tt.wantErr)220 return221 }222 if err := compareGetHash(tt.want.hash, got); err != nil {223 t.Errorf("GetHash() = %v, want %v", got, tt.want)224 }225 if tt.want.err != tt.err {226 t.Errorf("GetHash() error = %v, wantErr %v", err, tt.wantErr)227 }228 })229 }230 destoryHashMeta(t, txn, []byte("TestGetHashExistKey"))231 destoryHashMeta(t, txn, []byte("TestGetHashSlotKey"))232 txn.Commit(context.TODO())233}234func TestHashHSet(t *testing.T) {235 type args struct {236 field []byte237 value []byte238 }239 type want struct {240 num int241 len int242 }243 tests := []struct {244 name string245 args args246 want want247 }{248 {249 name: "TestHashHSetNoExistKey",250 args: args{251 field: []byte("HashField"),252 value: []byte("HashValue"),253 },254 want: want{255 num: 1,256 len: 1,257 },258 },259 {260 name: "TestHashHSetExistKey",261 args: args{262 field: []byte("HashField"),263 value: []byte("HashValue2"),264 },265 want: want{266 num: 0,267 len: 1,268 },269 },270 }271 for _, tt := range tests {272 t.Run(tt.name, func(t *testing.T) {273 hash, txn, err := getHash(t, []byte("TestHashHSet"))274 assert.NoError(t, err)275 assert.NotNil(t, txn)276 assert.NotNil(t, hash)277 got, err := hash.HSet(tt.args.field, tt.args.value)278 assert.NoError(t, err)279 assert.NotNil(t, got)280 txn.Commit(context.TODO())281 assert.Equal(t, got, tt.want.num)282 })283 }284}285func TestHashHDel(t *testing.T) {286 hash, txn, err := getHash(t, []byte("TestHashHDel"))287 assert.NoError(t, err)288 assert.NotNil(t, txn)289 assert.NotNil(t, hash)290 var fileds [][]byte291 fileds = append(fileds, []byte("TestHashDelFiled1"))292 fileds = append(fileds, []byte("TestHashDelFiled2"))293 fileds = append(fileds, []byte("TestHashDelFiled3"))294 hash.HSet([]byte("TestHashDelFiled1"), []byte("TestDelHashValue1"))295 hash.HSet([]byte("TestHashDelFiled2"), []byte("TestDelHashValue2"))296 hash.HSet([]byte("TestHashDelFiled3"), []byte("TestDelHashValue3"))297 txn.Commit(context.TODO())298 type args struct {299 fields [][]byte300 }301 type want struct {302 num int64303 len int64304 }305 tests := []struct {306 name string307 args args308 want want309 }{310 {311 name: "TestHashDelCase1",312 args: args{313 fields: fileds[:1],314 },315 want: want{316 num: 1,317 len: 2,318 },319 },320 {321 name: "TestHashDelCase2",322 args: args{323 fields: fileds[1:],324 },325 want: want{326 num: 2,327 len: 0,328 },329 },330 }331 for _, tt := range tests {332 t.Run(tt.name, func(t *testing.T) {333 //test hdel method334 hash, txn, err := getHash(t, []byte("TestHashHDel"))335 assert.NoError(t, err)336 assert.NotNil(t, txn)337 assert.NotNil(t, hash)338 got, err := hash.HDel(tt.args.fields)339 assert.NoError(t, err)340 assert.NotNil(t, got)341 txn.Commit(context.TODO())342 assert.Equal(t, got, tt.want.num)343 //use hlen check344 hash, txn, err = getHash(t, []byte("TestHashHDel"))345 hlen, err1 := hash.HLen()346 assert.NoError(t, err1)347 assert.Equal(t, hlen, tt.want.len)348 txn.Commit(context.TODO())349 })350 }351}352func TestHashHSetNX(t *testing.T) {353 type args struct {354 field []byte355 value []byte356 }357 tests := []struct {358 name string359 args args360 want int361 }{362 {363 name: "TestHash_HSetNXNoExist",364 args: args{365 field: []byte("TestHashSetNxField"),366 value: []byte("TestHashSetNxValue"),367 },368 want: 1,369 },370 {371 name: "TestHash_HSetNXExist",372 args: args{373 field: []byte("TestHashSetNxField"),374 value: []byte("TestHashSetNxValue"),375 },376 want: 0,377 },378 }379 for _, tt := range tests {380 t.Run(tt.name, func(t *testing.T) {381 hash, txn, err := getHash(t, []byte("TestHashHSetNX"))382 assert.NoError(t, err)383 assert.NotNil(t, txn)384 assert.NotNil(t, hash)385 got, err := hash.HSetNX(tt.args.field, tt.args.value)386 txn.Commit(context.TODO())387 assert.Equal(t, got, tt.want)388 })389 }390}391func TestHash_HGet(t *testing.T) {392 hash, txn, err := getHash(t, []byte("TestHashHGet"))393 assert.NoError(t, err)394 assert.NotNil(t, txn)395 assert.NotNil(t, hash)396 hash.HSet([]byte("TestHashHGetFiled"), []byte("TestHashHGetValue"))397 txn.Commit(context.TODO())398 type args struct {399 field []byte400 }401 tests := []struct {402 name string403 args args404 want []byte405 }{406 {407 name: "TestHashHGet",408 args: args{409 field: []byte("TestHashHGetFiled"),410 },411 want: []byte("TestHashHGetValue"),412 },413 {414 name: "TestHashHGetNoExist",415 args: args{416 field: []byte("TestHashHGetFiled1"),417 },418 want: nil,419 },420 }421 for _, tt := range tests {422 t.Run(tt.name, func(t *testing.T) {423 hash, txn, err := getHash(t, []byte("TestHashHGet"))424 assert.NoError(t, err)425 assert.NotNil(t, txn)426 assert.NotNil(t, hash)427 got, err := hash.HGet(tt.args.field)428 txn.Commit(context.TODO())429 assert.Equal(t, got, tt.want)430 })431 }432}433func TestHashHGetAll(t *testing.T) {434 hash, txn, err := getHash(t, []byte("TestHashHGetAll"))435 assert.NoError(t, err)436 assert.NotNil(t, txn)437 assert.NotNil(t, hash)438 hash.HSet([]byte("TestHashHGetAllFiled1"), []byte("TestHashHGetAllValue1"))439 hash.HSet([]byte("TestHashHGetAllFiled2"), []byte("TestHashHGetAllValue2"))440 hash.HSet([]byte("TestHashHGetAllFiled3"), []byte("TestHashHGetAllValue3"))441 txn.Commit(context.TODO())442 type want struct {443 fields [][]byte444 value [][]byte445 }446 var fields [][]byte447 var value [][]byte448 fields = append(fields, []byte("TestHashHGetAllFiled1"))449 fields = append(fields, []byte("TestHashHGetAllFiled2"))450 fields = append(fields, []byte("TestHashHGetAllFiled3"))451 value = append(value, []byte("TestHashHGetAllValue1"))452 value = append(value, []byte("TestHashHGetAllValue2"))453 value = append(value, []byte("TestHashHGetAllValue3"))454 tests := []struct {455 name string456 want want457 }{458 {459 name: "TestHashHGetAll",460 want: want{461 fields: fields,462 value: value,463 },464 },465 }466 for _, tt := range tests {467 t.Run(tt.name, func(t *testing.T) {468 hash, txn, err := getHash(t, []byte("TestHashHGetAll"))469 assert.NoError(t, err)470 assert.NotNil(t, txn)471 assert.NotNil(t, hash)472 got, got1, err := hash.HGetAll()473 assert.NoError(t, err)474 assert.NotNil(t, got)475 assert.NotNil(t, got1)476 txn.Commit(context.TODO())477 assert.Equal(t, got, tt.want.fields)478 assert.Equal(t, got1, tt.want.value)479 })480 }481}482func TestHash_HExists(t *testing.T) {483 hash, txn, err := getHash(t, []byte("TestHashExists"))484 assert.NoError(t, err)485 assert.NotNil(t, txn)486 assert.NotNil(t, hash)487 hash.HSet([]byte("TestHashDestory"), []byte("TestHashDestoryValue1"))488 txn.Commit(context.TODO())489 type args struct {490 field []byte491 }492 tests := []struct {493 name string494 args args495 want bool496 }{497 {498 name: "TestHashExists",499 args: args{500 field: []byte("TestHashDestory"),501 },502 want: true,503 },504 {505 name: "TestHashNoExists",506 args: args{507 field: []byte("TestHashNoExistsDestory"),508 },509 want: false,510 },511 }512 for _, tt := range tests {513 t.Run(tt.name, func(t *testing.T) {514 hash, txn, err := getHash(t, []byte("TestHashExists"))515 assert.NoError(t, err)516 assert.NotNil(t, txn)517 assert.NotNil(t, hash)518 got, err := hash.HExists(tt.args.field)519 txn.Commit(context.TODO())520 assert.Equal(t, got, tt.want)521 assert.NoError(t, err)522 })523 }524}525func TestHashHIncrByFloat(t *testing.T) {526 hash, txn, err := getHash(t, []byte("TestHashHIncrByFloat"))527 assert.NoError(t, err)528 assert.NotNil(t, txn)529 assert.NotNil(t, hash)530 hash.HSet([]byte("TestHashHIncrByFloat"), []byte("10.50"))531 txn.Commit(context.TODO())532 type args struct {533 field []byte534 v float64535 }536 tests := []struct {537 name string538 args args539 want float64540 }{541 {542 name: "TestHashHIncrByFloat",543 args: args{544 field: []byte("TestHashHIncrByFloat"),545 v: float64(0.1),546 },547 want: float64(10.6),548 },549 {550 name: "TestHashHIncrByFloat2",551 args: args{552 field: []byte("TestHashHIncrByFloat"),553 v: float64(-5),554 },555 want: float64(5.6),556 },557 }558 for _, tt := range tests {559 t.Run(tt.name, func(t *testing.T) {560 hash, txn, err := getHash(t, []byte("TestHashHIncrByFloat"))561 assert.NoError(t, err)562 assert.NotNil(t, txn)563 assert.NotNil(t, hash)564 got, err := hash.HIncrByFloat(tt.args.field, tt.args.v)565 txn.Commit(context.TODO())566 assert.Equal(t, got, tt.want)567 assert.NoError(t, err)568 })569 }570}571func TestHashHLen(t *testing.T) {572 hash, txn, err := getHash(t, []byte("TestHashHLen"))573 assert.NoError(t, err)574 assert.NotNil(t, txn)575 assert.NotNil(t, hash)576 // hashslot, err := getHash(t, []byte("TestHashSlotHLen"))577 // hashslot.HMSlot(10)578 hash.HSet([]byte("TestHashHlenField1"), []byte("TestHashHlenValue"))579 hash.HSet([]byte("TestHashHlenField2"), []byte("TestHashHlenValue"))580 hash.HSet([]byte("TestHashHlenField3"), []byte("TestHashHlenValue"))581 txn.Commit(context.TODO())582 hashslot, txn, err := getHash(t, []byte("TestHashSlotHLen"))583 assert.NoError(t, err)584 assert.NotNil(t, txn)585 assert.NotNil(t, hashslot)586 // hashslot, err := getHash(t, []byte("TestHashSlotHLen"))587 // hashslot.HMSlot(10)588 hashslot.HSet([]byte("TestHashHlenField1"), []byte("TestHashHlenValue"))589 hashslot.HSet([]byte("TestHashHlenField2"), []byte("TestHashHlenValue"))590 hashslot.HSet([]byte("TestHashHlenField3"), []byte("TestHashHlenValue"))591 txn.Commit(context.TODO())592 // hashslot.HSet([]byte("TestHashslotHlenField1"), []byte("TestHashHlenValue"))593 // hashslot.HSet([]byte("TestHashslotHlenField2"), []byte("TestHashHlenValue"))594 // hashslot.HSet([]byte("TestHashslotHlenField3"), []byte("TestHashHlenValue"))595 tests := []struct {596 name string597 want int64598 }{599 {600 name: "TestHashHLen",601 want: 3,602 },603 }604 for _, tt := range tests {605 t.Run(tt.name, func(t *testing.T) {606 hash, txn, err := getHash(t, []byte("TestHashHLen"))607 assert.NoError(t, err)608 assert.NotNil(t, txn)609 assert.NotNil(t, hash)610 got, err := hash.HLen()611 txn.Commit(context.TODO())612 assert.Equal(t, got, tt.want)613 assert.NoError(t, err)614 hashslot, txn, err := getHash(t, []byte("TestHashSlotHLen"))615 assert.NoError(t, err)616 assert.NotNil(t, txn)617 assert.NotNil(t, hashslot)618 got1, err := hashslot.HLen()619 txn.Commit(context.TODO())620 assert.Equal(t, got1, tt.want)621 assert.NoError(t, err)622 })623 }624}625func TestHash_HScan(t *testing.T) {626 hash, txn, err := getHash(t, []byte("TestHashHScan"))627 assert.NoError(t, err)628 assert.NotNil(t, txn)629 assert.NotNil(t, hash)630 hash.HSet([]byte("TestHashHScanFiled1"), []byte("TestHashHScanValue1"))631 hash.HSet([]byte("TestHashHScanFiled2"), []byte("TestHashHScanValue2"))632 hash.HSet([]byte("TestHashHScanFiled3"), []byte("TestHashHScanValue3"))633 txn.Commit(context.TODO())634 type args struct {635 cursor []byte636 f func(key, val []byte) bool637 }638 var value [][]byte639 count := 2640 tests := []struct {641 name string642 args args643 want [][]byte644 }{645 {646 name: "TestHashHScan",647 args: args{648 cursor: []byte("TestHashHScanFiled"),649 f: func(key, val []byte) bool {650 if count == 0 {651 return false652 }653 value = append(value, key, val)654 count--655 return true656 },657 },658 want: append(value, []byte("TestHashHScanFiled1"), []byte("TestHashHScanValue1"), []byte("TestHashHScanFiled2"), []byte("TestHashHScanValue2")),659 },660 }661 for _, tt := range tests {662 t.Run(tt.name, func(t *testing.T) {663 hash, txn, err := getHash(t, []byte("TestHashHScan"))664 assert.NoError(t, err)665 assert.NotNil(t, txn)666 assert.NotNil(t, hash)667 err = hash.HScan(tt.args.cursor, tt.args.f)668 txn.Commit(context.TODO())669 assert.Equal(t, value, tt.want)670 assert.NoError(t, err)671 })672 }673}674func TestHash_HMGet(t *testing.T) {675 hash, txn, err := getHash(t, []byte("TestHashHMGet"))676 assert.NoError(t, err)677 assert.NotNil(t, txn)678 assert.NotNil(t, hash)679 hash.HSet([]byte("TestHashHMGetFiled1"), []byte("TestHashHGetValue1"))680 hash.HSet([]byte("TestHashHMGetFiled2"), []byte("TestHashHGetValue2"))681 hash.HSet([]byte("TestHashHMGetFiled3"), []byte("TestHashHGetValue3"))682 txn.Commit(context.TODO())683 var fields [][]byte684 var value [][]byte685 fields = append(fields, []byte("TestHashHMGetFiled1"))686 fields = append(fields, []byte("TestHashHMGetFiled2"))687 fields = append(fields, []byte("TestHashHMGetFiled3"))688 value = append(value, []byte("TestHashHGetValue1"))689 value = append(value, []byte("TestHashHGetValue2"))690 value = append(value, []byte("TestHashHGetValue3"))691 type args struct {692 fields [][]byte693 }694 tests := []struct {695 name string696 args args697 want [][]byte698 }{699 {700 name: "TestHashHMGet",701 args: args{702 fields: fields,703 },704 want: value,705 },706 }707 for _, tt := range tests {708 t.Run(tt.name, func(t *testing.T) {709 hash, txn, err := getHash(t, []byte("TestHashHMGet"))710 assert.NoError(t, err)711 assert.NotNil(t, txn)712 assert.NotNil(t, hash)713 got, err := hash.HMGet(tt.args.fields)714 txn.Commit(context.TODO())715 assert.Equal(t, got, tt.want)716 assert.NoError(t, err)717 })718 }719}720func TestHashHMSet(t *testing.T) {721 var fields [][]byte722 var value [][]byte723 fields = append(fields, []byte("TestHashHMSetFiled1"))724 fields = append(fields, []byte("TestHashHMSetFiled2"))725 fields = append(fields, []byte("TestHashHMSetFiled3"))726 value = append(value, []byte("TestHashHSetValue1"))727 value = append(value, []byte("TestHashHSetValue2"))728 value = append(value, []byte("TestHashHSetValue3"))729 type args struct {730 fields [][]byte731 values [][]byte732 }733 type want struct {734 value [][]byte735 len int64736 }737 tests := []struct {738 name string739 args args740 want want741 }{742 {743 name: "TestHashHMSet",744 args: args{745 fields: fields,746 values: value,747 },748 want: want{749 value: value,750 len: int64(3),751 },752 },753 }754 for _, tt := range tests {755 t.Run(tt.name, func(t *testing.T) {756 hash, txn, err := getHash(t, []byte("TestHashHMSet"))757 assert.NoError(t, err)758 assert.NotNil(t, txn)759 assert.NotNil(t, hash)760 err = hash.HMSet(tt.args.fields, tt.args.values)761 assert.NoError(t, err)762 txn.Commit(context.TODO())763 got, err := hash.HMGet(fields)764 assert.Equal(t, got, tt.want.value)765 assert.NoError(t, err)766 })767 }768}769func TestHashExpired(t *testing.T) {770 setExpireAt := func(t *testing.T, key []byte, expireAt int64) []byte {771 hash, txn, err := getHash(t, key)772 assert.NoError(t, err)773 assert.NotNil(t, txn)774 assert.NotNil(t, hash)775 id := hash.meta.Object.ID776 hash.meta.Object.ExpireAt = expireAt777 hash.HSet([]byte("TestHashExpiredfield"), []byte("TestHashExpiredval"))778 txn.Commit(context.TODO())779 return id780 }781 ts := Now()782 type args struct {783 key []byte784 expireAt int64785 }786 tests := []struct {787 name string788 args args789 want bool790 }{791 {792 name: "TestHashExpired",793 args: args{794 key: []byte("TestHashExpired"),795 expireAt: ts - 3*int64(time.Second),796 },797 want: false,798 },799 {800 name: "TestHashNotExpired",801 args: args{802 key: []byte("TestHashNotExpired"),803 expireAt: ts + 10*int64(time.Second),804 },805 want: true,806 },807 }808 for _, tt := range tests {809 t.Run(tt.name, func(t *testing.T) {810 oldID := setExpireAt(t, tt.args.key, tt.args.expireAt)811 hash, txn, err := getHash(t, tt.args.key)812 assert.NoError(t, err)813 assert.NotNil(t, txn)814 assert.NotNil(t, hash)815 newID := hash.meta.Object.ID816 txn.Commit(context.TODO())817 if tt.want {818 assert.Equal(t, newID, oldID)819 } else {820 assert.NotEqual(t, newID, oldID)821 }822 })823 }824}...
queuebrowser_test.go
Source:queuebrowser_test.go
...47 }48 assert.Nil(t, errCons)49 msgIterator, err := browser.GetEnumeration()50 assert.Nil(t, err)51 assert.NotNil(t, msgIterator)52 // Asking for a second Enumeration from the same Browser returns the53 // same object (only one Enumeration per Browser)54 msgIteratorSame, err := browser.GetEnumeration()55 assert.Equal(t, &msgIterator, &msgIteratorSame)56 gotMsg1, gotErr1 := msgIterator.GetNext()57 assert.Nil(t, gotErr1)58 assert.NotNil(t, gotMsg1)59 assert.Equal(t, msg1.GetJMSMessageID(), gotMsg1.GetJMSMessageID())60 gotMsg2, gotErr2 := msgIterator.GetNext()61 assert.Nil(t, gotErr2)62 assert.NotNil(t, gotMsg2)63 assert.Equal(t, msg2.GetJMSMessageID(), gotMsg2.GetJMSMessageID())64 gotMsg3, gotErr3 := msgIterator.GetNext()65 assert.Nil(t, gotErr3)66 assert.NotNil(t, gotMsg3)67 assert.Equal(t, msg3.GetJMSMessageID(), gotMsg3.GetJMSMessageID())68 // No more messages left.69 gotMsg4, gotErr4 := msgIterator.GetNext()70 assert.Nil(t, gotErr4)71 assert.Nil(t, gotMsg4)72 // Now use a second browser to confirm that the messages were not73 // destructively consumed.74 browser2, errCons := context.CreateBrowser(queue)75 if browser2 != nil {76 defer browser2.Close()77 }78 assert.Nil(t, errCons)79 msgIterator2, err := browser2.GetEnumeration()80 assert.Nil(t, err)81 assert.NotNil(t, msgIterator)82 gotMsg1, gotErr1 = msgIterator2.GetNext()83 assert.Nil(t, gotErr1)84 assert.NotNil(t, gotMsg1) // Failure here shows messages were destructively consumed85 assert.Equal(t, msg1.GetJMSMessageID(), gotMsg1.GetJMSMessageID())86 gotMsg2, gotErr2 = msgIterator2.GetNext()87 assert.Nil(t, gotErr2)88 assert.NotNil(t, gotMsg2)89 assert.Equal(t, msg2.GetJMSMessageID(), gotMsg2.GetJMSMessageID())90 gotMsg3, gotErr3 = msgIterator2.GetNext()91 assert.Nil(t, gotErr3)92 assert.NotNil(t, gotMsg3)93 assert.Equal(t, msg3.GetJMSMessageID(), gotMsg3.GetJMSMessageID())94 // No more messages left.95 gotMsg4, gotErr4 = msgIterator2.GetNext()96 assert.Nil(t, gotErr4)97 assert.Nil(t, gotMsg4)98 // Tidy up the messages by destructively consuming them with a99 // real Consumer.100 consumer, errCons := context.CreateConsumer(queue)101 if consumer != nil {102 defer consumer.Close()103 }104 assert.Nil(t, errCons)105 gotMsg1, gotErr1 = consumer.ReceiveNoWait()106 assert.Nil(t, gotErr1)107 assert.NotNil(t, gotMsg1)108 assert.Equal(t, msg1.GetJMSMessageID(), gotMsg1.GetJMSMessageID())109 gotMsg2, gotErr2 = consumer.ReceiveNoWait()110 assert.Nil(t, gotErr2)111 assert.NotNil(t, gotMsg2)112 assert.Equal(t, msg2.GetJMSMessageID(), gotMsg2.GetJMSMessageID())113 gotMsg3, gotErr3 = consumer.ReceiveNoWait()114 assert.Nil(t, gotErr3)115 assert.NotNil(t, gotMsg3)116 assert.Equal(t, msg3.GetJMSMessageID(), gotMsg3.GetJMSMessageID())117 // No more messages left.118 gotMsg4, gotErr4 = consumer.ReceiveNoWait()119 assert.Nil(t, gotErr4)120 assert.Nil(t, gotMsg4)121}122/*123 * Test that QueueBrowser provides a live view of the messages on a queue,124 * including if more are added after the browsing begins.125 */126func TestQueueBrowserWhilePutting(t *testing.T) {127 // Loads CF parameters from connection_info.json and applicationApiKey.json in the Downloads directory128 cf, cfErr := mqjms.CreateConnectionFactoryFromDefaultJSONFiles()129 assert.Nil(t, cfErr)130 // Creates a connection to the queue manager, using defer to close it automatically131 // at the end of the function (if it was created successfully)132 context, ctxErr := cf.CreateContext()133 assert.Nil(t, ctxErr)134 if context != nil {135 defer context.Close()136 }137 // Browse for the messages that we put onto the queue.138 queue := context.CreateQueue("DEV.QUEUE.1")139 browser, errCons := context.CreateBrowser(queue)140 if browser != nil {141 defer browser.Close()142 }143 assert.Nil(t, errCons)144 msgIterator, err := browser.GetEnumeration()145 assert.Nil(t, err)146 assert.NotNil(t, msgIterator)147 // Not currently any messages on the queue.148 gotPreMsg, gotPreErr := msgIterator.GetNext()149 assert.Nil(t, gotPreErr)150 assert.Nil(t, gotPreMsg) // no message151 // Create and send some TextMessages152 producer := context.CreateProducer().SetTimeToLive(20000)153 msg1 := context.CreateTextMessageWithString("browser msg 1")154 msg2 := context.CreateTextMessageWithString("browser msg 2")155 msg3 := context.CreateTextMessageWithString("browser msg 3")156 errSend := producer.Send(queue, msg1)157 assert.Nil(t, errSend)158 errSend = producer.Send(queue, msg2)159 assert.Nil(t, errSend)160 errSend = producer.Send(queue, msg3)161 assert.Nil(t, errSend)162 gotMsg1, gotErr1 := msgIterator.GetNext()163 assert.Nil(t, gotErr1)164 assert.NotNil(t, gotMsg1)165 assert.Equal(t, msg1.GetJMSMessageID(), gotMsg1.GetJMSMessageID())166 gotMsg2, gotErr2 := msgIterator.GetNext()167 assert.Nil(t, gotErr2)168 assert.NotNil(t, gotMsg2)169 assert.Equal(t, msg2.GetJMSMessageID(), gotMsg2.GetJMSMessageID())170 gotMsg3, gotErr3 := msgIterator.GetNext()171 assert.Nil(t, gotErr3)172 assert.NotNil(t, gotMsg3)173 assert.Equal(t, msg3.GetJMSMessageID(), gotMsg3.GetJMSMessageID())174 // No more messages left.175 gotMsg4, gotErr4 := msgIterator.GetNext()176 assert.Nil(t, gotErr4)177 assert.Nil(t, gotMsg4)178 // Send some more messages179 msg4 := context.CreateTextMessageWithString("browser msg 4")180 msg5 := context.CreateTextMessageWithString("browser msg 5")181 errSend = producer.Send(queue, msg4)182 assert.Nil(t, errSend)183 errSend = producer.Send(queue, msg5)184 assert.Nil(t, errSend)185 gotMsg4, gotErr4 = msgIterator.GetNext()186 assert.Nil(t, gotErr4)187 assert.NotNil(t, gotMsg4)188 assert.Equal(t, msg4.GetJMSMessageID(), gotMsg4.GetJMSMessageID())189 gotMsg5, gotErr5 := msgIterator.GetNext()190 assert.Nil(t, gotErr5)191 assert.NotNil(t, gotMsg5)192 assert.Equal(t, msg5.GetJMSMessageID(), gotMsg5.GetJMSMessageID())193 // No more messages left.194 gotMsg6, gotErr6 := msgIterator.GetNext()195 assert.Nil(t, gotErr6)196 assert.Nil(t, gotMsg6)197 // Tidy up the messages by destructively consuming them with a198 // real Consumer.199 consumer, errCons := context.CreateConsumer(queue)200 if consumer != nil {201 defer consumer.Close()202 }203 assert.Nil(t, errCons)204 gotMsg1, gotErr1 = consumer.ReceiveNoWait()205 assert.Nil(t, gotErr1)206 assert.NotNil(t, gotMsg1)207 assert.Equal(t, msg1.GetJMSMessageID(), gotMsg1.GetJMSMessageID())208 gotMsg2, gotErr2 = consumer.ReceiveNoWait()209 assert.Nil(t, gotErr2)210 assert.NotNil(t, gotMsg2)211 assert.Equal(t, msg2.GetJMSMessageID(), gotMsg2.GetJMSMessageID())212 gotMsg3, gotErr3 = consumer.ReceiveNoWait()213 assert.Nil(t, gotErr3)214 assert.NotNil(t, gotMsg3)215 assert.Equal(t, msg3.GetJMSMessageID(), gotMsg3.GetJMSMessageID())216 gotMsg4, gotErr4 = consumer.ReceiveNoWait()217 assert.Nil(t, gotErr4)218 assert.NotNil(t, gotMsg4)219 assert.Equal(t, msg4.GetJMSMessageID(), gotMsg4.GetJMSMessageID())220 gotMsg5, gotErr5 = consumer.ReceiveNoWait()221 assert.Nil(t, gotErr5)222 assert.NotNil(t, gotMsg5)223 assert.Equal(t, msg5.GetJMSMessageID(), gotMsg5.GetJMSMessageID())224 // No more messages left.225 gotMsg6, gotErr6 = consumer.ReceiveNoWait()226 assert.Nil(t, gotErr6)227 assert.Nil(t, gotMsg6)228}229/*230 * Test that QueueBrowser provides a live view of the messages on a queue,231 * including if messages are removed after the browsing begins.232 */233func TestQueueBrowserWhileGetting(t *testing.T) {234 // Loads CF parameters from connection_info.json and applicationApiKey.json in the Downloads directory235 cf, cfErr := mqjms.CreateConnectionFactoryFromDefaultJSONFiles()236 assert.Nil(t, cfErr)237 // Creates a connection to the queue manager, using defer to close it automatically238 // at the end of the function (if it was created successfully)239 context, ctxErr := cf.CreateContext()240 assert.Nil(t, ctxErr)241 if context != nil {242 defer context.Close()243 }244 // Create and send some TextMessages245 queue := context.CreateQueue("DEV.QUEUE.1")246 producer := context.CreateProducer().SetTimeToLive(20000)247 msg1 := context.CreateTextMessageWithString("browser msg 1")248 errSend := producer.Send(queue, msg1)249 assert.Nil(t, errSend)250 // Create a real consumer ready to destructively consume messages.251 consumer, errCons := context.CreateConsumer(queue)252 if consumer != nil {253 defer consumer.Close()254 }255 assert.Nil(t, errCons)256 // Browse for the messages that we put onto the queue.257 browser, errCons := context.CreateBrowser(queue)258 if browser != nil {259 defer browser.Close()260 }261 assert.Nil(t, errCons)262 msgIterator, err := browser.GetEnumeration()263 assert.Nil(t, err)264 assert.NotNil(t, msgIterator)265 // Destructively consume the (one) message we had put.266 gotMsg1, gotErr1 := consumer.ReceiveNoWait()267 assert.Nil(t, gotErr1)268 assert.NotNil(t, gotMsg1)269 assert.Equal(t, msg1.GetJMSMessageID(), gotMsg1.GetJMSMessageID())270 // Not currently any messages on the queue.271 gotPreMsg, gotPreErr := msgIterator.GetNext()272 assert.Nil(t, gotPreErr)273 assert.Nil(t, gotPreMsg) // no message274 // Create and send some TextMessages275 msg2 := context.CreateTextMessageWithString("browser msg 2")276 msg3 := context.CreateTextMessageWithString("browser msg 3")277 msg4 := context.CreateTextMessageWithString("browser msg 4")278 msg5 := context.CreateTextMessageWithString("browser msg 5")279 msg6 := context.CreateTextMessageWithString("browser msg 6")280 errSend = producer.Send(queue, msg2)281 assert.Nil(t, errSend)282 errSend = producer.Send(queue, msg3)283 assert.Nil(t, errSend)284 errSend = producer.Send(queue, msg4)285 assert.Nil(t, errSend)286 errSend = producer.Send(queue, msg5)287 assert.Nil(t, errSend)288 errSend = producer.Send(queue, msg6)289 assert.Nil(t, errSend)290 // Browse a few messages291 gotMsg2, gotErr2 := msgIterator.GetNext()292 assert.Nil(t, gotErr2)293 assert.NotNil(t, gotMsg2)294 assert.Equal(t, msg2.GetJMSMessageID(), gotMsg2.GetJMSMessageID())295 gotMsg3, gotErr3 := msgIterator.GetNext()296 assert.Nil(t, gotErr3)297 assert.NotNil(t, gotMsg3)298 assert.Equal(t, msg3.GetJMSMessageID(), gotMsg3.GetJMSMessageID())299 gotMsg4, gotErr4 := msgIterator.GetNext()300 assert.Nil(t, gotErr4)301 assert.NotNil(t, gotMsg4)302 assert.Equal(t, msg4.GetJMSMessageID(), gotMsg4.GetJMSMessageID())303 // Now destructively read a couple of messages "behind" the browser304 gotMsg2, gotErr2 = consumer.ReceiveNoWait()305 assert.Nil(t, gotErr2)306 assert.NotNil(t, gotMsg2)307 assert.Equal(t, msg2.GetJMSMessageID(), gotMsg2.GetJMSMessageID())308 gotMsg3, gotErr3 = consumer.ReceiveNoWait()309 assert.Nil(t, gotErr3)310 assert.NotNil(t, gotMsg3)311 assert.Equal(t, msg3.GetJMSMessageID(), gotMsg3.GetJMSMessageID())312 // Browse another message313 gotMsg5, gotErr5 := msgIterator.GetNext()314 assert.Nil(t, gotErr5)315 assert.NotNil(t, gotMsg5)316 assert.Equal(t, msg5.GetJMSMessageID(), gotMsg5.GetJMSMessageID())317 // Put a few more messages318 msg7 := context.CreateTextMessageWithString("browser msg 7")319 msg8 := context.CreateTextMessageWithString("browser msg 8")320 msg9 := context.CreateTextMessageWithString("browser msg 9")321 msg10 := context.CreateTextMessageWithString("browser msg 10")322 errSend = producer.Send(queue, msg7)323 assert.Nil(t, errSend)324 errSend = producer.Send(queue, msg8)325 assert.Nil(t, errSend)326 errSend = producer.Send(queue, msg9)327 assert.Nil(t, errSend)328 errSend = producer.Send(queue, msg10)329 assert.Nil(t, errSend)330 // Browse another message331 gotMsg6, gotErr6 := msgIterator.GetNext()332 assert.Nil(t, gotErr6)333 assert.NotNil(t, gotMsg6)334 assert.Equal(t, msg6.GetJMSMessageID(), gotMsg6.GetJMSMessageID())335 // Destructively consume a few more336 gotMsg4, gotErr4 = consumer.ReceiveNoWait()337 assert.Nil(t, gotErr4)338 assert.NotNil(t, gotMsg4)339 assert.Equal(t, msg4.GetJMSMessageID(), gotMsg4.GetJMSMessageID())340 gotMsg5, gotErr5 = consumer.ReceiveNoWait()341 assert.Nil(t, gotErr5)342 assert.NotNil(t, gotMsg5)343 assert.Equal(t, msg5.GetJMSMessageID(), gotMsg5.GetJMSMessageID())344 // Browse another message345 gotMsg7, gotErr7 := msgIterator.GetNext()346 assert.Nil(t, gotErr7)347 assert.NotNil(t, gotMsg7)348 assert.Equal(t, msg7.GetJMSMessageID(), gotMsg7.GetJMSMessageID())349 // Destructively consume a message from the "middle" of the queue350 // by using its MessageID.351 selectorStr := "JMSMessageID = '" + msg9.GetJMSMessageID() + "'"352 msgIdConsumer, errCons := context.CreateConsumerWithSelector(queue, selectorStr)353 if msgIdConsumer != nil {354 defer msgIdConsumer.Close()355 }356 assert.Nil(t, errCons)357 gotMsg9, gotErr9 := msgIdConsumer.ReceiveNoWait()358 assert.Nil(t, gotErr9)359 assert.NotNil(t, gotMsg9)360 assert.Equal(t, msg9.GetJMSMessageID(), gotMsg9.GetJMSMessageID())361 // Put more messages362 msg11 := context.CreateTextMessageWithString("browser msg 11")363 msg12 := context.CreateTextMessageWithString("browser msg 12")364 msg13 := context.CreateTextMessageWithString("browser msg 13")365 errSend = producer.Send(queue, msg11)366 assert.Nil(t, errSend)367 errSend = producer.Send(queue, msg12)368 assert.Nil(t, errSend)369 errSend = producer.Send(queue, msg13)370 assert.Nil(t, errSend)371 // Browse over the "missing middle" (msg9)372 gotMsg8, gotErr8 := msgIterator.GetNext()373 assert.Nil(t, gotErr8)374 assert.NotNil(t, gotMsg8)375 assert.Equal(t, msg8.GetJMSMessageID(), gotMsg8.GetJMSMessageID())376 // not 9377 gotMsg10, gotErr10 := msgIterator.GetNext()378 assert.Nil(t, gotErr10)379 assert.NotNil(t, gotMsg10)380 assert.Equal(t, msg10.GetJMSMessageID(), gotMsg10.GetJMSMessageID())381 // Destructively consume "past" the browser382 gotMsg6, gotErr6 = consumer.ReceiveNoWait()383 assert.Nil(t, gotErr6)384 assert.NotNil(t, gotMsg6)385 assert.Equal(t, msg6.GetJMSMessageID(), gotMsg6.GetJMSMessageID())386 gotMsg7, gotErr7 = consumer.ReceiveNoWait()387 assert.Nil(t, gotErr7)388 assert.NotNil(t, gotMsg7)389 assert.Equal(t, msg7.GetJMSMessageID(), gotMsg7.GetJMSMessageID())390 gotMsg8, gotErr8 = consumer.ReceiveNoWait()391 assert.Nil(t, gotErr8)392 assert.NotNil(t, gotMsg8)393 assert.Equal(t, msg8.GetJMSMessageID(), gotMsg8.GetJMSMessageID())394 // Not 9395 gotMsg10, gotErr10 = consumer.ReceiveNoWait()396 assert.Nil(t, gotErr10)397 assert.NotNil(t, gotMsg10)398 assert.Equal(t, msg10.GetJMSMessageID(), gotMsg10.GetJMSMessageID())399 gotMsg11, gotErr11 := consumer.ReceiveNoWait()400 assert.Nil(t, gotErr11)401 assert.NotNil(t, gotMsg11)402 assert.Equal(t, msg11.GetJMSMessageID(), gotMsg11.GetJMSMessageID())403 // Browse another message404 // 11 got consumed before being browsed, so next is 12.405 gotMsg12, gotErr12 := msgIterator.GetNext()406 assert.Nil(t, gotErr12)407 assert.NotNil(t, gotMsg12)408 assert.Equal(t, msg12.GetJMSMessageID(), gotMsg12.GetJMSMessageID())409 // Destructively consume 12 + 13410 gotMsg12, gotErr12 = consumer.ReceiveNoWait()411 assert.Nil(t, gotErr12)412 assert.NotNil(t, gotMsg12)413 assert.Equal(t, msg12.GetJMSMessageID(), gotMsg12.GetJMSMessageID())414 gotMsg13, gotErr13 := consumer.ReceiveNoWait()415 assert.Nil(t, gotErr13)416 assert.NotNil(t, gotMsg13)417 assert.Equal(t, msg13.GetJMSMessageID(), gotMsg13.GetJMSMessageID())418 // No more messages left.419 gotMsg13, gotErr13 = msgIterator.GetNext()420 assert.Nil(t, gotErr13)421 assert.Nil(t, gotMsg13)422 // No more messages left to descructively consume.423 gotMsg14, gotErr14 := consumer.ReceiveNoWait()424 assert.Nil(t, gotErr14)425 assert.Nil(t, gotMsg14)426}...
NotNil
Using AI Code Generation
1import (2func TestNil(t *testing.T) {3 assert.Nil(t, s)4 s = new(string)5 assert.NotNil(t, s)6 fmt.Println("Nil test case passed")7}
NotNil
Using AI Code Generation
1import (2func TestNil(t *testing.T) {3 assert.Nil(t, a)4}5func TestNotNil(t *testing.T) {6 assert.NotNil(t, a)7}
NotNil
Using AI Code Generation
1import (2func TestNotNil(t *testing.T) {3 if a != 0 {4 fmt.Println("a is not nil")5 } else {6 fmt.Println("a is nil")7 }8}
NotNil
Using AI Code Generation
1import (2func TestSomething(t *testing.T) {3 assert.NotNil(t, "Hello", "Not nil")4}5import (6func TestSomething(t *testing.T) {7 assert.Nil(t, nil, "Nil")8}9import (10func TestSomething(t *testing.T) {11 assert.True(t, true, "True")12}13import (14func TestSomething(t *testing.T) {15 assert.False(t, false, "False")16}17import (18func TestSomething(t *testing.T) {19 assert.Equal(t, "Hello", "Hello", "Equal")20}21import (22func TestSomething(t *testing.T) {23 assert.NotEqual(t, "Hello", "Hi", "Not Equal")24}25import (26func TestSomething(t *testing.T) {27 assert.Empty(t, "", "Empty")28}29import (30func TestSomething(t *testing.T) {31 assert.NotEmpty(t, "Hello", "Not Empty")32}33import (34func TestSomething(t *testing.T) {35 assert.Contains(t, "Hello", "ll", "Contains")36}37import (
NotNil
Using AI Code Generation
1import (2func TestNil(t *testing.T) {3 assert.NotNil(t, 1)4}5func main() {6 fmt.Println("Hello, playground")7}
NotNil
Using AI Code Generation
1import (2func TestNil(t *testing.T) {3 assert.Nil(t, a)4 fmt.Println("a is nil")5}6func TestNotNil(t *testing.T) {7 assert.NotNil(t, a)8 fmt.Println("a is not nil")9}
NotNil
Using AI Code Generation
1import (2func TestNotNil(t *testing.T) {3 var i interface{}4 if i == nil {5 t.Error("interface is nil")6 }7}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!