(t *testing.T)
| 436 | } |
| 437 | |
| 438 | func TestUpdateDevVersion_JSON(t *testing.T) { |
| 439 | // Same state-isolation rationale as TestUpdateNpm_JSON. |
| 440 | t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir()) |
| 441 | |
| 442 | f, stdout, _ := newTestFactory(t) |
| 443 | cmd := NewCmdUpdate(f) |
| 444 | cmd.SetArgs([]string{"--json"}) |
| 445 | |
| 446 | origFetch := fetchLatest |
| 447 | fetchLatest = func() (string, error) { return "1.0.0", nil } |
| 448 | defer func() { fetchLatest = origFetch }() |
| 449 | origVersion := currentVersion |
| 450 | currentVersion = func() string { return "DEV" } |
| 451 | defer func() { currentVersion = origVersion }() |
| 452 | mockDetectAndNpm(t, |
| 453 | selfupdate.DetectResult{Method: selfupdate.InstallNpm, ResolvedPath: "/node_modules/@larksuite/cli/bin/lark-cli", NpmAvailable: true}, |
| 454 | func(version string) *selfupdate.NpmResult { return &selfupdate.NpmResult{} }, |
| 455 | ) |
| 456 | |
| 457 | err := cmd.Execute() |
| 458 | if err != nil { |
| 459 | t.Fatalf("unexpected error: %v", err) |
| 460 | } |
| 461 | out := stdout.String() |
| 462 | if !strings.Contains(out, `"action": "updated"`) { |
| 463 | t.Errorf("expected updated in JSON output, got: %s", out) |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | func TestUpdateNpmFail_JSON(t *testing.T) { |
| 468 | f, stdout, _ := newTestFactory(t) |
nothing calls this directly
no test coverage detected