Repository: cli/cli
File: pkg/cmd/pr/view/view_test.go (Go)

Code before:
				`state:\tOPEN\n`,
				`author:\tnobody\n`,
				`labels:\t\n`,
				`assignees:\t\n`,
				`projects:\t\n`,
				`milestone:\t\n`,
				`additions:\t100\n`,
				`deletions:\t10\n`,
				`auto-merge:\tenabled\thubot\tsquash\n`,
			},
		},
		"PR with nil project": {
			branch: "master",
			args:   "12",
			fixtures: map[string]string{
				"PullRequestByNumber": "./fixtures/prViewPreviewWithNilProject.json",
			},
			expectedOutputs: []string{
				`projects:\t\n`,
			},
		},
	}

	for name, tc := range tests {
		t.Run(name, func(t *testing.T) {
			t.Cleanup(shared.ResetRunCommandFinder)

			http := &httpmock.Registry{}
			defer http.Verify(t)

			pr, err := prFromFixtures(tc.fixtures)
			require.NoError(t, err)
			shared.RunCommandFinder("12", pr, ghrepo.New("OWNER", "REPO"))

			output, err := runCommand(http, tc.branch, false, tc.args)
			if err != nil {
				t.Errorf("error running command `%v`: %v", tc.args, err)
			}

			assert.Equal(t, "", output.Stderr())

			//nolint:staticcheck // prefer exact matchers over ExpectLines
			test.ExpectLines(t, output.String(), tc.expectedOutputs...)
		})
	}
}

func TestPRView_Preview(t *testing.T) {
	tests := map[string]struct {
		branch          string
		args            string

Review comment (bug):
These were silly tests that were just leaving global state around that caused bizarre failures:

```
➜  cli git:(wm/projectsv1-deprecation-pr-view) ✗ go test -count=1 ./pkg/cmd/pr/view
--- FAIL: TestProjectsV1Deprecation (0.00s)
    --- FAIL: TestProjectsV1Deprecation/when_projects_v1_is_supported,_is_included_in_query (0.00s)
        view_test.go:908: 1 HTTP stubs unmatched, stacks:
            Stub 1:
                goroutine 82 [running]:
            runtime/debug.Stack()
                /opt/homebrew/Cellar/go/1.24.0/libexec/src/runtime/debug/stack.go:26 +0x64
            github.com/cli/cli/v2/pkg/httpmock.(*Registry).Register(...)
                /Users/williammartin/workspace/cli/pkg/httpmock/registry.go:26
            github.com/cli/cli/v2/pkg/cmd/pr/view.TestProjectsV1Deprecation.func1(0x1400009ba40)
                /Users/williammartin/workspace/cli/pkg/cmd/pr/view/view_test.go:881 +0x88
            testing.tRunner(0x1400009ba40, 0x100f52fc0)
                /opt/homebrew/Cellar/go/1.24.0/libexec/src/testing/testing.go:1792 +0xe4
            created by testing.(*T).Run in goroutine 81
                /opt/homebrew/Cellar/go/1.24.0/libexec/src/testing/testing.go:1851 +0x374
FAIL
FAIL    github.com/cli/cli/v2/pkg/cmd/pr/view   0.364s
FAIL

➜  cli git:(wm/projectsv1-deprecation-pr-view) ✗ go test -count=1 -run ^TestProjectsV1Deprecation$ ./pkg/cmd/pr/view
ok      github.com/cli/cli/v2/pkg/cmd/pr/view   0.404s
```

Code after:
				`state:\tOPEN\n`,
				`author:\tnobody\n`,
				`labels:\t\n`,
				`assignees:\t\n`,
				`projects:\t\n`,
				`milestone:\t\n`,
				`additions:\t100\n`,
				`deletions:\t10\n`,
				`auto-merge:\tenabled\thubot\tsquash\n`,
			},
		},
		"PR with nil project": {
			branch: "master",
			args:   "12",
			fixtures: map[string]string{
				"PullRequestByNumber": "./fixtures/prViewPreviewWithNilProject.json",
			},
			expectedOutputs: []string{
				`projects:\t\n`,
			},
		},
	}

	for name, tc := range tests {
		t.Run(name, func(t *testing.T) {
			http := &httpmock.Registry{}
			defer http.Verify(t)

			pr, err := prFromFixtures(tc.fixtures)
			require.NoError(t, err)
			shared.StubFinderForRunCommandStyleTests(t, "12", pr, ghrepo.New("OWNER", "REPO"))

			output, err := runCommand(http, tc.branch, false, tc.args)
			if err != nil {
				t.Errorf("error running command `%v`: %v", tc.args, err)
			}

			assert.Equal(t, "", output.Stderr())

			//nolint:staticcheck // prefer exact matchers over ExpectLines
			test.ExpectLines(t, output.String(), tc.expectedOutputs...)
		})
	}
}

func TestPRView_Preview(t *testing.T) {
	tests := map[string]struct {
		branch          string
		args            string
		fixtures        map[string]string
		expectedOutputs []string