(test *testing.T)
| 68 | } |
| 69 | |
| 70 | func TestCodeAccessSides(test *testing.T) { |
| 71 | current, previous := comparisonReaders(test) |
| 72 | access, err := NewComparisonCodeAccess(current, previous) |
| 73 | if err != nil { |
| 74 | test.Fatal(err) |
| 75 | } |
| 76 | baseline := comparisonProviders(¤t, nil) |
| 77 | for index, provider := range comparisonProviders(¤t, access) { |
| 78 | test.Run(provider.Tool().Name(), func(test *testing.T) { |
| 79 | args := comparisonArgs(provider.Tool().Name()) |
| 80 | want, err := baseline[index].Execute(context.Background(), args) |
| 81 | if err != nil { |
| 82 | test.Fatal(err) |
| 83 | } |
| 84 | for _, explicit := range []bool{false, true} { |
| 85 | if explicit { |
| 86 | args["side"] = "new" |
| 87 | } |
| 88 | got, err := provider.Execute(context.Background(), args) |
| 89 | if err != nil || got != want { |
| 90 | test.Fatalf("default/new output changed: %q, %v; want %q", got, err, want) |
| 91 | } |
| 92 | } |
| 93 | args["side"] = "old" |
| 94 | got, err := provider.Execute(context.Background(), args) |
| 95 | if err != nil || !strings.HasPrefix(got, "SIDE: old\nREVISION: "+previous.Ref+"\n") { |
| 96 | test.Fatalf("old source missing: %q, %v", got, err) |
| 97 | } |
| 98 | if strings.Contains(got, "new-marker") || strings.Contains(got, "workspace-marker") || strings.Contains(got, "after.txt") { |
| 99 | test.Fatalf("old side leaked new content: %s", got) |
| 100 | } |
| 101 | if provider.Tool() != FileRead && (!strings.Contains(got, "removed.txt") || !strings.Contains(got, "before.txt")) { |
| 102 | test.Fatalf("old paths missing: %s", got) |
| 103 | } |
| 104 | for _, invalid := range []any{nil, "", "OLD", "HEAD", true, float64(1)} { |
| 105 | args["side"] = invalid |
| 106 | if _, err := provider.Execute(context.Background(), args); err == nil { |
| 107 | test.Fatalf("accepted invalid side %#v", invalid) |
| 108 | } |
| 109 | } |
| 110 | args["side"] = "old" |
| 111 | cancelled, cancel := context.WithCancel(context.Background()) |
| 112 | cancel() |
| 113 | if _, err := provider.Execute(cancelled, args); !errors.Is(err, context.Canceled) { |
| 114 | test.Fatalf("cancellation lost: %v", err) |
| 115 | } |
| 116 | for _, side := range []any{"old", "new", nil} { |
| 117 | args["side"] = side |
| 118 | if _, err := baseline[index].Execute(context.Background(), args); err == nil { |
| 119 | test.Fatalf("current-only provider accepted side %#v", side) |
| 120 | } |
| 121 | } |
| 122 | }) |
| 123 | } |
| 124 | reader := NewFileRead(¤t) |
| 125 | reader.Access = access |
| 126 | for _, name := range []string{"removed.txt", "before.txt", "after.txt"} { |
| 127 | for _, side := range []string{"old", "new"} { |
nothing calls this directly
no test coverage detected