This guide covers testing the Elementum CLI, including unit tests, integration tests, and manual testing with real apps.
# Run all tests from the repo root
go test ./...# Discovery tests
go test ./discovery/... -v
# Export tests
go test ./export/... -v# Generate coverage report
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out -o coverage.htmlThe CLI can be tested against real Elementum apps. Example:
- URL: https://appdemo.elementum.io/admin/apps/dealclosingprocess/flow
- Namespace:
dealclosingprocess
# 1. Build the CLI
go build -o ~/go/bin/ei .
# 2. Authenticate
ei auth login
# Follow prompts to enter credentialsei list objectsExpected output:
- Shows all apps and elements in your organization
- Displays type, name, and namespace
# By namespace
ei show app dealclosingprocess
# By URL
ei show app "https://appdemo.elementum.io/admin/apps/dealclosingprocess/flow"Expected output:
Deal Closing Process (app_xyz123)
├─ Fields (N)
│ ├─ Title [text] required
│ ├─ Status [dropdown] (3 options)
│ └─ ...
├─ Layouts (N)
├─ Flows (N)
├─ Automations (N)
├─ Agents (N)
├─ Widgets (N)
├─ AI File Readers (N)
└─ Approval Processes (N)
Summary
• N fields
• N layouts
• N automations
• N agents
• N flows
• N widgets
• N AI file readers
• N approval processes
ei export app dealclosingprocessExpected behavior:
- Shows interactive multi-select
- Displays counts for each resource type
- Includes AI File Readers and Approval Processes options
- Generates import blocks and Terraform config
ei export app dealclosingprocess --all -o dealclosingprocess.tfExpected behavior:
- Discovers all resources automatically
- Generates import blocks for:
- App
- Fields (all types)
- Layouts
- Flows
- Agents + Tools
- Widgets
- AI File Readers
- Approval Processes
- Runs terraform init and plan
- Outputs generated.tf
# Create a test element first, then:
ei export element <namespace-or-id>ei export group "Engineering Team"ei export cloudlink "Production API"After export, verify the generated Terraform:
# 1. Check the generated file
cat generated.tf
# 2. Validate Terraform syntax
terraform validate
# 3. Check plan (should show no changes after import)
terraform plan
# Expected: "No changes. Your infrastructure matches the configuration."- ParseNamespaceFromURL handles various URL formats
- GetAppByNamespace finds apps correctly
- GetApp discovers all resource types:
- Fields
- Layouts
- Flows
- Automations
- Agents
- Widgets
- AI File Readers
- Approval Processes
- GetElement works by namespace and ID
- GetGroup works by name and ID
- GetCloudLink works by name and ID
- SanitizeName converts names correctly
- BuildImportID generates correct formats:
-
{app_id}for apps -
{element_id}for elements -
{group_id}for groups -
{cloudlink_id}for cloudlinks -
{app_id}:{field_id}for fields -
{app_id}:{file_reader_id}for AI file readers -
{app_id}:{approval_id}for approval processes
-
- GenerateImportBlocks handles all resource types
- Duplicate names get suffixes (_1, _2, etc.)
- RenderImportBlocks produces valid HCL
-
show appdisplays all resources in tree -
export appincludes all resource types in interactive mode -
export app --allexports everything -
export elementworks for elements -
export groupworks for groups -
export cloudlinkworks for cloudlinks - Help text is accurate
- Error messages are helpful
- All resources implement ImportState interface
- Import IDs match expected formats
- Terraform import works end-to-end
For comprehensive testing, create an app with:
- Multiple field types (text, number, dropdown, user, etc.)
- At least 2 layouts/stages
- 1+ flows
- 1+ automations with triggers and tasks
- 1+ agents with tools
- 1+ widgets
- 1+ AI file readers
- 1+ approval processes
- Name: "Products"
- Handle: "PROD"
- Namespace: "products"
- Fields: Title, Description, SKU, Price
- Name: "Engineering Team"
- Approver: true
- Members: 2+
- Name: "Production API"
- Type: "api"
- Valid: true
ei show app dealclosingprocess -v
ei export app dealclosingprocess --verbose# Set debug env var
export DEBUG_GRAPHQL=1
ei show app dealclosingprocessWhen export runs, it shows:
Working directory: /var/folders/.../elementum-export-xyz
You can inspect this directory to debug:
cd /var/folders/.../elementum-export-xyz
cat provider.tf
cat imports.tf
terraform plan# Run before committing
go test ./...
go vet ./...
golangci-lint run- Email Aliases - Not exportable (no ImportState in provider)
- Automations - Excluded from export (per requirements)
- System Fields - Skipped automatically (TITLE, STATUS, etc.)
- Duplicate Names - Get numeric suffixes
All tests pass:
✅ discovery tests
✅ export tests
✅ CLI builds without errors
✅ Commands work with real apps
✅ Generated Terraform is valid
✅ Terraform import succeeds
If tests fail:
- Check error messages carefully
- Enable verbose mode
- Verify authentication
- Check API permissions
- Review generated files in temp directory
For issues with specific resources:
- Verify resource exists in app
- Check import ID format
- Verify ImportState implementation
- Test with minimal example