Skip to content

test: Add comprehensive testing infrastructure (Phase 2)#11

Merged
rianjs merged 10 commits intoopen-cli-collective:mainfrom
rianjs:feature/phase2-testing-infrastructure
Jan 11, 2026
Merged

test: Add comprehensive testing infrastructure (Phase 2)#11
rianjs merged 10 commits intoopen-cli-collective:mainfrom
rianjs:feature/phase2-testing-infrastructure

Conversation

@rianjs
Copy link
Copy Markdown
Collaborator

@rianjs rianjs commented Jan 11, 2026

Summary

  • Add unit tests for API client with httptest mocking (27 tests)
  • Add unit tests for keychain/credential storage (12 tests)
  • Add unit tests for command handler helpers (19 tests)
  • Create integration-tests.md manual test documentation

This is Phase 2 of the CLI guide alignment roadmap (Issue #2).

Note: This PR includes Phase 1 commits. Once PR #10 is merged, this can be rebased to show only Phase 2 changes.

Changes

API Client Tests (internal/client/client_test.go)

  • Add NewWithConfig constructor for test injection
  • 27 tests covering all client methods
  • Tests for pagination, error handling, auth headers
  • Uses httptest.NewServer for HTTP mocking

Keychain Tests (internal/keychain/keychain_test.go)

  • 12 tests for credential storage
  • Tests config file operations (set, get, delete)
  • Tests file permissions (0600 for credentials, 0700 for directory)
  • Tests XDG_CONFIG_HOME support
  • Platform-aware test skipping for keychain-specific tests

Command Tests (cmd/messages_test.go)

  • Tests for helper functions (formatTimestamp, truncate, buildDefaultBlocks)
  • Tests for command structure and registration
  • Table-driven tests with t.Run

Integration Tests (integration-tests.md)

  • Test environment setup guide
  • Test matrix for all commands
  • Edge cases and error scenarios
  • Pre-release test checklist
  • Troubleshooting guide

Test Coverage

ok  github.com/piekstra/slack-cli/cmd                  0.2s
ok  github.com/piekstra/slack-cli/internal/client      0.2s
ok  github.com/piekstra/slack-cli/internal/keychain    0.2s

Test plan

  • All new tests pass: go test ./...
  • Lint passes: golangci-lint run
  • Tests use proper mocking (no real API calls)
  • Tests are table-driven where appropriate

Fixes #2

🤖 Generated with Claude Code

rianjs and others added 10 commits January 11, 2026 09:38
Add CI workflow that runs on every push to main and every PR:
- Build and test job with race detection and coverage
- Lint job using golangci-lint

This establishes the foundation for validating all future changes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add .golangci.yml with standard linters:
- errcheck, govet, ineffassign, staticcheck, unused, misspell
- gofmt and goimports formatters with local prefix

Fix lint issues found:
- Replace fmt.Sscanf with strconv.ParseInt in formatTimestamp
- Properly handle resp.Body.Close() errors using named returns
- Fix import ordering with goimports

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add build-time version injection via ldflags:
- VERSION from git describe
- COMMIT from git rev-parse
- DATE from current time

Add new targets:
- test-cover: Run tests with coverage report
- test-short: Run quick tests
- lint: Run golangci-lint
- fmt: Run gofmt and goimports
- deps: Download and tidy dependencies
- verify: Verify go.mod

Update build target to output to bin/ directory.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add version package with variables set via ldflags:
- Version: semantic version from git tag
- Commit: git commit hash
- Date: build timestamp

Includes Info() helper for formatted version string.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add version information to root command:
- Set Version field from version package
- Custom version template showing commit and build date

Now `slack-cli --version` shows:
  slack-cli vX.Y.Z (commit: abc123, built: 2024-...)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Apply goimports formatting with local prefix to ensure consistent
import ordering across all command files.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add NewWithConfig constructor for test injection with custom:
- Base URL (for httptest servers)
- Token
- HTTP client

Add 27 tests covering:
- Client configuration and initialization
- Channel operations (list, get, create, archive, unarchive, topic, purpose, invite)
- User operations (list, get)
- Message operations (send, update, delete, history, thread replies)
- Reactions (add, remove)
- Team info
- Pagination handling
- API error handling
- Network error handling
- Invalid JSON handling
- Auth header verification

All tests use httptest.NewServer for HTTP mocking.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add 12 tests covering:
- GetAPIToken from environment variable
- GetAPIToken when no token configured
- IsSecureStorage platform detection
- Config directory resolution (default and XDG_CONFIG_HOME)
- Config file operations (set, get, delete)
- Multiple keys handling
- Key updates
- File permissions (0600 for file, 0700 for directory)
- Values containing equals signs

Uses t.TempDir() and t.Setenv() for isolated testing.
Skip keychain-dependent tests on macOS where appropriate.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add tests for messages.go helper functions:
- formatTimestamp: timestamp parsing and formatting
- truncate: string truncation with newline handling
- buildDefaultBlocks: Block Kit structure generation

Add tests for command structure:
- Verify messages command registration
- Verify subcommands exist (send, update, delete, etc.)
- Verify command aliases (msg, m)

Uses table-driven tests with t.Run for clear test cases.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive manual test documentation covering:
- Test environment setup and prerequisites
- Test data conventions
- Command tests for all operations:
  - Configuration (set-token, show, delete-token)
  - Channels (list, get, create, archive, topic, invite)
  - Users (list, get)
  - Messages (send, update, delete, history, thread, react)
  - Workspace (info)
- Edge cases and error scenarios
- Pre-release test execution checklist
- Troubleshooting guide

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@rianjs rianjs merged commit 2daaec3 into open-cli-collective:main Jan 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Epic: Phase 2 - Testing Infrastructure

1 participant