MCPcopy Create free account
hub / github.com/algolia/cli / TestNewCreateCmd

Function TestNewCreateCmd

pkg/cmd/crawler/create/create_test.go:20–80  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestNewCreateCmd(t *testing.T) {
21 tmpFile := filepath.Join(t.TempDir(), "config.json")
22 err := os.WriteFile(tmpFile, []byte("{\"appId\":\"test-app\"}"), 0o600)
23 require.NoError(t, err)
24
25 tests := []struct {
26 name string
27 tty bool
28 cli string
29 wantsErr bool
30 wantsOpts CreateOptions
31 }{
32 {
33 name: "no tty",
34 cli: fmt.Sprintf("my-crawler -F '%s'", tmpFile),
35 tty: false,
36 wantsErr: false,
37 wantsOpts: CreateOptions{
38 Name: "my-crawler",
39 config: crawler.Config{AppID: "test-app"},
40 },
41 },
42 }
43
44 for _, tt := range tests {
45 t.Run(tt.name, func(t *testing.T) {
46 io, _, stdout, stderr := iostreams.Test()
47 if tt.tty {
48 io.SetStdinTTY(tt.tty)
49 io.SetStdoutTTY(tt.tty)
50 }
51
52 f := &cmdutil.Factory{
53 IOStreams: io,
54 }
55
56 var opts *CreateOptions
57 cmd := NewCreateCmd(f, func(o *CreateOptions) error {
58 opts = o
59 return nil
60 })
61
62 args, err := shlex.Split(tt.cli)
63 require.NoError(t, err)
64 cmd.SetArgs(args)
65 _, err = cmd.ExecuteC()
66 if tt.wantsErr {
67 assert.Error(t, err)
68 return
69 } else {
70 require.NoError(t, err)
71 }
72
73 assert.Equal(t, "", stdout.String())
74 assert.Equal(t, "", stderr.String())
75
76 assert.Equal(t, tt.wantsOpts.Name, opts.Name)
77 assert.Equal(t, tt.wantsOpts.config, opts.config)

Callers

nothing calls this directly

Calls 7

TestFunction · 0.92
SetStdinTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
NewCreateCmdFunction · 0.70
RunMethod · 0.45
ErrorMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected