(t *testing.T)
| 269 | } |
| 270 | |
| 271 | func TestUpdateForce_JSON(t *testing.T) { |
| 272 | // Same state-isolation rationale as TestUpdateNpm_JSON. |
| 273 | t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir()) |
| 274 | |
| 275 | f, stdout, _ := newTestFactory(t) |
| 276 | cmd := NewCmdUpdate(f) |
| 277 | cmd.SetArgs([]string{"--force", "--json"}) |
| 278 | |
| 279 | origFetch := fetchLatest |
| 280 | fetchLatest = func() (string, error) { return "1.0.0", nil } |
| 281 | defer func() { fetchLatest = origFetch }() |
| 282 | origVersion := currentVersion |
| 283 | currentVersion = func() string { return "1.0.0" } |
| 284 | defer func() { currentVersion = origVersion }() |
| 285 | mockDetectAndNpm(t, |
| 286 | selfupdate.DetectResult{Method: selfupdate.InstallNpm, ResolvedPath: "/node_modules/@larksuite/cli/bin/lark-cli", NpmAvailable: true}, |
| 287 | func(version string) *selfupdate.NpmResult { return &selfupdate.NpmResult{} }, |
| 288 | ) |
| 289 | |
| 290 | err := cmd.Execute() |
| 291 | if err != nil { |
| 292 | t.Fatalf("unexpected error: %v", err) |
| 293 | } |
| 294 | out := stdout.String() |
| 295 | if !strings.Contains(out, `"action": "updated"`) { |
| 296 | t.Errorf("expected updated in JSON output, got: %s", out) |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | func TestUpdateFetchError_JSON(t *testing.T) { |
| 301 | f, stdout, _ := newTestFactory(t) |
nothing calls this directly
no test coverage detected