MCPcopy
hub / github.com/cli/cli / TestNewCmdCheckout

Function TestNewCmdCheckout

pkg/cmd/pr/checkout/checkout_test.go:29–105  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestNewCmdCheckout(t *testing.T) {
30 tests := []struct {
31 name string
32 args string
33 wantsOpts CheckoutOptions
34 wantErr error
35 }{
36 {
37 name: "recurse submodules",
38 args: "--recurse-submodules 123",
39 wantsOpts: CheckoutOptions{
40 RecurseSubmodules: true,
41 },
42 },
43 {
44 name: "force",
45 args: "--force 123",
46 wantsOpts: CheckoutOptions{
47 Force: true,
48 },
49 },
50 {
51 name: "detach",
52 args: "--detach 123",
53 wantsOpts: CheckoutOptions{
54 Detach: true,
55 },
56 },
57 {
58 name: "branch",
59 args: "--branch test-branch 123",
60 wantsOpts: CheckoutOptions{
61 BranchName: "test-branch",
62 },
63 },
64 {
65 name: "when there is no selector and no TTY, returns an error",
66 args: "",
67 wantErr: cmdutil.FlagErrorf("pull request number, URL, or branch required when not running interactively"),
68 },
69 }
70
71 for _, tt := range tests {
72 t.Run(tt.name, func(t *testing.T) {
73 ios, _, _, _ := iostreams.Test()
74 f := &cmdutil.Factory{
75 IOStreams: ios,
76 }
77
78 ios.SetStdinTTY(false)
79
80 argv, err := shlex.Split(tt.args)
81 assert.NoError(t, err)
82
83 var spiedOpts *CheckoutOptions
84 cmd := NewCmdCheckout(f, func(opts *CheckoutOptions) error {
85 spiedOpts = opts
86 return nil

Callers

nothing calls this directly

Calls 6

FlagErrorfFunction · 0.92
TestFunction · 0.92
NewCmdCheckoutFunction · 0.85
SetStdinTTYMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected