Use this file to discover all available pages before exploring further.
Testing is a critical part of contributing to Meshery. This guide covers testing strategies, tools, and best practices for Go (server/CLI), JavaScript (UI), and integration testing.
Go unit tests use the standard library testing package.File naming: Place tests in *_test.go files alongside the code they test.Test naming: Use descriptive names: TestFunctionName_Scenario_ExpectedResultExample unit test:
func TestValidateWorkspaceName(t *testing.T) { tests := []struct { name string input string expected bool }{ {"valid name", "my-workspace", true}, {"empty name", "", false}, {"too long", "a" + strings.Repeat("b", 100), false}, {"special chars", "my@workspace", false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result := ValidateWorkspaceName(tt.input) if result != tt.expected { t.Errorf("ValidateWorkspaceName(%q) = %v, want %v", tt.input, result, tt.expected) } }) }}
Running unit tests:
# Run all tests in current directorygo test .# Run all tests recursivelygo test ./...# Run only short tests (skip integration tests)go test --short ./...# Run specific testgo test -run TestValidateWorkspaceName# Run with coveragego test -cover ./...# Generate coverage reportgo test -coverprofile=coverage.out ./...go tool cover -html=coverage.out
Integration tests verify interactions with external systems like Kubernetes and databases.Location:server/integration-tests/MeshSync Integration Tests:
# Check dependencies (Docker, kind, kubectl, helm)make server-integration-tests-meshsync-check-dependencies# Setup test environmentmake server-integration-tests-meshsync-setup# Run testsmake server-integration-tests-meshsync-run# Cleanupmake server-integration-tests-meshsync-cleanup# Full cycle (build + setup + run + cleanup)make server-integration-tests-meshsync
What the setup does:
Creates a kind (Kubernetes in Docker) cluster
Deploys Meshery Operator to the cluster
Starts NATS messaging broker
Configures connection between test cluster and Meshery Server
Meshery UI uses Playwright for end-to-end testing.Install Playwright:
make test-setup-ui
This installs Playwright browsers (Chromium) with system dependencies.Run E2E tests:
# Interactive modemake ui-integration-tests# Or with npmcd uinpm run test:e2e# CI mode (non-interactive)make test-e2e-ci# Or with npmcd uinpm run test:e2e:ci
Test file location:ui/tests/ or ui/**/*.spec.jsExample Playwright test:
// ui/tests/workspaces.spec.jsimport { test, expect } from '@playwright/test';test.describe('Workspace Management', () => { test.beforeEach(async ({ page }) => { await page.goto('http://localhost:3000'); }); test('should create a new workspace', async ({ page }) => { // Navigate to workspaces page await page.click('a:has-text("Workspaces")'); // Click create button await page.click('button:has-text("Create Workspace")'); // Fill form await page.fill('input[name="name"]', 'Test Workspace'); await page.fill('textarea[name="description"]', 'This is a test workspace'); // Submit form await page.click('button:has-text("Save")'); // Verify workspace appears in list await expect(page.locator('text=Test Workspace')).toBeVisible(); }); test('should filter workspaces', async ({ page }) => { await page.goto('http://localhost:3000/workspaces'); // Type in search box await page.fill('input[placeholder="Search workspaces"]', 'Test'); // Verify filtered results const results = page.locator('[data-testid="workspace-card"]'); await expect(results).toHaveCount(1); }); test('should delete workspace', async ({ page }) => { await page.goto('http://localhost:3000/workspaces'); // Click delete button await page.click('[data-testid="delete-workspace-btn"]'); // Confirm deletion await page.click('button:has-text("Confirm")'); // Verify workspace removed await expect(page.locator('text=Test Workspace')).not.toBeVisible(); });});
Avoid hardcoded waits; use Playwright’s auto-waiting
Test user workflows, not implementation details
Keep tests independent and idempotent
Use descriptive test names
Debugging Playwright tests:
# Run in headed mode (show browser)npx playwright test --headed# Run in debug modenpx playwright test --debug# Run specific test filenpx playwright test tests/workspaces.spec.js# Show test reportnpx playwright show-report