(t *testing.T)
| 51 | } |
| 52 | |
| 53 | func 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 | } |
nothing calls this directly
no test coverage detected