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

Function Test_runUpdateCmd

pkg/cmd/objects/update/update_test.go:17–100  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func Test_runUpdateCmd(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 updated 1 objects on foo in",
34 },
35 {
36 name: "from file",
37 cli: fmt.Sprintf("foo -F '%s'", tmpFile),
38 wantOut: "✓ Successfully updated 1 objects on foo in",
39 },
40 {
41 name: "from stdin with invalid JSON",
42 cli: "foo -F -",
43 stdin: `{"objectID": "foo"},`,
44 wantErr: "X Found 1 error (out of 1 objects) while parsing the file:\n line 1: invalid JSON: invalid character ',' after top-level value\n",
45 },
46 {
47 name: "from stdin with invalid JSON (multiple objects)",
48 cli: "foo -F -",
49 stdin: `{"objectID": "foo"},
50 {"test": "bar"}`,
51 wantErr: "X Found 2 errors (out of 2 objects) while parsing the file:\n line 1: invalid JSON: invalid character ',' after top-level value\n line 2: objectID is required\n",
52 },
53 {
54 name: "from stdin with invalid JSON (1 object) with --continue-on-error",
55 cli: "foo -F - --continue-on-error",
56 stdin: `{"objectID": "foo"},`,
57 wantErr: "X Found 1 error (out of 1 objects) while parsing the file:\n line 1: invalid JSON: invalid character ',' after top-level value\n",
58 },
59 {
60 name: "from stdin with invalid JSON (2 objects) with --continue-on-error",
61 cli: "foo -F - --continue-on-error",
62 stdin: `{"objectID": "foo"}
63 {"test": "bar"}`,
64 wantOut: "✓ Successfully updated 1 objects on foo in",
65 },
66 {
67 name: "missing file flag",
68 cli: "foo",
69 wantErr: "required flag(s) \"file\" not set",
70 },
71 {
72 name: "non-existant file",
73 cli: "foo -F /tmp/foo",
74 wantErr: "open /tmp/foo: no such file or directory",

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

Tested by

no test coverage detected