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

Function Test_runOperationsCmd

pkg/cmd/objects/operations/operations_test.go:17–107  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func Test_runOperationsCmd(t *testing.T) {
18 tmpFile := filepath.Join(t.TempDir(), "operations.json")
19 err := os.WriteFile(
20 tmpFile,
21 []byte(
22 `{"action":"addObject","indexName":"index1","body":{"firstname":"Jimmie","lastname":"Barninger"}}`,
23 ),
24 0o600,
25 )
26 require.NoError(t, err)
27
28 tests := []struct {
29 name string
30 cli string
31 stdin string
32 wantOut string
33 wantErr string
34 }{
35 {
36 name: "from stdin",
37 cli: "-F -",
38 stdin: `{"action":"addObject","indexName":"index1","body":{"firstname":"Jimmie","lastname":"Barninger"}}`,
39 wantOut: "✓ Successfully processed 1 operations in",
40 },
41 {
42 name: "from file",
43 cli: fmt.Sprintf("-F '%s'", tmpFile),
44 wantOut: "✓ Successfully processed 1 operations in",
45 },
46 {
47 name: "from stdin with invalid JSON",
48 cli: "-F -",
49 stdin: `{"action":"addObject","indexName":"index1","body":{"firstname":"Jimmie","lastname":"Barninger"}},`,
50 wantErr: "X Found 1 error (out of 1 operations) while parsing the file:\n line 1: invalid JSON: invalid character ',' after top-level value\n",
51 },
52
53 {
54 name: "from stdin with invalid JSON (multiple operations)",
55 cli: "-F -",
56 stdin: `{"action": "addObject","indexName":"index1"},
57 {"test": "bar"}`,
58 wantErr: "X Found 2 errors (out of 2 operations) while parsing the file:\n line 1: invalid JSON: invalid character ',' after top-level value\n line 2: missing action\n",
59 },
60 {
61 name: "from stdin with invalid JSON (1 operation) with --continue-on-error",
62 cli: "-F - --continue-on-error",
63 stdin: `{"action": "addObject"},`,
64 wantErr: "X Found 1 error (out of 1 operations) while parsing the file:\n line 1: invalid JSON: invalid character ',' after top-level value\n",
65 },
66 {
67 name: "from stdin with invalid JSON (2 objects) with --continue-on-error",
68 cli: "-F - --continue-on-error",
69 stdin: `{"action": "addObject","indexName":"index1"}
70 {"action": "deleteObject","indexName":"index2",body:{"objectID": "abc"}}`,
71 wantOut: "✓ Successfully processed 1 operations in",
72 },
73 {
74 name: "missing file flag",

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
NewOperationsCmdFunction · 0.85
RunMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected