(t *testing.T)
| 80 | } |
| 81 | |
| 82 | func 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 | |
| 126 | func Test_runCreateCmd_dryRunJSON(t *testing.T) { |
| 127 | tmpFile := filepath.Join(t.TempDir(), "config.json") |
nothing calls this directly
no test coverage detected