MCPcopy Create free account
hub / github.com/cli/cli / TestNewCmdCreate

Function TestNewCmdCreate

pkg/cmd/repo/autolink/create/create_test.go:19–93  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestNewCmdCreate(t *testing.T) {
20 tests := []struct {
21 name string
22 input string
23 output createOptions
24 wantErr bool
25 errMsg string
26 }{
27 {
28 name: "no argument",
29 input: "",
30 wantErr: true,
31 errMsg: "Cannot create autolink: keyPrefix and urlTemplate arguments are both required",
32 },
33 {
34 name: "one argument",
35 input: "TEST-",
36 wantErr: true,
37 errMsg: "Cannot create autolink: keyPrefix and urlTemplate arguments are both required",
38 },
39 {
40 name: "two argument",
41 input: "TICKET- https://example.com/TICKET?query=<num>",
42 output: createOptions{
43 KeyPrefix: "TICKET-",
44 URLTemplate: "https://example.com/TICKET?query=<num>",
45 },
46 },
47 {
48 name: "numeric flag",
49 input: "TICKET- https://example.com/TICKET?query=<num> --numeric",
50 output: createOptions{
51 KeyPrefix: "TICKET-",
52 URLTemplate: "https://example.com/TICKET?query=<num>",
53 Numeric: true,
54 },
55 },
56 }
57
58 for _, tt := range tests {
59 t.Run(tt.name, func(t *testing.T) {
60 ios, _, _, _ := iostreams.Test()
61 f := &cmdutil.Factory{
62 IOStreams: ios,
63 }
64 f.HttpClient = func() (*http.Client, error) {
65 return &http.Client{}, nil
66 }
67
68 argv, err := shlex.Split(tt.input)
69 require.NoError(t, err)
70
71 var gotOpts *createOptions
72 cmd := NewCmdCreate(f, func(opts *createOptions) error {
73 gotOpts = opts
74 return nil
75 })
76

Callers

nothing calls this directly

Calls 4

TestFunction · 0.92
EqualMethod · 0.80
NewCmdCreateFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected