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

Function Test_runImportCmd

pkg/cmd/objects/import/import_test.go:17–98  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func Test_runImportCmd(t *testing.T) {
18 tmpFile := filepath.Join(t.TempDir(), "objects.json")
19 err := os.WriteFile(tmpFile, []byte("{\"objectID\":\"foo\"}"), 0o600)
20 require.NoError(t, err)
21
22 tests := []struct {
23 name string
24 cli string
25 stdin string
26 wantOut string
27 wantErr string
28 }{
29 {
30 name: "from stdin",
31 cli: "foo -F -",
32 stdin: `{"objectID": "foo"}`,
33 wantOut: "✓ Successfully imported 1 objects to foo in",
34 },
35 {
36 name: "from file",
37 cli: fmt.Sprintf("foo -F '%s'", tmpFile),
38 wantOut: "✓ Successfully imported 1 objects to foo in",
39 },
40 {
41 name: "empty record",
42 cli: "foo -F -",
43 stdin: `{}`,
44 wantErr: "empty object on line 0",
45 },
46 {
47 name: "missing objectID",
48 cli: "foo -F -",
49 stdin: `{"attribute": "foo"}`,
50 wantErr: "missing objectID on line 0",
51 },
52 {
53 name: "with auto-generated objectID",
54 cli: "foo --auto-generate-object-id-if-not-exist -F -",
55 stdin: `{"attribute": "foo"}`,
56 wantOut: "✓ Successfully imported 1 objects to foo in",
57 },
58 {
59 name: "from stdin with invalid JSON",
60 cli: "foo -F -",
61 stdin: `{"objectID", "foo"},`,
62 wantErr: "failed to parse JSON object on line 0: invalid character ',' after object key",
63 },
64 {
65 name: "missing file flag",
66 cli: "foo",
67 wantErr: "required flag(s) \"file\" not set",
68 },
69 {
70 name: "non-existant file",
71 cli: "foo -F /tmp/foo",
72 wantErr: "open /tmp/foo: no such file or directory",
73 },
74 }

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
NewImportCmdFunction · 0.70
RunMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected