package cmd // TableTestStandards defines standardized field names and patterns for table-driven tests // This file serves as documentation and helper types for consistent table test structure // // IMPLEMENTED STANDARDIZATION: // Successfully standardized field naming across all cmd test files: // - expectedOut/expectedOutput → wantOutput // - expectError → wantError // - expectedError → wantErrorMsg // // Files standardized: // - cmd_commands_test.go (multiple test functions) // - cmd_root_test.go (completion and execute tests) // - cmd_logswatch_test.go (logs watch tests) // - cmd_service_test.go (service command tests) // - status_command_refactored_test.go (status tests) // StandardTestCase provides a standardized structure for basic table-driven tests type StandardTestCase struct { Name string `json:"name"` // Test case name - REQUIRED Args []string `json:"args"` // Command arguments WantOutput string `json:"wantOutput"` // Expected output content WantError bool `json:"wantError"` // Whether error is expected WantErrorMsg string `json:"wantErrorMsg"` // Specific error message to check (optional) } // CommandTestCase extends StandardTestCase for command testing with mock setup type CommandTestCase struct { StandardTestCase Setup func(*MockClientBuilder) `json:"-"` // Setup function for mock configuration MockSetup func(interface{}) `json:"-"` // Generic mock setup function } // ServiceTestCase specialized for service command testing type ServiceTestCase struct { StandardTestCase MockResponse string `json:"mockResponse"` // Mock service response MockError error `json:"mockError"` // Mock service error } // LogsTestCase specialized for logs command testing type LogsTestCase struct { StandardTestCase MockLogs []string `json:"mockLogs"` // Mock log lines Limit int `json:"limit"` // Log limit } // StandardFieldNames defines the recommended field naming conventions var StandardFieldNames = map[string]string{ // Required fields "name": "name", // Test case identifier "args": "args", // Command arguments // Output expectations "expectedOutput": "wantOutput", // Use wantOutput instead "expectedOut": "wantOutput", // Use wantOutput instead "expected": "wantOutput", // Use wantOutput instead // Error expectations "expectError": "wantError", // Use wantError instead "isError": "wantError", // Use wantError instead "expectedError": "wantErrorMsg", // Use wantErrorMsg instead // Setup patterns "setupMock": "setup", // Use setup instead "mockSetup": "setup", // Use setup instead "setupBanned": "setup", // Use setup instead "setupBans": "setup", // Use setup instead } // ConversionGuide provides examples of before/after standardization type ConversionGuide struct { Before string After string Reason string } // StandardizationExamples provides examples of before/after field name conversions var StandardizationExamples = []ConversionGuide{ { Before: `tests := []struct { name string args []string expectedOut string expectError bool }`, After: `tests := []struct { name string args []string wantOutput string wantError bool }`, Reason: "Consistent with Go testing conventions using 'want' prefix", }, { Before: `if output != tt.expectedOut { t.Errorf("expected %q, got %q", tt.expectedOut, output) }`, After: `if output != tt.wantOutput { t.Errorf("expected %q, got %q", tt.wantOutput, output) }`, Reason: "Consistent field naming reduces cognitive load", }, { Before: `AssertError(t, err, tt.expectError, tt.name)`, After: `AssertError(t, err, tt.wantError, tt.name)`, Reason: "Aligns with Go testing best practices", }, } // TestFieldValidator provides validation for test case structures type TestFieldValidator struct { RequiredFields []string RecommendedNames map[string]string } // NewTestFieldValidator creates a validator with standard recommendations func NewTestFieldValidator() *TestFieldValidator { return &TestFieldValidator{ RequiredFields: []string{"name"}, RecommendedNames: StandardFieldNames, } } // ValidateFieldNaming checks if field names follow standards (implementation would go here) func (v *TestFieldValidator) ValidateFieldNaming(_ string) []string { // This would contain logic to validate struct field names // For now, returns empty slice (implementation can be added later) return []string{} }