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

Function Test_runCreateCmd

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

Source from the content-addressed store, hash-verified

80}
81
82func Test_runCreateCmd(t *testing.T) {
83 tmpFile := filepath.Join(t.TempDir(), "config.json")
84 err := os.WriteFile(tmpFile, []byte("{\"enableReRanking\":false}"), 0o600)
85 require.NoError(t, err)
86
87 tests := []struct {
88 name string
89 cli string
90 isTTY bool
91 wantOut string
92 }{
93 {
94 name: "no tty",
95 cli: fmt.Sprintf("my-crawler -F '%s'", tmpFile),
96 isTTY: false,
97 wantOut: "",
98 },
99 {
100 name: "tty",
101 cli: fmt.Sprintf("my-crawler -F '%s'", tmpFile),
102 isTTY: true,
103 wantOut: "✓ Crawler my-crawler created: crawler-id\n",
104 },
105 }
106
107 for _, tt := range tests {
108 t.Run(tt.name, func(t *testing.T) {
109 r := httpmock.Registry{}
110 res := crawler.Crawler{ID: "crawler-id"}
111 r.Register(httpmock.REST("POST", "api/1/crawlers"), httpmock.JSONResponse(res))
112 defer r.Verify(t)
113
114 f, out := test.NewFactory(tt.isTTY, &r, nil, "")
115 cmd := NewCreateCmd(f, nil)
116 out, err := test.Execute(cmd, tt.cli, out)
117 if err != nil {
118 t.Fatal(err)
119 }
120
121 assert.Equal(t, tt.wantOut, out.String())
122 })
123 }
124}
125
126func Test_runCreateCmd_dryRunJSON(t *testing.T) {
127 tmpFile := filepath.Join(t.TempDir(), "config.json")

Callers

nothing calls this directly

Calls 9

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
JSONResponseFunction · 0.92
NewFactoryFunction · 0.92
ExecuteFunction · 0.92
NewCreateCmdFunction · 0.70
RunMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected