How to use Occurrence method of diff Package

Best Got code snippet using diff.Occurrence

storage.go

Source:storage.go Github

copy

Full Screen

...141 if _, err := g.CreateNote(ctx, nPID2, testNoteID, "userID", n2); err != nil {142 t.Errorf("CreateNote got %v want success", err)143 }144 })145 t.Run("CreateOccurrence", func(t *testing.T) {146 g, gp, cleanUp := createStore(t)147 defer cleanUp()148 ctx := context.Background()149 nPID := "vulnerability-scanner-a"150 if _, err := gp.CreateProject(ctx, nPID, &prpb.Project{}); err != nil {151 t.Errorf("CreateProject got %v want success", err)152 }153 n := createTestNote(nPID)154 if _, err := g.CreateNote(ctx, nPID, testNoteID, "userID", n); err != nil {155 t.Errorf("CreateNote got %v want success", err)156 }157 oPID := "occurrence-project"158 o := createTestOccurrence(oPID, n.Name)159 oo, err := g.CreateOccurrence(ctx, oPID, "userID", o)160 if err != nil {161 t.Errorf("CreateOccurrence got %v want success", err)162 }163 pID, oID, err := name.ParseOccurrence(oo.Name)164 if err != nil {165 t.Fatalf("Error parsing projectID and occurrenceID %v", err)166 }167 got, err := g.GetOccurrence(ctx, pID, oID)168 if err != nil {169 t.Fatalf("GetOccurrence got %v, want success", err)170 }171 if diff := cmp.Diff(got, oo, opt); diff != "" {172 t.Errorf("GetOccurrence returned diff (want -> got):\n%s", diff)173 }174 })175 t.Run("CreateSameOccurrenceTwice", func(t *testing.T) {176 g, gp, cleanUp := createStore(t)177 defer cleanUp()178 ctx := context.Background()179 nPID := "vulnerability-scanner-a"180 if _, err := gp.CreateProject(ctx, nPID, &prpb.Project{}); err != nil {181 t.Errorf("CreateProject got %v want success", err)182 }183 n := createTestNote(nPID)184 if _, err := g.CreateNote(ctx, nPID, testNoteID, "userID", n); err != nil {185 t.Errorf("CreateNote got %v want success", err)186 }187 oPID := "occurrence-project"188 o := createTestOccurrence(oPID, n.Name)189 if _, err := g.CreateOccurrence(ctx, nPID, "userID", o); err != nil {190 t.Errorf("CreateOccurrence got %v want success", err)191 }192 // Try to insert the same occurrence twice, expect success, because different IDs are generated.193 if _, err := g.CreateOccurrence(ctx, nPID, "userID", o); err != nil {194 t.Errorf("CreateOccurrence got %v, want success", err)195 }196 })197 t.Run("DeleteProject", func(t *testing.T) {198 _, gp, cleanUp := createStore(t)199 defer cleanUp()200 ctx := context.Background()201 pID := "myproject"202 // Delete before the project exists203 if err := gp.DeleteProject(ctx, pID); err == nil {204 t.Error("Deleting nonexistant note got success, want error")205 }206 if _, err := gp.CreateProject(ctx, pID, &prpb.Project{}); err != nil {207 t.Fatalf("CreateProject got %v want success", err)208 }209 if err := gp.DeleteProject(ctx, pID); err != nil {210 t.Errorf("DeleteProject got %v, want success ", err)211 }212 })213 t.Run("DeleteOccurrence", func(t *testing.T) {214 g, gp, cleanUp := createStore(t)215 defer cleanUp()216 ctx := context.Background()217 nPID := "vulnerability-scanner-a"218 if _, err := gp.CreateProject(ctx, nPID, &prpb.Project{}); err != nil {219 t.Errorf("CreateProject got %v want success", err)220 }221 n := createTestNote(nPID)222 if _, err := g.CreateNote(ctx, nPID, testNoteID, "userID", n); err != nil {223 t.Fatalf("CreateNote got %v want success", err)224 }225 oPID := "occurrence-project"226 o := createTestOccurrence(oPID, n.Name)227 oo, err := g.CreateOccurrence(ctx, oPID, "userID", o)228 if err != nil {229 t.Fatalf("CreateOccurrence got %v want success", err)230 }231 pID, oID, err := name.ParseOccurrence(oo.Name)232 if err != nil {233 t.Fatalf("Error parsing occurrence %v", err)234 }235 if err := g.DeleteOccurrence(ctx, pID, oID); err != nil {236 t.Errorf("DeleteOccurrence got %v, want success ", err)237 }238 })239 t.Run("UpdateOccurrence", func(t *testing.T) {240 g, gp, cleanUp := createStore(t)241 defer cleanUp()242 ctx := context.Background()243 nPID := "vulnerability-scanner-a"244 if _, err := gp.CreateProject(ctx, nPID, &prpb.Project{}); err != nil {245 t.Errorf("CreateProject got %v want success", err)246 }247 n := createTestNote(nPID)248 if _, err := g.CreateNote(ctx, nPID, testNoteID, "userID", n); err != nil {249 t.Fatalf("CreateNote got %v want success", err)250 }251 oPID := "occurrence-project"252 o := createTestOccurrence(oPID, n.Name)253 oo, err := g.CreateOccurrence(ctx, oPID, "userID", o)254 if err != nil {255 t.Fatalf("CreateOccurrence got %v want success", err)256 }257 pID, oID, err := name.ParseOccurrence(oo.Name)258 if err != nil {259 t.Fatalf("Error parsing projectID and occurrenceID %v", err)260 }261 got, err := g.GetOccurrence(ctx, pID, oID)262 if err != nil {263 t.Fatalf("GetOccurrence got %v, want success", err)264 }265 if diff := cmp.Diff(got, oo, opt); diff != "" {266 t.Errorf("GetOccurrence returned diff (want -> got):\n%s", diff)267 }268 o2 := oo269 o2.GetVulnerability().CvssScore = 1.0270 // TODO(#312): check the result of the update271 // TODO(#312): use fieldmask in the param272 if _, err := g.UpdateOccurrence(ctx, pID, oID, o2, nil); err != nil {273 t.Fatalf("UpdateOccurrence got %v want success", err)274 }275 got, err = g.GetOccurrence(ctx, pID, oID)276 if err != nil {277 t.Fatalf("GetOccurrence got %v, want success", err)278 }279 if diff := cmp.Diff(got, o2, opt); diff != "" {280 t.Errorf("GetOccurrence returned diff (want -> got):\n%s", diff)281 }282 })283 t.Run("DeleteNote", func(t *testing.T) {284 g, gp, cleanUp := createStore(t)285 defer cleanUp()286 ctx := context.Background()287 nPID := "vulnerability-scanner-a"288 if _, err := gp.CreateProject(ctx, nPID, &prpb.Project{}); err != nil {289 t.Errorf("CreateProject got %v want success", err)290 }291 n := createTestNote(nPID)292 // Delete before the note exists293 pID, nID, err := name.ParseNote(n.Name)294 if err != nil {295 t.Fatalf("Error parsing note %v", err)296 }297 if err := g.DeleteNote(ctx, pID, nID); err == nil {298 t.Error("Deleting nonexistent note got success, want error")299 }300 if _, err := g.CreateNote(ctx, pID, nID, "userID", n); err != nil {301 t.Fatalf("CreateNote got %v want success", err)302 }303 if err := g.DeleteNote(ctx, pID, nID); err != nil {304 t.Errorf("DeleteNote got %v, want success ", err)305 }306 })307 t.Run("UpdateNote", func(t *testing.T) {308 g, gp, cleanUp := createStore(t)309 defer cleanUp()310 ctx := context.Background()311 nPID := "vulnerability-scanner-a"312 if _, err := gp.CreateProject(ctx, nPID, &prpb.Project{}); err != nil {313 t.Errorf("CreateProject got %v want success", err)314 }315 n := createTestNote(nPID)316 pID, nID, err := name.ParseNote(n.Name)317 if err != nil {318 t.Fatalf("Error parsing projectID and noteID %v", err)319 }320 if _, err := g.UpdateNote(ctx, pID, nID, n, nil); err == nil {321 t.Fatal("UpdateNote got success want error")322 }323 if _, err := g.CreateNote(ctx, pID, nID, "userID", n); err != nil {324 t.Fatalf("CreateNote got %v want success", err)325 }326 got, err := g.GetNote(ctx, pID, nID)327 if err != nil {328 t.Fatalf("GetNote got %v, want success", err)329 }330 if diff := cmp.Diff(got, n, opt); diff != "" {331 t.Errorf("GetNote returned diff (want -> got):\n%s", diff)332 }333 n2 := n334 n2.GetVulnerability().CvssScore = 1.0335 // TODO(#312): check the result of the update336 // TODO(#312): use fieldmask in the param337 if _, err := g.UpdateNote(ctx, pID, nID, n2, nil); err != nil {338 t.Fatalf("UpdateNote got %v want success", err)339 }340 got, err = g.GetNote(ctx, pID, nID)341 if err != nil {342 t.Fatalf("GetNote got %v, want success", err)343 }344 if diff := cmp.Diff(got, n2, opt); diff != "" {345 t.Errorf("GetNote returned diff (want -> got):\n%s", diff)346 }347 })348 t.Run("GetProject", func(t *testing.T) {349 _, gp, cleanUp := createStore(t)350 defer cleanUp()351 ctx := context.Background()352 pID := "myproject"353 // Try to get project before it has been created, expect failure.354 if _, err := gp.GetProject(ctx, pID); err == nil {355 t.Errorf("GetProject got success, want Error")356 } else if s, _ := status.FromError(err); s.Code() != codes.NotFound {357 t.Errorf("GetProject got code %v want %v", s.Code(), codes.NotFound)358 }359 p := &prpb.Project{}360 p.Name = name.FormatProject(pID)361 _, err := gp.CreateProject(ctx, pID, p)362 if err != nil {363 t.Fatalf("CreateProject got %v want success", err)364 }365 if proj, err := gp.GetProject(ctx, pID); err != nil {366 t.Fatalf("GetProject got %v want success", err)367 } else if p.Name != proj.Name {368 t.Fatalf("Got %s want %s", p.Name, pID)369 }370 })371 t.Run("GetOccurrence", func(t *testing.T) {372 g, gp, cleanUp := createStore(t)373 defer cleanUp()374 ctx := context.Background()375 nPID := "vulnerability-scanner-a"376 if _, err := gp.CreateProject(ctx, nPID, &prpb.Project{}); err != nil {377 t.Errorf("CreateProject got %v want success", err)378 }379 n := createTestNote(nPID)380 if _, err := g.CreateNote(ctx, nPID, testNoteID, "userID", n); err != nil {381 t.Fatalf("CreateNote got %v want success", err)382 }383 oPID := "occurrence-project"384 o := createTestOccurrence(oPID, n.Name)385 oo, err := g.CreateOccurrence(ctx, oPID, "userID", o)386 if err != nil {387 t.Errorf("CreateOccurrence got %v, want Success", err)388 }389 pID, oID, err := name.ParseOccurrence(oo.Name)390 if err != nil {391 t.Fatalf("Error parsing occurrence %v", err)392 }393 got, err := g.GetOccurrence(ctx, pID, oID)394 if err != nil {395 t.Fatalf("GetOccurrence got %v, want success", err)396 }397 if diff := cmp.Diff(got, oo, opt); diff != "" {398 t.Errorf("GetOccurrence returned diff (want -> got):\n%s", diff)399 }400 })401 t.Run("GetNote", func(t *testing.T) {402 g, gp, cleanUp := createStore(t)403 defer cleanUp()404 ctx := context.Background()405 nPID := "vulnerability-scanner-a"406 if _, err := gp.CreateProject(ctx, nPID, &prpb.Project{}); err != nil {407 t.Errorf("CreateProject got %v want success", err)408 }409 n := createTestNote(nPID)410 pID, nID, err := name.ParseNote(n.Name)411 if err != nil {412 t.Fatalf("Error parsing note %v", err)413 }414 if _, err := g.GetNote(ctx, pID, nID); err == nil {415 t.Fatal("GetNote got success, want error")416 }417 if _, err := g.CreateNote(ctx, nPID, testNoteID, "userID", n); err != nil {418 t.Errorf("CreateNote got %v, want Success", err)419 }420 got, err := g.GetNote(ctx, pID, nID)421 if err != nil {422 t.Fatalf("GetNote got %v, want success", err)423 }424 if diff := cmp.Diff(got, n, opt); diff != "" {425 t.Errorf("GetNote returned diff (want -> got):\n%s", diff)426 }427 })428 t.Run("GetOccurrenceNote", func(t *testing.T) {429 g, gp, cleanUp := createStore(t)430 defer cleanUp()431 ctx := context.Background()432 nPID := "vulnerability-scanner-a"433 if _, err := gp.CreateProject(ctx, nPID, &prpb.Project{}); err != nil {434 t.Errorf("CreateProject got %v want success", err)435 }436 n := createTestNote(nPID)437 if _, err := g.CreateNote(ctx, nPID, testNoteID, "userID", n); err != nil {438 t.Fatalf("CreateNote got %v want success", err)439 }440 oPID := "occurrence-project"441 o := createTestOccurrence(oPID, n.Name)442 oo, err := g.CreateOccurrence(ctx, oPID, "userID", o)443 if err != nil {444 t.Errorf("CreateOccurrence got %v, want Success", err)445 }446 pID, oID, err := name.ParseOccurrence(oo.Name)447 if err != nil {448 t.Fatalf("Error parsing occurrence %v", err)449 }450 got, err := g.GetOccurrenceNote(ctx, pID, oID)451 if err != nil {452 t.Fatalf("GetOccurrenceNote got %v, want success", err)453 }454 if diff := cmp.Diff(got, n, opt); diff != "" {455 t.Errorf("GetOccurrenceNote returned diff (want -> got):\n%s", diff)456 }457 })458 t.Run("ListProjects", func(t *testing.T) {459 _, gp, cleanUp := createStore(t)460 defer cleanUp()461 ctx := context.Background()462 wantProjectNames := []string{}463 for i := 0; i < 20; i++ {464 pID := fmt.Sprint("Project", i)465 p := &prpb.Project{}466 p.Name = name.FormatProject(pID)467 p, err := gp.CreateProject(ctx, pID, p)468 if err != nil {469 t.Fatalf("CreateProject got %v want success", err)470 }471 wantProjectNames = append(wantProjectNames, p.Name)472 }473 filter := "filters_are_yet_to_be_implemented"474 gotProjects, pageToken, err := gp.ListProjects(ctx, filter, 100, "")475 if err != nil {476 t.Fatalf("ListProjects got %v want success", err)477 }478 if pageToken != "" {479 t.Errorf("Got %s want empty page token", pageToken)480 }481 if len(gotProjects) != 20 {482 t.Errorf("ListProjects got %v projects, want 20", len(gotProjects))483 }484 gotProjectNames := make([]string, len(gotProjects))485 for i, project := range gotProjects {486 gotProjectNames[i] = project.Name487 }488 // Sort to handle that wantProjectNames are not guaranteed to be listed in insertion order489 sort.Strings(wantProjectNames)490 sort.Strings(gotProjectNames)491 if !reflect.DeepEqual(gotProjectNames, wantProjectNames) {492 t.Errorf("ListProjects got %v want %v", gotProjectNames, wantProjectNames)493 }494 })495 t.Run("ListProjectsWithPaging", func(t *testing.T) {496 _, gp, cleanUp := createStore(t)497 defer cleanUp()498 ctx := context.Background()499 projCount := 20500 wantProjectNames := make([]string, projCount)501 for i := 0; i < projCount; i++ {502 pID := fmt.Sprint("Project", i)503 p := &prpb.Project{}504 p.Name = name.FormatProject(pID)505 p, err := gp.CreateProject(ctx, pID, p)506 if err != nil {507 t.Fatalf("CreateProject got %v want success", err)508 }509 wantProjectNames[i] = p.Name510 }511 filter := "filters_are_yet_to_be_implemented"512 gotProjectNames := make([]string, 0)513 pageToken := ""514 pageSize := 10515 for {516 gotProjects, nextPageToken, err := gp.ListProjects(ctx, filter, pageSize, pageToken)517 if err != nil {518 t.Errorf("ListProjects got %v, want success", err)519 }520 if len(gotProjects) > pageSize {521 t.Errorf("ListProjects got %v projects, want <= %v", len(gotProjects), pageSize)522 }523 for _, project := range gotProjects {524 gotProjectNames = append(gotProjectNames, project.Name)525 }526 if nextPageToken == "" && len(gotProjectNames) < len(wantProjectNames) {527 t.Errorf("ListProjects returned empty next page token before returning all results")528 }529 // no more data530 if nextPageToken == "" {531 break532 }533 if pageToken == nextPageToken {534 t.Errorf("ListProjects returned the same page token as it received: %s", nextPageToken)535 }536 pageToken = nextPageToken537 }538 // Sort to handle that wantProjectNames are not guaranteed to be listed in insertion order539 sort.Strings(wantProjectNames)540 sort.Strings(gotProjectNames)541 if !reflect.DeepEqual(gotProjectNames, wantProjectNames) {542 t.Errorf("ListProjects got %v want %v", gotProjectNames, wantProjectNames)543 }544 })545 t.Run("ListNotes", func(t *testing.T) {546 g, gp, cleanUp := createStore(t)547 defer cleanUp()548 ctx := context.Background()549 findProject := "findThese"550 if _, err := gp.CreateProject(ctx, findProject, &prpb.Project{}); err != nil {551 t.Errorf("CreateProject got %v want success", err)552 }553 dontFind := "dontFind"554 if _, err := gp.CreateProject(ctx, dontFind, &prpb.Project{}); err != nil {555 t.Errorf("CreateProject got %v want success", err)556 }557 ns := []*pb.Note{}558 for i := 0; i < 20; i++ {559 n := createTestNote("")560 nPID := ""561 if i < 5 {562 n.Name = name.FormatNote(findProject, strconv.Itoa(i))563 nPID = findProject564 } else {565 n.Name = name.FormatNote(dontFind, strconv.Itoa(i))566 nPID = dontFind567 }568 if _, err := g.CreateNote(ctx, nPID, n.Name, "userID", n); err != nil {569 t.Fatalf("CreateNote got %v want success", err)570 }571 ns = append(ns, n)572 }573 filter := "filters_are_yet_to_be_implemented"574 gotNs, _, err := g.ListNotes(ctx, findProject, filter, "", 100)575 if err != nil {576 t.Fatalf("ListNotes got %v want success", err)577 }578 if len(gotNs) != 5 {579 t.Errorf("ListNotes got %v notes, want 5", len(gotNs))580 }581 for _, n := range gotNs {582 want := name.FormatProject(findProject)583 if !strings.HasPrefix(n.Name, want) {584 t.Errorf("ListNotes got %v want %v", n.Name, want)585 }586 }587 })588 t.Run("ListOccurrences", func(t *testing.T) {589 g, gp, cleanUp := createStore(t)590 defer cleanUp()591 ctx := context.Background()592 findProject := "findThese"593 if _, err := gp.CreateProject(ctx, findProject, &prpb.Project{}); err != nil {594 t.Errorf("CreateProject got %v want success", err)595 }596 dontFind := "dontFind"597 if _, err := gp.CreateProject(ctx, dontFind, &prpb.Project{}); err != nil {598 t.Errorf("CreateProject got %v want success", err)599 }600 nFind := createTestNote(findProject)601 if _, err := g.CreateNote(ctx, findProject, testNoteID, "userID", nFind); err != nil {602 t.Fatalf("CreateNote got %v want success", err)603 }604 nDontFind := createTestNote(dontFind)605 if _, err := g.CreateNote(ctx, dontFind, testNoteID, "userID", nDontFind); err != nil {606 t.Fatalf("CreateNote got %v want success", err)607 }608 os := []*pb.Occurrence{}609 for i := 0; i < 20; i++ {610 oPID := ""611 o := createTestOccurrence("", "")612 if i < 5 {613 oPID = findProject614 o.NoteName = nFind.Name615 } else {616 oPID = dontFind617 o.NoteName = nDontFind.Name618 }619 oo, err := g.CreateOccurrence(ctx, oPID, "userID", o)620 if err != nil {621 t.Fatalf("CreateOccurrence got %v want success", err)622 }623 os = append(os, oo)624 }625 filter := "filters_are_yet_to_be_implemented"626 gotOs, _, err := g.ListOccurrences(ctx, findProject, filter, "", 100)627 if err != nil {628 t.Fatalf("ListOccurrences got %v want success", err)629 }630 if len(gotOs) != 5 {631 t.Errorf("ListOccurrences got %v Occurrences, want 5", len(gotOs))632 }633 for _, o := range gotOs {634 want := name.FormatProject(findProject)635 if !strings.HasPrefix(o.Name, want) {636 t.Errorf("ListOccurrences got %v want %v", o.Name, want)637 }638 }639 })640 t.Run("ListNoteOccurrences", func(t *testing.T) {641 g, gp, cleanUp := createStore(t)642 defer cleanUp()643 ctx := context.Background()644 findProject := "findThese"645 if _, err := gp.CreateProject(ctx, findProject, &prpb.Project{}); err != nil {646 t.Errorf("CreateProject got %v want success", err)647 }648 dontFind := "dontFind"649 if _, err := gp.CreateProject(ctx, dontFind, &prpb.Project{}); err != nil {650 t.Errorf("CreateProject got %v want success", err)651 }652 n := createTestNote(findProject)653 if _, err := g.CreateNote(ctx, findProject, testNoteID, "userID", n); err != nil {654 t.Fatalf("CreateNote got %v want success", err)655 }656 os := []*pb.Occurrence{}657 for i := 0; i < 20; i++ {658 oPID := ""659 o := createTestOccurrence("", "")660 if i < 5 {661 oPID = findProject662 } else {663 oPID = dontFind664 }665 o.NoteName = n.Name666 oo, err := g.CreateOccurrence(ctx, oPID, "userID", o)667 if err != nil {668 t.Fatalf("CreateOccurrence got %v want success", err)669 }670 os = append(os, oo)671 }672 pID, nID, err := name.ParseNote(n.Name)673 if err != nil {674 t.Fatalf("Error parsing note name %v", err)675 }676 filter := "filters_are_yet_to_be_implemented"677 gotOs, _, err := g.ListNoteOccurrences(ctx, pID, nID, filter, "", 100)678 if err != nil {679 t.Fatalf("ListNoteOccurrences got %v want success", err)680 }681 if len(gotOs) != 20 {682 t.Errorf("ListNoteOccurrences got %v Occurrences, want 20", len(gotOs))683 }684 for _, o := range gotOs {685 if o.NoteName != n.Name {686 t.Errorf("ListNoteOccurrences got %v want %v", o.Name, o.NoteName)687 }688 }689 })690 t.Run("ProjectPagination", func(t *testing.T) {691 _, gp, cleanUp := createStore(t)692 defer cleanUp()693 ctx := context.Background()694 p1 := &prpb.Project{695 Name: "projects/project1",696 }697 p1ID := "project1"698 if _, err := gp.CreateProject(ctx, p1ID, p1); err != nil {699 t.Errorf("CreateProject got %v want success", err)700 }701 p2 := &prpb.Project{702 Name: "projects/project2",703 }704 p2ID := "project2"705 if _, err := gp.CreateProject(ctx, p2ID, p2); err != nil {706 t.Errorf("CreateProject got %v want success", err)707 }708 p3 := &prpb.Project{709 Name: "projects/project3",710 }711 p3ID := "project3"712 if _, err := gp.CreateProject(ctx, p3ID, p3); err != nil {713 t.Errorf("CreateProject got %v want success", err)714 }715 filter := "filters_are_yet_to_be_implemented"716 // Get projects717 gotProjects, lastPage, err := gp.ListProjects(ctx, filter, 2, "")718 if err != nil {719 t.Fatalf("ListProjects got %v want success", err)720 }721 if len(gotProjects) != 2 {722 t.Errorf("ListProjects got %v projects, want 2", len(gotProjects))723 }724 if p := gotProjects[0]; p.Name != p1.Name {725 t.Errorf("Got %s want %s", p.Name, p1.Name)726 }727 if p := gotProjects[1]; p.Name != p2.Name {728 t.Errorf("Got %s want %s", p.Name, p2.Name)729 }730 // Get projects again731 gotProjects, pageToken, err := gp.ListProjects(ctx, filter, 100, lastPage)732 if err != nil {733 t.Fatalf("ListProjects got %v want success", err)734 }735 if pageToken != "" {736 t.Fatalf("Got %s want empty page token", pageToken)737 }738 if len(gotProjects) != 1 {739 t.Errorf("ListProjects got %v projects, want 1", len(gotProjects))740 }741 if p := gotProjects[0]; p.Name != p3.Name {742 t.Fatalf("Got %s want %s", p.Name, p3.Name)743 }744 })745 t.Run("NotesPagination", func(t *testing.T) {746 g, gp, cleanUp := createStore(t)747 defer cleanUp()748 ctx := context.Background()749 pID := "project"750 if _, err := gp.CreateProject(ctx, pID, &prpb.Project{}); err != nil {751 t.Errorf("CreateProject got %v want success", err)752 }753 nID1 := "note1"754 op1 := createTestNote(pID)755 op1.Name = name.FormatNote(pID, nID1)756 if _, err := g.CreateNote(ctx, pID, nID1, "userID", op1); err != nil {757 t.Errorf("CreateNote got %v want success", err)758 }759 nID2 := "note2"760 op2 := createTestNote(pID)761 op2.Name = name.FormatNote(pID, nID2)762 if _, err := g.CreateNote(ctx, pID, nID2, "userID", op2); err != nil {763 t.Errorf("CreateNote got %v want success", err)764 }765 nID3 := "note3"766 op3 := createTestNote(pID)767 op3.Name = name.FormatNote(pID, nID3)768 if _, err := g.CreateNote(ctx, pID, nID3, "userID", op3); err != nil {769 t.Errorf("CreateNote got %v want success", err)770 }771 filter := "filters_are_yet_to_be_implemented"772 // Get occurrences773 gotNotes, lastPage, err := g.ListNotes(ctx, pID, filter, "", 2)774 if err != nil {775 t.Fatalf("ListNotes got %v want success", err)776 }777 if len(gotNotes) != 2 {778 t.Errorf("ListNotes got %v notes, want 2", len(gotNotes))779 }780 if p := gotNotes[0]; p.Name != name.FormatNote(pID, nID1) {781 t.Fatalf("Got %s want %s", p.Name, name.FormatNote(pID, nID1))782 }783 if p := gotNotes[1]; p.Name != name.FormatNote(pID, nID2) {784 t.Fatalf("Got %s want %s", p.Name, name.FormatNote(pID, nID2))785 }786 // Get occurrences again787 gotNotes, pageToken, err := g.ListNotes(ctx, pID, filter, lastPage, 100)788 if err != nil {789 t.Fatalf("ListNotes got %v want success", err)790 }791 if pageToken != "" {792 t.Errorf("Got %s want empty page token", pageToken)793 }794 if len(gotNotes) != 1 {795 t.Errorf("ListNotes got %v notes, want 1", len(gotNotes))796 }797 if p := gotNotes[0]; p.Name != name.FormatNote(pID, nID3) {798 t.Fatalf("Got %s want %s", p.Name, name.FormatNote(pID, nID3))799 }800 })801 t.Run("OccurrencePagination", func(t *testing.T) {802 g, gp, cleanUp := createStore(t)803 defer cleanUp()804 ctx := context.Background()805 pID := "project"806 if _, err := gp.CreateProject(ctx, pID, &prpb.Project{}); err != nil {807 t.Errorf("CreateProject got %v want success", err)808 }809 n := createTestNote(pID)810 if _, err := g.CreateNote(ctx, pID, testNoteID, "userID", n); err != nil {811 t.Fatalf("CreateNote got %v want success", err)812 }813 op1 := createTestOccurrence(pID, n.Name)814 if _, err := g.CreateOccurrence(ctx, pID, "userID", op1); err != nil {815 t.Errorf("CreateOccurrence got %v want success", err)816 }817 op2 := createTestOccurrence(pID, n.Name)818 if _, err := g.CreateOccurrence(ctx, pID, "userID", op2); err != nil {819 t.Errorf("CreateOccurrence got %v want success", err)820 }821 op3 := createTestOccurrence(pID, n.Name)822 if _, err := g.CreateOccurrence(ctx, pID, "userID", op3); err != nil {823 t.Errorf("CreateOccurrence got %v want success", err)824 }825 filter := "filters_are_yet_to_be_implemented"826 // Get occurrences827 gotOccurrences, lastPage, err := g.ListOccurrences(ctx, pID, filter, "", 2)828 if err != nil {829 t.Fatalf("ListOccurrences got %v want success", err)830 }831 if len(gotOccurrences) != 2 {832 t.Errorf("ListOccurrences got %v occurrences, want 2", len(gotOccurrences))833 }834 // Get occurrences again835 gotOccurrences, pageToken, err := g.ListOccurrences(ctx, pID, filter, lastPage, 100)836 if err != nil {837 t.Fatalf("ListOccurrences got %v want success", err)838 }839 if pageToken != "" {840 t.Errorf("Got %s want empty page token", pageToken)841 }842 if len(gotOccurrences) != 1 {843 t.Errorf("ListOccurrences got %v operations, want 1", len(gotOccurrences))844 }845 })846 t.Run("NoteOccurrencePagination", func(t *testing.T) {847 g, gp, cleanUp := createStore(t)848 defer cleanUp()849 ctx := context.Background()850 pID := "project"851 if _, err := gp.CreateProject(ctx, pID, &prpb.Project{}); err != nil {852 t.Errorf("CreateProject got %v want success", err)853 }854 nPID := "noteproject"855 if _, err := gp.CreateProject(ctx, nPID, &prpb.Project{}); err != nil {856 t.Errorf("CreateProject got %v want success", err)857 }858 n := createTestNote(nPID)859 if _, err := g.CreateNote(ctx, nPID, testNoteID, "userID", n); err != nil {860 t.Fatalf("CreateNote got %v want success", err)861 }862 op1 := createTestOccurrence(pID, n.Name)863 if _, err := g.CreateOccurrence(ctx, pID, "userID", op1); err != nil {864 t.Errorf("CreateOccurrence got %v want success", err)865 }866 op2 := createTestOccurrence(pID, n.Name)867 if _, err := g.CreateOccurrence(ctx, pID, "userID", op2); err != nil {868 t.Errorf("CreateOccurrence got %v want success", err)869 }870 op3 := createTestOccurrence(pID, n.Name)871 if _, err := g.CreateOccurrence(ctx, pID, "userID", op3); err != nil {872 t.Errorf("CreateOccurrence got %v want success", err)873 }874 filter := "filters_are_yet_to_be_implemented"875 _, nID, err := name.ParseNote(n.Name)876 // Get occurrences877 gotOccurrences, lastPage, err := g.ListNoteOccurrences(ctx, nPID, nID, filter, "", 2)878 if err != nil {879 t.Fatalf("ListNoteOccurrences got %v want success", err)880 }881 if len(gotOccurrences) != 2 {882 t.Errorf("ListNoteOccurrences got %v occurrences, want 2", len(gotOccurrences))883 }884 // Get occurrences again885 gotOccurrences, pageToken, err := g.ListNoteOccurrences(ctx, nPID, nID, filter, lastPage, 100)886 if err != nil {887 t.Fatalf("ListNoteOccurrences got %v want success", err)888 }889 if pageToken != "" {890 t.Fatalf("Got %s want empty page token", pageToken)891 }892 if len(gotOccurrences) != 1 {893 t.Errorf("ListNoteOccurrences got %v operations, want 1", len(gotOccurrences))894 }895 })896}897func createTestOccurrence(pID, noteName string) *pb.Occurrence {898 return &pb.Occurrence{899 Name: fmt.Sprintf("projects/%s/occurrences/134", pID),900 Resource: &pb.Resource{Uri: "gcr.io/foo/bar"},901 NoteName: noteName,902 Kind: cpb.NoteKind_VULNERABILITY,903 Details: &pb.Occurrence_Vulnerability{904 Vulnerability: &vpb.Details{905 Severity: vpb.Severity_HIGH,906 CvssScore: 7.5,907 PackageIssue: []*vpb.PackageIssue{908 {909 SeverityName: "HIGH",910 AffectedLocation: &vpb.VulnerabilityLocation{911 CpeUri: "cpe:/o:debian:debian_linux:8",912 Package: "icu",913 Version: &pkgpb.Version{914 Name: "52.1",915 Revision: "8+deb8u3",916 },917 },...

Full Screen

Full Screen

occurrence_test.go

Source:occurrence_test.go Github

copy

Full Screen

...21 "golang.org/x/net/context"22 "google.golang.org/grpc/codes"23 "google.golang.org/grpc/status"24)25func TestGetOccurrence(t *testing.T) {26 ctx := context.Background()27 s := newFakeStorage()28 g := &API{29 Storage: s,30 Auth: &fakeAuth{},31 EnforceValidation: true,32 }33 // Create the occurrence to get.34 o := vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian")35 createdOcc, err := s.CreateOccurrence(ctx, "consumer1", "", o)36 if err != nil {37 t.Fatalf("Failed to create occurrence %+v", o)38 }39 req := &gpb.GetOccurrenceRequest{40 Name: createdOcc.Name,41 }42 gotOcc := &gpb.Occurrence{}43 if err := g.GetOccurrence(ctx, req, gotOcc); err != nil {44 t.Fatalf("Got err %v, want success", err)45 }46 // TODO: migrate to protocolbuffers/protobuf-go when it is stable so we can use47 // protocmp.IgnoreFields instead.48 gotOcc.Name = ""49 if diff := cmp.Diff(o, gotOcc, cmp.Comparer(proto.Equal)); diff != "" {50 t.Errorf("GetOccurrence(%v) returned diff (want -> got):\n%s", req, diff)51 }52}53func TestGetOccurrenceErrors(t *testing.T) {54 ctx := context.Background()55 tests := []struct {56 desc string57 occName string58 internalStorageErr, authErr bool59 wantErrStatus codes.Code60 }{61 {62 desc: "invalid occurrence name",63 occName: "projects/consumer1",64 wantErrStatus: codes.InvalidArgument,65 },66 {67 desc: "auth error",68 occName: "projects/consumer1/occurrences/1234-abcd-3456-wxyz",69 authErr: true,70 wantErrStatus: codes.PermissionDenied,71 },72 {73 desc: "internal storage error",74 occName: "projects/consumer1/occurrences/1234-abcd-3456-wxyz",75 internalStorageErr: true,76 wantErrStatus: codes.Internal,77 },78 {79 desc: "occurrence doesn't exist, not found error",80 occName: "projects/consumer1/occurrences/1234-abcd-3456-wxyz",81 wantErrStatus: codes.NotFound,82 },83 }84 for _, tt := range tests {85 s := newFakeStorage()86 s.getOccErr = tt.internalStorageErr87 g := &API{88 Storage: s,89 Auth: &fakeAuth{authErr: tt.authErr},90 EnforceValidation: true,91 }92 req := &gpb.GetOccurrenceRequest{93 Name: tt.occName,94 }95 gotOcc := &gpb.Occurrence{}96 err := g.GetOccurrence(ctx, req, gotOcc)97 t.Logf("%q: error: %v", tt.desc, err)98 if status.Code(err) != tt.wantErrStatus {99 t.Errorf("%q: got error status %v, want %v", tt.desc, status.Code(err), tt.wantErrStatus)100 }101 }102}103func TestListOccurrences(t *testing.T) {104 ctx := context.Background()105 s := newFakeStorage()106 g := &API{107 Storage: s,108 Auth: &fakeAuth{},109 EnforceValidation: true,110 }111 // Create the occurrence to list.112 o := vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian")113 if _, err := s.CreateOccurrence(ctx, "consumer1", "", o); err != nil {114 t.Fatalf("Failed to create occurrence %+v", o)115 }116 req := &gpb.ListOccurrencesRequest{117 Parent: "projects/consumer1",118 }119 resp := &gpb.ListOccurrencesResponse{}120 if err := g.ListOccurrences(ctx, req, resp); err != nil {121 t.Fatalf("Got err %v, want success", err)122 }123 if len(resp.Occurrences) != 1 {124 t.Fatalf("Got occurrences of len %d, want 1", len(resp.Occurrences))125 }126 // TODO: migrate to protocolbuffers/protobuf-go when it is stable so we can use127 // protocmp.IgnoreFields instead.128 resp.Occurrences[0].Name = ""129 if diff := cmp.Diff(o, resp.Occurrences[0], cmp.Comparer(proto.Equal)); diff != "" {130 t.Errorf("ListOccurrences(%v) returned diff (want -> got):\n%s", req, diff)131 }132}133func TestListOccurrencesErrors(t *testing.T) {134 ctx := context.Background()135 tests := []struct {136 desc string137 parent string138 pageSize int32139 internalStorageErr, authErr bool140 wantErrStatus codes.Code141 }{142 {143 desc: "invalid parent name",144 parent: "projects",145 wantErrStatus: codes.InvalidArgument,146 },147 {148 desc: "auth error",149 parent: "projects/consumer1",150 authErr: true,151 wantErrStatus: codes.PermissionDenied,152 },153 {154 desc: "internal storage error",155 parent: "projects/consumer1",156 internalStorageErr: true,157 wantErrStatus: codes.Internal,158 },159 {160 desc: "invalid page size error",161 parent: "projects/consumer1",162 pageSize: -1,163 wantErrStatus: codes.InvalidArgument,164 },165 }166 for _, tt := range tests {167 s := newFakeStorage()168 s.listOccsErr = tt.internalStorageErr169 g := &API{170 Storage: s,171 Auth: &fakeAuth{authErr: tt.authErr},172 EnforceValidation: true,173 }174 req := &gpb.ListOccurrencesRequest{175 Parent: tt.parent,176 PageSize: tt.pageSize,177 }178 resp := &gpb.ListOccurrencesResponse{}179 err := g.ListOccurrences(ctx, req, resp)180 t.Logf("%q: error: %v", tt.desc, err)181 if status.Code(err) != tt.wantErrStatus {182 t.Errorf("%q: got error status %v, want %v", tt.desc, status.Code(err), tt.wantErrStatus)183 }184 }185}186func TestCreateOccurrence(t *testing.T) {187 ctx := context.Background()188 g := &API{189 Storage: newFakeStorage(),190 Auth: &fakeAuth{},191 EnforceValidation: true,192 }193 req := &gpb.CreateOccurrenceRequest{194 Parent: "projects/consumer1",195 Occurrence: vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian"),196 }197 createdOcc := &gpb.Occurrence{}198 if err := g.CreateOccurrence(ctx, req, createdOcc); err != nil {199 t.Fatalf("Got err %v, want success", err)200 }201 // TODO: migrate to protocolbuffers/protobuf-go when it is stable so we can use202 // protocmp.IgnoreFields instead.203 createdOcc.Name = ""204 if diff := cmp.Diff(req.Occurrence, createdOcc, cmp.Comparer(proto.Equal)); diff != "" {205 t.Errorf("CreateOccurrence(%v) returned diff (want -> got):\n%s", req, diff)206 }207}208func TestCreateOccurrenceErrors(t *testing.T) {209 ctx := context.Background()210 tests := []struct {211 desc string212 parent string213 occ *gpb.Occurrence214 internalStorageErr, authErr, endUserIDErr bool215 wantErrStatus codes.Code216 }{217 {218 desc: "invalid project name",219 parent: "projects",220 occ: vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian"),221 wantErrStatus: codes.InvalidArgument,222 },223 {224 desc: "nil occurrence",225 parent: "projects/consumer1",226 occ: nil,227 wantErrStatus: codes.InvalidArgument,228 },229 {230 desc: "invalid note name",231 parent: "projects/consumer1",232 occ: vulnzOcc(t, "consumer1", "foobar", "debian"),233 wantErrStatus: codes.InvalidArgument,234 },235 {236 desc: "auth error",237 parent: "projects/consumer1",238 occ: vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian"),239 authErr: true,240 wantErrStatus: codes.PermissionDenied,241 },242 {243 desc: "end user ID error",244 parent: "projects/consumer1",245 occ: vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian"),246 endUserIDErr: true,247 wantErrStatus: codes.Internal,248 },249 {250 desc: "internal storage error",251 parent: "projects/consumer1",252 occ: vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian"),253 internalStorageErr: true,254 wantErrStatus: codes.Internal,255 },256 {257 desc: "invalid vulnerability occurrence",258 parent: "projects/goog-vulnz",259 occ: invalidVulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH"),260 wantErrStatus: codes.InvalidArgument,261 },262 }263 for _, tt := range tests {264 s := newFakeStorage()265 s.createOccErr = tt.internalStorageErr266 g := &API{267 Storage: s,268 Auth: &fakeAuth{authErr: tt.authErr, endUserIDErr: tt.endUserIDErr},269 EnforceValidation: true,270 }271 req := &gpb.CreateOccurrenceRequest{272 Parent: tt.parent,273 Occurrence: tt.occ,274 }275 o := &gpb.Occurrence{}276 err := g.CreateOccurrence(ctx, req, o)277 t.Logf("%q: error: %v", tt.desc, err)278 if status.Code(err) != tt.wantErrStatus {279 t.Errorf("%q: got error status %v, want %v", tt.desc, status.Code(err), tt.wantErrStatus)280 }281 }282}283func TestBatchCreateOccurrences(t *testing.T) {284 ctx := context.Background()285 g := &API{286 Storage: newFakeStorage(),287 Auth: &fakeAuth{},288 EnforceValidation: true,289 }290 req := &gpb.BatchCreateOccurrencesRequest{291 Parent: "projects/consumer1",292 Occurrences: []*gpb.Occurrence{293 vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian"),294 },295 }296 resp := &gpb.BatchCreateOccurrencesResponse{}297 if err := g.BatchCreateOccurrences(ctx, req, resp); err != nil {298 t.Fatalf("Got err %v, want success", err)299 }300 if len(resp.Occurrences) != 1 {301 t.Fatalf("Got created occurrences of len %d, want 1", len(resp.Occurrences))302 }303 // TODO: migrate to protocolbuffers/protobuf-go when it is stable so we can use304 // protocmp.IgnoreFields instead.305 resp.Occurrences[0].Name = ""306 if diff := cmp.Diff(req.Occurrences[0], resp.Occurrences[0], cmp.Comparer(proto.Equal)); diff != "" {307 t.Errorf("BatchCreateOccurrences(%v) returned diff (want -> got):\n%s", req, diff)308 }309}310func TestBatchCreateOccurrencesErrors(t *testing.T) {311 ctx := context.Background()312 tests := []struct {313 desc string314 parent string315 occs []*gpb.Occurrence316 internalStorageErr, authErr, endUserIDErr bool317 wantErrStatus codes.Code318 }{319 {320 desc: "invalid project name",321 parent: "projects",322 occs: []*gpb.Occurrence{323 vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian"),324 },325 wantErrStatus: codes.InvalidArgument,326 },327 {328 desc: "nil occurrences",329 parent: "projects/consumer1",330 occs: nil,331 wantErrStatus: codes.InvalidArgument,332 },333 {334 desc: "empty occurrences",335 parent: "projects/consumer1",336 occs: []*gpb.Occurrence{},337 wantErrStatus: codes.InvalidArgument,338 },339 {340 desc: "invalid note name",341 parent: "projects/consumer1",342 occs: []*gpb.Occurrence{343 vulnzOcc(t, "consumer1", "foobar", "debian"),344 },345 wantErrStatus: codes.InvalidArgument,346 },347 {348 desc: "auth error",349 parent: "projects/consumer1",350 occs: []*gpb.Occurrence{351 vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian"),352 },353 authErr: true,354 wantErrStatus: codes.PermissionDenied,355 },356 {357 desc: "end user ID error",358 parent: "projects/consumer1",359 occs: []*gpb.Occurrence{360 vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian"),361 },362 endUserIDErr: true,363 wantErrStatus: codes.Internal,364 },365 {366 desc: "internal storage error",367 parent: "projects/consumer1",368 occs: []*gpb.Occurrence{369 vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian"),370 },371 internalStorageErr: true,372 wantErrStatus: codes.InvalidArgument,373 },374 {375 desc: "invalid vulnerability occurrence",376 parent: "projects/consumer1",377 occs: []*gpb.Occurrence{378 invalidVulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH"),379 },380 wantErrStatus: codes.InvalidArgument,381 },382 {383 desc: "two invalid vulnerability occurrences",384 parent: "projects/consumer1",385 occs: []*gpb.Occurrence{386 invalidVulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH"),387 invalidVulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH"),388 },389 wantErrStatus: codes.InvalidArgument,390 },391 {392 desc: "one valid, one invalid vulnerability occurrences",393 parent: "projects/consumer1",394 occs: []*gpb.Occurrence{395 vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian"),396 invalidVulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH"),397 },398 wantErrStatus: codes.InvalidArgument,399 },400 {401 desc: "number of occurrences exceeds batch max",402 parent: "projects/consumer1",403 occs: vulnzOccs(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian-", 1001),404 wantErrStatus: codes.InvalidArgument,405 },406 }407 for _, tt := range tests {408 s := newFakeStorage()409 s.batchCreateOccsErr = tt.internalStorageErr410 g := &API{411 Storage: s,412 Auth: &fakeAuth{authErr: tt.authErr, endUserIDErr: tt.endUserIDErr},413 EnforceValidation: true,414 }415 req := &gpb.BatchCreateOccurrencesRequest{416 Parent: tt.parent,417 Occurrences: tt.occs,418 }419 resp := &gpb.BatchCreateOccurrencesResponse{}420 err := g.BatchCreateOccurrences(ctx, req, resp)421 t.Logf("%q: error: %v", tt.desc, err)422 if status.Code(err) != tt.wantErrStatus {423 t.Errorf("%q: got error status %v, want %v", tt.desc, status.Code(err), tt.wantErrStatus)424 }425 }426}427func TestUpdateOccurrence(t *testing.T) {428 ctx := context.Background()429 s := newFakeStorage()430 g := &API{431 Storage: s,432 Auth: &fakeAuth{},433 EnforceValidation: true,434 }435 // Create the occurrence to update.436 o := vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian")437 createdOcc, err := s.CreateOccurrence(ctx, "consumer1", "", o)438 if err != nil {439 t.Fatalf("Failed to create occurrence %+v", o)440 }441 o.Remediation = "update to latest version"442 req := &gpb.UpdateOccurrenceRequest{443 Name: createdOcc.Name,444 Occurrence: o,445 }446 updatedOcc := &gpb.Occurrence{}447 if err := g.UpdateOccurrence(ctx, req, updatedOcc); err != nil {448 t.Fatalf("Got err %v, want success", err)449 }450 // TODO: migrate to protocolbuffers/protobuf-go when it is stable so we can use451 // protocmp.IgnoreFields instead.452 updatedOcc.Name = ""453 if diff := cmp.Diff(o, updatedOcc, cmp.Comparer(proto.Equal)); diff != "" {454 t.Errorf("UpdateOccurrence(%v) returned diff (want -> got):\n%s", req, diff)455 }456}457func TestUpdateOccurrenceErrors(t *testing.T) {458 ctx := context.Background()459 tests := []struct {460 desc string461 occName string462 occ *gpb.Occurrence463 internalStorageErr, authErr bool464 wantErrStatus codes.Code465 }{466 {467 desc: "invalid occurrence name",468 occName: "projects",469 occ: vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian"),470 wantErrStatus: codes.InvalidArgument,471 },472 {473 desc: "nil occurrence",474 occName: "projects/consumer1/occurrences/1234-abcd-3456-wxyz",475 occ: nil,476 wantErrStatus: codes.InvalidArgument,477 },478 {479 desc: "invalid note name",480 occName: "projects/consumer1/occurrences/1234-abcd-3456-wxyz",481 occ: vulnzOcc(t, "consumer1", "projects/foobar", "debian"),482 wantErrStatus: codes.InvalidArgument,483 },484 {485 desc: "auth error",486 occName: "projects/consumer1/occurrences/1234-abcd-3456-wxyz",487 occ: vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian"),488 authErr: true,489 wantErrStatus: codes.PermissionDenied,490 },491 {492 desc: "internal storage error",493 occName: "projects/consumer1/occurrences/1234-abcd-3456-wxyz",494 occ: vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian"),495 internalStorageErr: true,496 wantErrStatus: codes.Internal,497 },498 {499 desc: "occurrence doesn't exist, not found error",500 occName: "projects/consumer1/occurrences/1234-abcd-3456-wxyz",501 occ: vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian"),502 wantErrStatus: codes.NotFound,503 },504 }505 for _, tt := range tests {506 s := newFakeStorage()507 s.updateOccErr = tt.internalStorageErr508 g := &API{509 Storage: s,510 Auth: &fakeAuth{authErr: tt.authErr},511 EnforceValidation: true,512 }513 req := &gpb.UpdateOccurrenceRequest{514 Name: tt.occName,515 Occurrence: tt.occ,516 }517 o := &gpb.Occurrence{}518 err := g.UpdateOccurrence(ctx, req, o)519 t.Logf("%q: error: %v", tt.desc, err)520 if status.Code(err) != tt.wantErrStatus {521 t.Errorf("%q: got error status %v, want %v", tt.desc, status.Code(err), tt.wantErrStatus)522 }523 }524}525func TestDeleteOccurrence(t *testing.T) {526 ctx := context.Background()527 tests := []struct {528 noteName string529 }{530 {noteName: "projects/goog-vulnz/notes/CVE-UH-OH"},531 {noteName: ""},532 }533 for _, tt := range tests {534 s := newFakeStorage()535 g := &API{536 Storage: s,537 Auth: &fakeAuth{},538 EnforceValidation: true,539 }540 // Create the occurrence to delete.541 o := vulnzOcc(t, "consumer1", tt.noteName, "debian")542 createdOcc, err := s.CreateOccurrence(ctx, "consumer1", "", o)543 if err != nil {544 t.Fatalf("Failed to create occurrence %+v", o)545 }546 req := &gpb.DeleteOccurrenceRequest{547 Name: createdOcc.Name,548 }549 if err := g.DeleteOccurrence(ctx, req, nil); err != nil {550 t.Errorf("Got err %v, want success", err)551 }552 }553}554func TestDeleteOccurrenceErrors(t *testing.T) {555 ctx := context.Background()556 tests := []struct {557 desc string558 existingOcc *gpb.Occurrence559 occToDeleteOverride string560 internalStorageErr, authErr, purgeErr bool561 wantErrStatus codes.Code562 }{563 {564 desc: "invalid occurrence name in delete request",565 existingOcc: vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian"),566 occToDeleteOverride: "projects/consumer1",567 wantErrStatus: codes.InvalidArgument,568 },569 {570 desc: "occurrence to delete has invalid note name",571 existingOcc: vulnzOcc(t, "consumer1", "projects/goog-vulnz", "debian"),572 wantErrStatus: codes.InvalidArgument,573 },574 {575 desc: "auth error",576 existingOcc: vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian"),577 authErr: true,578 wantErrStatus: codes.PermissionDenied,579 },580 {581 desc: "internal storage error",582 existingOcc: vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian"),583 internalStorageErr: true,584 wantErrStatus: codes.Internal,585 },586 {587 desc: "purge policy err, fail open",588 existingOcc: vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian"),589 purgeErr: true,590 wantErrStatus: codes.OK,591 },592 {593 desc: "occurrence doesn't exist, not found error",594 occToDeleteOverride: "projects/consumer1/occurrences/1234-abcd-3456-wxyz",595 wantErrStatus: codes.NotFound,596 },597 }598 for _, tt := range tests {599 s := newFakeStorage()600 s.deleteOccErr = tt.internalStorageErr601 g := &API{602 Storage: s,603 Auth: &fakeAuth{authErr: tt.authErr, purgeErr: tt.purgeErr},604 EnforceValidation: true,605 }606 var createdOcc *gpb.Occurrence607 if tt.existingOcc != nil {608 var err error609 createdOcc, err = s.CreateOccurrence(ctx, "consumer1", "", tt.existingOcc)610 if err != nil {611 t.Fatalf("Failed to create occurrence %+v: %v", tt.existingOcc, err)612 }613 }614 occToDelete := createdOcc.GetName()615 if tt.occToDeleteOverride != "" {616 occToDelete = tt.occToDeleteOverride617 }618 req := &gpb.DeleteOccurrenceRequest{619 Name: occToDelete,620 }621 err := g.DeleteOccurrence(ctx, req, nil)622 t.Logf("%q: error: %v", tt.desc, err)623 if status.Code(err) != tt.wantErrStatus {624 t.Errorf("%q: got error status %v, want %v", tt.desc, status.Code(err), tt.wantErrStatus)625 }626 }627}628func TestListNoteOccurrences(t *testing.T) {629 ctx := context.Background()630 s := newFakeStorage()631 g := &API{632 Storage: s,633 Auth: &fakeAuth{},634 EnforceValidation: true,635 }636 // Create a note and its occurrences we want to list.637 n := vulnzNote(t)638 if _, err := s.CreateNote(ctx, "goog-vulnz", "CVE-UH-OH", "", n); err != nil {639 t.Fatalf("Failed to create note %+v", n)640 }641 o := vulnzOcc(t, "consumer1", "projects/goog-vulnz/notes/CVE-UH-OH", "debian")642 createdOcc, err := s.CreateOccurrence(ctx, "consumer1", "", o)643 if err != nil {644 t.Fatalf("Failed to create occurrence %+v", o)645 }646 req := &gpb.ListNoteOccurrencesRequest{647 Name: "projects/goog-vulnz/notes/CVE-UH-OH",648 }649 resp := &gpb.ListNoteOccurrencesResponse{}650 if err := g.ListNoteOccurrences(ctx, req, resp); err != nil {651 t.Fatalf("ListNoteOccurrences(%v) got err %v, want success", req, err)652 }653 if len(resp.Occurrences) != 1 {654 t.Fatalf("Got occurrences of len %d, want 1", len(resp.Occurrences))655 }656 // TODO: migrate to protocolbuffers/protobuf-go when it is stable so we can use657 // protocmp.IgnoreFields instead.658 resp.Occurrences[0].Name = ""659 if diff := cmp.Diff(createdOcc, resp.Occurrences[0], cmp.Comparer(proto.Equal)); diff != "" {660 t.Errorf("ListNoteOccurrences(%v) returned diff (want -> got):\n%s", req, diff)661 }662}663func TestListNoteOccurrencesErrors(t *testing.T) {664 ctx := context.Background()665 tests := []struct {666 desc string667 noteName string668 pageSize int32669 internalStorageErr, authErr bool670 wantErrStatus codes.Code671 }{672 {673 desc: "invalid note name",674 noteName: "projects/google-vulnz/notes/",675 wantErrStatus: codes.InvalidArgument,676 },677 {678 desc: "auth error",679 noteName: "projects/goog-vulnz/notes/CVE-UH-OH",680 authErr: true,681 wantErrStatus: codes.PermissionDenied,682 },683 {684 desc: "internal storage error",685 noteName: "projects/goog-vulnz/notes/CVE-UH-OH",686 internalStorageErr: true,687 wantErrStatus: codes.Internal,688 },689 {690 desc: "invalid page size error",691 noteName: "projects/goog-vulnz/notes/CVE-UH-OH",692 pageSize: -1,693 wantErrStatus: codes.InvalidArgument,694 },695 }696 for _, tt := range tests {697 s := newFakeStorage()698 s.listNoteOccsErr = tt.internalStorageErr699 g := &API{700 Storage: s,701 Auth: &fakeAuth{authErr: tt.authErr},702 EnforceValidation: true,703 }704 req := &gpb.ListNoteOccurrencesRequest{705 Name: tt.noteName,706 PageSize: tt.pageSize,707 }708 resp := &gpb.ListNoteOccurrencesResponse{}709 err := g.ListNoteOccurrences(ctx, req, resp)710 t.Logf("%q: error: %v", tt.desc, err)711 if status.Code(err) != tt.wantErrStatus {712 t.Errorf("%q: got error status %v, want %v", tt.desc, status.Code(err), tt.wantErrStatus)713 }714 }715}716// vulnzOcc returns a fake v1 valid vulnerability occurrence for testing.717func vulnzOcc(t *testing.T, pID, noteName, imageName string) *gpb.Occurrence {718 t.Helper()719 return &gpb.Occurrence{720 ResourceUri: fmt.Sprintf("https://us.gcr.io/%s/%s@sha256:0baa7a935c0cba530xxx03af85770cb52b26bfe570a9ff09e17c1a02c6b0bd9a", pID, imageName),721 NoteName: noteName,722 Details: &gpb.Occurrence_Vulnerability{723 Vulnerability: &gpb.VulnerabilityOccurrence{724 PackageIssue: []*gpb.VulnerabilityOccurrence_PackageIssue{725 {726 AffectedCpeUri: "cpe:/o:debian:debian_linux:8",727 AffectedPackage: "abc",728 AffectedVersion: &gpb.Version{729 Name: "0.2.0",730 Kind: gpb.Version_NORMAL,731 },732 FixedCpeUri: "cpe:/o:debian:debian_linux:8",733 FixedPackage: "abc",734 FixedVersion: &gpb.Version{735 Name: "1.0.0",736 Kind: gpb.Version_NORMAL,737 },738 },739 },740 },741 },742 }743}744// invalidVulnzOcc returns a fake v1 invalid vulnerability occurrence for testing. Occurrence745// is missing resource.746func invalidVulnzOcc(t *testing.T, pID, noteName string) *gpb.Occurrence {747 t.Helper()748 return &gpb.Occurrence{749 NoteName: noteName,750 Details: &gpb.Occurrence_Vulnerability{751 Vulnerability: &gpb.VulnerabilityOccurrence{752 PackageIssue: []*gpb.VulnerabilityOccurrence_PackageIssue{753 {754 AffectedCpeUri: "cpe:/o:debian:debian_linux:8",755 AffectedPackage: "abc",756 AffectedVersion: &gpb.Version{757 Name: "0.2.0",758 Kind: gpb.Version_NORMAL,759 },760 FixedCpeUri: "cpe:/o:debian:debian_linux:8",761 FixedPackage: "abc",762 FixedVersion: &gpb.Version{763 Name: "1.0.0",764 Kind: gpb.Version_NORMAL,765 },766 },767 },768 },769 },770 }771}772// vulnzOccs creates the specified number of fake v1 valid vulnerability occurrences for773// testing.774func vulnzOccs(t *testing.T, pID, noteName, imageNamePrefix string, num int) []*gpb.Occurrence {775 t.Helper()776 occs := []*gpb.Occurrence{}777 for i := 0; i < num; i++ {778 occs = append(occs, vulnzOcc(t, pID, noteName, fmt.Sprintf("%s%d", imageNamePrefix, i)))779 }780 return occs781}...

Full Screen

Full Screen

Occurrence

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 dmp := diffmatchpatch.New()4 d := dmp.DiffMain(a, b, false)5 fmt.Println(dmp.DiffPrettyText(d))6 fmt.Println(dmp.DiffText1(d))7 fmt.Println(dmp.DiffText2(d))8 fmt.Println(dmp.DiffToDelta(d))9 diffs := dmp.DiffFromDelta(a, dmp.DiffToDelta(d))10 fmt.Println(diffs)11 fmt.Println(dmp.DiffPrettyText(diffs))12 fmt.Println(dmp.DiffXIndex(diffs, 4))13 fmt.Println(dmp.DiffXIndex(diffs, 36))14 fmt.Println(dmp.DiffLevenshtein(diffs))15 fmt.Println(dmp.DiffBisect(a, b))16 fmt.Println(dmp.DiffBisectSplit(a, b, 10))17 fmt.Println(dmp.DiffCommonPrefix(a, b))18 fmt.Println(dmp.DiffCommonSuffix(a, b))19 fmt.Println(dmp.DiffCommonOverlap(a, b))20 fmt.Println(dmp.DiffHalfMatch(a, b))21 fmt.Println(dmp.DiffHalfMatchI(a, b))22 fmt.Println(dmp.DiffLinesToChars(a, b))23 fmt.Println(dmp.DiffCharsToLines(diffs, "1"))24 fmt.Println(dmp.DiffCleanupSemantic(diffs))25 fmt.Println(dmp.DiffCleanupSemanticLossless(diffs))26 fmt.Println(dmp.DiffCleanupEfficiency(diffs))27 fmt.Println(dmp.DiffPrettyHtml(diffs))28 fmt.Println(dmp.DiffPrettyHtml(diffs))29 fmt.Println(dmp.DiffCleanupMerge(diffs))30 fmt.Println(dmp.DiffMain(a, b, true))31 fmt.Println(dmp.DiffMain(a, b, false))32 fmt.Println(dmp.DiffMain(b, a, true))33 fmt.Println(dmp.DiffMain(b, a, false))34 fmt.Println(dmp.DiffMain("abc", "ab123c", true))35 fmt.Println(dmp.DiffMain("abc", "ab123c", false))36 fmt.Println(dmp.DiffMain("1234abcdef", "1234abxyz", true))37 fmt.Println(dmp.DiffMain("1234

Full Screen

Full Screen

Occurrence

Using AI Code Generation

copy

Full Screen

1import (2func main() {3dmp := diffmatchpatch.New()4diffs := dmp.DiffMain(text1, text2, false)5fmt.Println(diffs)6fmt.Println(dmp.DiffPrettyText(diffs))7fmt.Println(dmp.DiffText1(diffs))8fmt.Println(dmp.DiffText2(diffs))9fmt.Println(dmp.DiffToDelta(diffs))10fmt.Println(dmp.DiffFromDelta(text1, "=-4\t-7\t+That\t=3\t+jumped\t=7\t+a\t=12\t+lazy\t=5\t+dog."))11fmt.Println(dmp.DiffXIndex(diffs, 4))12fmt.Println(dmp.DiffLevenshtein(diffs))13fmt.Println(dmp.DiffBisect(text1, text2))14fmt.Println(dmp.DiffBisectSplit(text1, text2, 3))15fmt.Println(dmp.DiffCommonPrefix(text1, text2))16fmt.Println(dmp.DiffCommonSuffix(text1, text2))17fmt.Println(dmp.DiffCommonOverlap(text1, text2))18fmt.Println(dmp.DiffHalfMatch(text1, text2))19fmt.Println(dmp.DiffLinesToChars(text1, text2))20fmt.Println(dmp.DiffCharsToLines(diffs, text1, text2))21fmt.Println(dmp.DiffCleanupSemantic(diffs))22fmt.Println(dmp.DiffCleanupSemanticLossless(diffs))23fmt.Println(dmp.DiffCleanupEfficiency(diffs))24fmt.Println(dmp.DiffPrettyHtml(diffs))25fmt.Println(dmp.DiffXIndex(diffs, 4))26fmt.Println(dmp.DiffXIndex(diffs, 5))27fmt.Println(dmp.DiffXIndex(diffs, 6))28fmt.Println(dmp.DiffXIndex(diffs, 7))29fmt.Println(dmp.DiffXIndex(diffs, 8))30fmt.Println(dmp.DiffXIndex(diffs, 9))31fmt.Println(dmp.DiffXIndex(diffs, 10))32fmt.Println(dmp.DiffXIndex(diffs, 11))33fmt.Println(dmp.DiffXIndex(diffs, 12))34fmt.Println(dmp.DiffXIndex(diffs, 13))35fmt.Println(dmp.DiffXIndex(diffs, 14))36fmt.Println(dmp.DiffX

Full Screen

Full Screen

Occurrence

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter the first string:")4 fmt.Scanln(&str1)5 fmt.Println("Enter the second string:")6 fmt.Scanln(&str2)7 str1 = strings.ToLower(str1)8 str2 = strings.ToLower(str2)9 fmt.Println("The number of occurrences of the second string in the first string is", strings.Count(str1, str2))10}11Recommended Posts: Golang | strings.Index() method12Golang | strings.IndexAny() method13Golang | strings.IndexRune() method14Golang | strings.IndexByte() method15Golang | strings.LastIndex() method16Golang | strings.LastIndexAny() method17Golang | strings.LastIndexByte() method18Golang | strings.LastIndexRune() method19Golang | strings.IndexFunc() method20Golang | strings.IndexRune() method21Golang | strings.IndexByte() method22Golang | strings.LastIndex() method23Golang | strings.LastIndexAny() method24Golang | strings.LastIndexByte() method25Golang | strings.LastIndexRune() method26Golang | strings.IndexFunc() method27Golang | strings.Repeat() method28Golang | strings.Replace() method29Golang | strings.ReplaceAll() method30Golang | strings.ReplaceAll() method31Golang | strings.Replace() method32Golang | strings.Repeat() method33Golang | strings.Split() method34Golang | strings.SplitAfter() method35Golang | strings.SplitAfterN() method36Golang | strings.SplitN() method37Golang | strings.TrimSpace() method38Golang | strings.Trim() method39Golang | strings.TrimLeft() method40Golang | strings.TrimPrefix() method41Golang | strings.TrimRight() method42Golang | strings.TrimSuffix() method43Golang | strings.Title() method44Golang | strings.ToTitle() method45Golang | strings.ToTitleSpecial() method46Golang | strings.ToLower() method47Golang | strings.ToLowerSpecial() method

Full Screen

Full Screen

Occurrence

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter the first string:")4 fmt.Scan(&s1)5 fmt.Println("Enter the second string:")6 fmt.Scan(&s2)7 d := diff.New()8 d.Diff(s1, s2)9 fmt.Println(d.Occurrence())10}11Go | To find the number of occurrences of a substring in a string using strings.Count()12Go | To find the number of occurrences of a substring in a string using strings.Repeat()13Go | To find the number of occurrences of a substring in a string using strings.Replace()14Go | To find the number of occurrences of a substring in a string using strings.Split()15Go | To find the number of occurrences of a substring in a string using strings.Trim()16Go | To find the number of occurrences of a substring in a string using strings.TrimLeft()17Go | To find the number of occurrences of a substring in a string using strings.TrimRight()18Go | To find the number of occurrences of a substring in a string using strings.TrimSuffix()19Go | To find the number of occurrences of a substring in a string using strings.TrimPrefix()20Go | To find the number of occurrences of a substring in a string using strings.Fields()21Go | To find the number of occurrences of a substring in a string using strings.Join()22Go | To find the number of occurrences of a substring in a string using strings.Map()23Go | To find the number of occurrences of a substring in a string using strings.FieldsFunc()24Go | To find the number of occurrences of a substring in a string using strings.Title()25Go | To find the number of occurrences of a substring in a string using strings.ToLower()26Go | To find the number of occurrences of a substring in a string using strings.ToUpper()27Go | To find the number of occurrences of a substring in a string using strings.ToTitle()28Go | To find the number of occurrences of a substring in a string using strings.ToTitleLower()29Go | To find the number of occurrences of a substring in a string using strings.ToTitleUpper()

Full Screen

Full Screen

Occurrence

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "github.com/sergi/go-diff/diffmatchpatch"3func main() {4 dmp := diffmatchpatch.New()5 d := dmp.DiffMain("Hello World", "Hello Go", false)6 fmt.Println(dmp.DiffPrettyText(d))7 fmt.Println(dmp.DiffToDelta(d))8 fmt.Println(dmp.DiffFromDelta("Hello World", dmp.DiffToDelta(d)))9 fmt.Println(dmp.DiffXIndex(d, 4))10 fmt.Println(dmp.DiffXIndex(d, 5))11 fmt.Println(dmp.DiffLevenshtein(d))12 fmt.Println(dmp.DiffBisect("alpha beta gamma", "alpha delta gamma", 10))13 fmt.Println(dmp.DiffBisect("alpha beta gamma", "alpha delta gamma", 100))14 fmt.Println(dmp.DiffBisect("alpha beta gamma", "alpha delta gamma", 1000))15 fmt.Println(dmp.DiffBisect("alpha beta gamma", "alpha delta gamma", 10000))16 fmt.Println(dmp.DiffBisect("alpha beta gamma", "alpha delta gamma", 100000))17 fmt.Println(dmp.DiffBisect("alpha beta gamma", "alpha delta gamma", 1000000))18 fmt.Println(dmp.DiffBisect("alpha beta gamma", "alpha delta gamma", 10000000))19 fmt.Println(dmp.DiffBisect("alpha beta gamma", "alpha delta gamma", 100000000))20 fmt.Println(dmp.DiffBisect("alpha beta gamma", "alpha delta gamma", 1000000000))21 fmt.Println(dmp.DiffBisect("alpha beta gamma", "alpha delta gamma", 10000000000))22 fmt.Println(dmp.DiffBisect("alpha beta gamma", "alpha delta gamma", 100000000000))23 fmt.Println(dmp.DiffBisect("alpha beta gamma", "alpha delta gamma", 1000000000000))24 fmt.Println(dmp.DiffBisect("alpha beta gamma", "alpha delta gamma", 10000000000000))25 fmt.Println(dmp.DiffBisect("alpha beta gamma", "alpha delta gamma", 100000000000000))26 fmt.Println(dmp.DiffBisect("alpha beta gamma", "alpha delta gamma", 1000000000000000))27 fmt.Println(dmp.DiffB

Full Screen

Full Screen

Occurrence

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 dmp := diffmatchpatch.New()4 d := dmp.DiffMain(a, b, false)5 fmt.Println(dmp.DiffPrettyText(d))6 fmt.Println(dmp.DiffText1(d))7 fmt.Println(dmp.DiffText2(d))8 fmt.Println(dmp.DiffToDelta(d))9 diffs := dmp.DiffFromDelta(a, "The c<qui>ck brown fox jumps over the lazy dog.")10 fmt.Println(dmp.DiffPrettyText(diffs))11 fmt.Println(dmp.DiffToDelta(diffs))12}13import (14func main() {15 dmp := diffmatchpatch.New()16 d := dmp.DiffMain(a, b, false)17 fmt.Println(dmp.DiffPrettyText(d))18 fmt.Println(dmp.DiffText1(d))19 fmt.Println(dmp.DiffText2(d))20 fmt.Println(dmp.DiffToDelta(d))21 diffs := dmp.DiffFromDelta(a, "The c<qui>ck brown fox jumps over the lazy dog.")22 fmt.Println(dmp.DiffPrettyText(diffs))23 fmt.Println(dmp.DiffToDelta(diffs))24}

Full Screen

Full Screen

Occurrence

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 dmp := diffmatchpatch.New()4 diffs := dmp.DiffMain(a, b, false)5 fmt.Println(dmp.DiffPrettyText(diffs))6 fmt.Println(dmp.DiffPrettyHtml(diffs))7 fmt.Println(dmp.DiffText1(diffs))8 fmt.Println(dmp.DiffText2(diffs))9 fmt.Println(dmp.DiffToDelta(diffs))10 fmt.Println(dmp.DiffFromDelta(a, dmp.DiffToDelta(diffs)))11 fmt.Println(dmp.DiffXIndex(diffs, 1))12 fmt.Println(dmp.DiffLevenshtein(diffs))13 fmt.Println(dmp.DiffBisect(a, b))14 fmt.Println(dmp.DiffBisectSplit(a, b, 0))15 fmt.Println(dmp.DiffCommonPrefix(a, b))16 fmt.Println(dmp.DiffCommonSuffix(a, b))17 fmt.Println(dmp.DiffCommonOverlap(a, b))18 fmt.Println(dmp.DiffHalfMatch(a, b))19 fmt.Println(dmp.DiffLinesToChars(a, b))20 fmt.Println(dmp.DiffCharsToLines(diffs, a))21 fmt.Println(dmp.DiffCleanupSemantic(diffs))22 fmt.Println(dmp.DiffCleanupSemanticLossless(diffs))23 fmt.Println(dmp.DiffCleanupEfficiency(diffs))24 fmt.Println(dmp.DiffCleanupMerge(diffs))25 fmt.Println(dmp.DiffXIndex(diffs, 1))26 fmt.Println(dmp.DiffXIndex(diffs, 2))27 fmt.Println(dmp.DiffXIndex(diffs, 3))28 fmt.Println(dmp.DiffXIndex(diffs, 4))29 fmt.Println(dmp.DiffXIndex(diffs, 5))30 fmt.Println(dmp.DiffXIndex(diffs, 6))31 fmt.Println(dmp.DiffXIndex(diffs, 7))32 fmt.Println(dmp.DiffXIndex(diffs, 8))33 fmt.Println(dmp.DiffXIndex(diffs, 9))34 fmt.Println(dmp.DiffXIndex(diffs, 10))35 fmt.Println(dmp.DiffXIndex(diffs, 11))36 fmt.Println(dmp.DiffXIndex(diffs, 12))37 fmt.Println(dmp.DiffXIndex(diffs, 13))38 fmt.Println(dmp.DiffXIndex(diffs, 14))39 fmt.Println(dmp.DiffXIndex(diffs, 15))40 fmt.Println(dmp.DiffXIndex(diffs,

Full Screen

Full Screen

Occurrence

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Scan(&a, &b)4 fmt.Println(diff.Occurrence(a, b))5}6import "fmt"7func main() {8 fmt.Scan(&a, &b)9 fmt.Println(diff.Occurrence(a, b))10}11import "fmt"12func main() {13 fmt.Scan(&a, &b)14 fmt.Println(diff.Occurrence(a, b))15}16import "fmt"17func main() {18 fmt.Scan(&a, &b)19 fmt.Println(diff.Occurrence(a, b))20}21import "fmt"22func main() {23 fmt.Scan(&a, &b)24 fmt.Println(diff.Occurrence(a, b))25}26import "fmt"27func main() {28 fmt.Scan(&a, &b)29 fmt.Println(diff.Occurrence(a, b))30}31import "fmt"32func main() {33 fmt.Scan(&a, &b)34 fmt.Println(diff.Occurrence(a, b))35}36import "fmt"37func main() {38 fmt.Scan(&a, &b)39 fmt.Println(diff.Occurrence(a, b))40}41import "fmt"42func main() {43 fmt.Scan(&a, &b)44 fmt.Println(diff.Occurrence(a, b))45}

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful