MCPcopy Create free account
hub / github.com/driangle/taskmd / TestValidateFormat

Function TestValidateFormat

apps/cli/internal/cli/format_test.go:53–82  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

51}
52
53func TestValidateFormat(t *testing.T) {
54 tests := []struct {
55 name string
56 format string
57 supported []string
58 wantErr bool
59 }{
60 {"valid format", "json", []string{"table", "json", "yaml"}, false},
61 {"invalid format", "csv", []string{"table", "json", "yaml"}, true},
62 {"first option valid", "table", []string{"table", "json"}, false},
63 {"last option valid", "yaml", []string{"table", "json", "yaml"}, false},
64 }
65
66 for _, tt := range tests {
67 t.Run(tt.name, func(t *testing.T) {
68 err := ValidateFormat(tt.format, tt.supported)
69 if (err != nil) != tt.wantErr {
70 t.Errorf("ValidateFormat() error = %v, wantErr %v", err, tt.wantErr)
71 }
72 if tt.wantErr && err != nil {
73 if !strings.Contains(err.Error(), "unsupported format") {
74 t.Errorf("expected 'unsupported format' in error, got: %v", err)
75 }
76 if !strings.Contains(err.Error(), tt.format) {
77 t.Errorf("expected format name %q in error, got: %v", tt.format, err)
78 }
79 }
80 })
81 }
82}

Callers

nothing calls this directly

Calls 2

ValidateFormatFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected