From 15518ec71fe771372a49cb3711bac626ca3464ba Mon Sep 17 00:00:00 2001 From: Gabe Alford Date: Thu, 3 Dec 2026 10:25:34 -0700 Subject: [PATCH 1/2] feat(output): add csv output format Add `--output csv` to every command that uses the shared output flag. Rows come from the command's TableDefinition and are written with encoding/csv (RFC 4180 quoting). CSV never truncates values, so --max-col-width and --no-truncate are ignored; --columns and --no-headers apply as they do for the table. An empty result prints only the header row. A printer without a TableDefinition returns ErrNoTableDefinition instead of printing nothing. Cell values are written exactly as returned. The usage docs warn about spreadsheet formula injection. --- docs/usage.md | 29 ++++++++ pkg/cmdutil/flags.go | 10 +-- pkg/output/csv.go | 95 +++++++++++++++++++++++++ pkg/output/csv_test.go | 153 +++++++++++++++++++++++++++++++++++++++++ pkg/output/output.go | 3 + test/e2e/fcs_test.go | 15 ++++ 6 files changed, 300 insertions(+), 5 deletions(-) create mode 100644 pkg/output/csv.go create mode 100644 pkg/output/csv_test.go diff --git a/docs/usage.md b/docs/usage.md index 484ea55..cc82350 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -91,6 +91,35 @@ With `--all`: The CLI retries a request that gets HTTP 429 (rate limited), a 5xx error, or a network error, up to 3 attempts in total. It waits about 1 second before the first retry and longer before each later one, up to 10 seconds. On a 429 it waits for the time the API gives in `X-RateLimit-RetryAfter`, also up to 10 seconds. Each request, with its retries, times out after 30 seconds. If the last attempt still fails, the command reports the error. +## Output Formats + +Most `fcs` list and get commands accept `--output` (default `table`): + +| Format | Description | +|--------|-------------| +| `table` | Aligned columns for terminals; long values are truncated (see `--max-col-width`, `--no-truncate`) | +| `json` | Full API objects as an indented JSON array | +| `jsonl` | One JSON object per line, for piping to `jq` | +| `toon` | Token-Oriented Object Notation, a compact encoding of the JSON output | +| `csv` | RFC 4180 CSV with the same columns as `table` | + +The `csv` format writes a header row followed by one row per item. Values that +contain commas, double quotes, or line breaks are quoted. Values are never +truncated, so `--max-col-width` and `--no-truncate` have no effect. `--columns` +and `--no-headers` apply to CSV as they do to the table. An empty result prints +only the header row. The `fcs doctor` command does not support `csv`. + +```bash +falcon fcs iom list --output csv > iom.csv +falcon fcs assets list --output csv --columns id,name,provider --no-headers +``` + +> **Caution:** CSV values are written exactly as returned by the API. A cell +> that begins with `=`, `+`, `-`, or `@` may be treated as a formula when the +> file is opened in a spreadsheet application. Treat CSV exported from tenant +> data as untrusted input, and import it as text when you open it in a +> spreadsheet. + ## Authentication The CLI uses CrowdStrike API credentials (OAuth2 client ID and secret). Configure them interactively: diff --git a/pkg/cmdutil/flags.go b/pkg/cmdutil/flags.go index 3fb2370..9f6f86f 100644 --- a/pkg/cmdutil/flags.go +++ b/pkg/cmdutil/flags.go @@ -73,9 +73,9 @@ func AddSortFlag(cmd *cobra.Command, p *string) { cmd.Flags().StringVar(p, "sort", "", "Sort expression (e.g. \"severity|desc\")") } -// AddOutputFlag adds an --output flag (table|json|jsonl|toon). +// AddOutputFlag adds an --output flag (table|json|jsonl|toon|csv). func AddOutputFlag(cmd *cobra.Command, p *string) { - cmd.Flags().StringVar(p, "output", "table", "Output format: table, json, jsonl, or toon") + cmd.Flags().StringVar(p, "output", "table", "Output format: table, json, jsonl, toon, or csv") } // AddIDsFlag adds an --ids flag for multi-ID commands. @@ -96,10 +96,10 @@ type TableFormattingOptions struct { // AddTableFormattingFlags adds --no-truncate, --max-col-width, --columns, and --no-headers flags. func AddTableFormattingFlags(cmd *cobra.Command, opts *TableFormattingOptions) { - cmd.Flags().BoolVar(&opts.NoTruncate, "no-truncate", false, "Disable column value truncation") - cmd.Flags().IntVar(&opts.MaxColWidth, "max-col-width", 50, "Maximum column width before truncation (0 = unlimited)") + cmd.Flags().BoolVar(&opts.NoTruncate, "no-truncate", false, "Disable column value truncation (csv never truncates)") + cmd.Flags().IntVar(&opts.MaxColWidth, "max-col-width", 50, "Maximum column width before truncation (0 = unlimited; ignored for csv)") cmd.Flags().StringVar(&opts.Columns, "columns", "", "Comma-separated list of columns to display (e.g. id,name,provider)") - cmd.Flags().BoolVar(&opts.NoHeaders, "no-headers", false, "Suppress table header row") + cmd.Flags().BoolVar(&opts.NoHeaders, "no-headers", false, "Suppress header row (table and csv)") } // ToOutputTableOptions converts TableFormattingOptions to output.TableOptions. diff --git a/pkg/output/csv.go b/pkg/output/csv.go new file mode 100644 index 0000000..4d1a164 --- /dev/null +++ b/pkg/output/csv.go @@ -0,0 +1,95 @@ +// Copyright (c) 2026 CrowdStrike, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package output + +import ( + "encoding/csv" + "errors" + "fmt" + "io" + "reflect" +) + +// ErrNoTableDefinition is returned when a format that renders columns (such +// as CSV) is requested from a command that has no TableDefinition. +var ErrNoTableDefinition = errors.New("this command does not support column-based output") + +// csvPrinter writes one RFC 4180 record per item using the TableDefinition +// headers and RowFunc. Values are written in full: the truncation and width +// options of the table format are ignored. Columns and NoHeaders are honoured. +type csvPrinter struct { + def *TableDefinition + opts *TableOptions +} + +func (p *csvPrinter) Print(w io.Writer, data any) error { + if p.def == nil { + return fmt.Errorf("--output %s: %w", FormatCSV, ErrNoTableDefinition) + } + + activeIdx := columnIndices(p.def.Headers, p.opts.Columns) + if len(activeIdx) == 0 { + return nil + } + + cw := csv.NewWriter(w) + record := make([]string, len(activeIdx)) + write := func(cols []string) error { + for j, i := range activeIdx { + record[j] = "" + if i < len(cols) { + record[j] = cols[i] + } + } + return cw.Write(record) + } + + if !p.opts.NoHeaders { + if err := write(p.def.Headers); err != nil { + return fmt.Errorf("writing CSV header: %w", err) + } + } + + v := reflect.ValueOf(data) + if v.Kind() == reflect.Pointer { + v = v.Elem() + } + switch { + case !v.IsValid(): + // nil data or nil pointer: header only. + case v.Kind() == reflect.Slice: + for i := 0; i < v.Len(); i++ { + if err := write(p.def.RowFunc(v.Index(i).Interface())); err != nil { + return fmt.Errorf("writing CSV row: %w", err) + } + } + default: + if err := write(p.def.RowFunc(data)); err != nil { + return fmt.Errorf("writing CSV row: %w", err) + } + } + + cw.Flush() + if err := cw.Error(); err != nil { + return fmt.Errorf("writing CSV: %w", err) + } + return nil +} diff --git a/pkg/output/csv_test.go b/pkg/output/csv_test.go new file mode 100644 index 0000000..d8dcdc9 --- /dev/null +++ b/pkg/output/csv_test.go @@ -0,0 +1,153 @@ +// Copyright (c) 2026 CrowdStrike, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package output + +import ( + "bytes" + "errors" + "strings" + "testing" +) + +type csvItem struct { + ID string + Name string + Note string +} + +var csvItemDef = &TableDefinition{ + Headers: []string{"ID", "NAME", "NOTE"}, + RowFunc: func(item any) []string { + r, ok := item.(*csvItem) + if !ok || r == nil { + return nil + } + return []string{r.ID, r.Name, r.Note} + }, +} + +func TestCSVPrinter(t *testing.T) { + t.Parallel() + + long := strings.Repeat("x", 120) + + tests := []struct { + name string + data any + opts *TableOptions + want string + }{ + { + name: "plain values", + data: []*csvItem{{ID: "a1", Name: "alpha", Note: "ok"}}, + want: "ID,NAME,NOTE\na1,alpha,ok\n", + }, + { + name: "comma is quoted", + data: []*csvItem{{ID: "a1", Name: "smith, john", Note: ""}}, + want: "ID,NAME,NOTE\na1,\"smith, john\",\n", + }, + { + name: "double quote is doubled", + data: []*csvItem{{ID: "a1", Name: `say "hi"`, Note: ""}}, + want: "ID,NAME,NOTE\na1,\"say \"\"hi\"\"\",\n", + }, + { + name: "embedded newline is quoted", + data: []*csvItem{{ID: "a1", Name: "line1\nline2", Note: ""}}, + want: "ID,NAME,NOTE\na1,\"line1\nline2\",\n", + }, + { + name: "unicode passes through", + data: []*csvItem{{ID: "ü1", Name: "東京", Note: "✅ café"}}, + want: "ID,NAME,NOTE\nü1,東京,✅ café\n", + }, + { + name: "empty slice prints only header", + data: []*csvItem{}, + want: "ID,NAME,NOTE\n", + }, + { + name: "nil data prints only header", + data: nil, + want: "ID,NAME,NOTE\n", + }, + { + name: "single item that is not a slice", + data: &csvItem{ID: "a1", Name: "alpha", Note: "ok"}, + want: "ID,NAME,NOTE\na1,alpha,ok\n", + }, + { + name: "long values are never truncated", + data: []*csvItem{{ID: "a1", Name: long, Note: ""}}, + opts: &TableOptions{MaxColWidth: 10}, + want: "ID,NAME,NOTE\na1," + long + ",\n", + }, + { + name: "no headers", + data: []*csvItem{{ID: "a1", Name: "alpha", Note: "ok"}}, + opts: &TableOptions{NoHeaders: true}, + want: "a1,alpha,ok\n", + }, + { + name: "column selection and order", + data: []*csvItem{{ID: "a1", Name: "alpha", Note: "ok"}}, + opts: &TableOptions{Columns: []string{"note", "id"}}, + want: "NOTE,ID\nok,a1\n", + }, + { + name: "short row is padded with empty fields", + data: []*csvItem{nil}, + want: "ID,NAME,NOTE\n,,\n", + }, + { + name: "formula-like values are written unchanged", + data: []*csvItem{{ID: "=1+1", Name: "@sum", Note: "-2"}}, + want: "ID,NAME,NOTE\n=1+1,@sum,-2\n", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + var buf bytes.Buffer + if err := NewPrinter(FormatCSV, csvItemDef, tt.opts).Print(&buf, tt.data); err != nil { + t.Fatalf("Print: %v", err) + } + if got := buf.String(); got != tt.want { + t.Errorf("got:\n%q\nwant:\n%q", got, tt.want) + } + }) + } +} + +func TestCSVPrinter_NoTableDefinition(t *testing.T) { + t.Parallel() + + var buf bytes.Buffer + err := NewPrinter(FormatCSV, nil).Print(&buf, []*csvItem{{ID: "a1"}}) + if !errors.Is(err, ErrNoTableDefinition) { + t.Fatalf("got error %v, want ErrNoTableDefinition", err) + } + if buf.Len() != 0 { + t.Errorf("expected no output, got %q", buf.String()) + } +} diff --git a/pkg/output/output.go b/pkg/output/output.go index 2cff57d..f544b5e 100644 --- a/pkg/output/output.go +++ b/pkg/output/output.go @@ -33,6 +33,7 @@ const ( FormatJSON Format = "json" FormatJSONL Format = "jsonl" FormatTOON Format = "toon" + FormatCSV Format = "csv" ) // TableDefinition describes how to render a slice of items as a table. @@ -87,6 +88,8 @@ func NewPrinter(format Format, def *TableDefinition, tableOpts ...*TableOptions) return &jsonlPrinter{} case FormatTOON: return &toonPrinter{} + case FormatCSV: + return &csvPrinter{def: def, opts: opts} default: return &tablePrinter{def: def, opts: opts} } diff --git a/test/e2e/fcs_test.go b/test/e2e/fcs_test.go index e312221..ffa8396 100644 --- a/test/e2e/fcs_test.go +++ b/test/e2e/fcs_test.go @@ -116,6 +116,21 @@ var _ = Describe("falcon fcs", Label("fcs"), func() { Expect(out).To(ContainSubstring("high")) }) + It("outputs CSV", func() { + server := newMockServer([]route{ + {method: http.MethodGet, prefix: "/cloud-security-evaluations/queries/ioms/v1", fixture: "iom_query.json"}, + {method: http.MethodGet, prefix: "/cloud-security-evaluations/entities/ioms/v1", fixture: "iom_entities.json"}, + }) + defer server.Close() + f, stdout := newTestFactory(server) + + out, err := runFCS(f, stdout, "iom", "list", "--limit", "3", "--output", "csv") + Expect(err).NotTo(HaveOccurred(), out) + Expect(out).To(Equal( + "ID,RULE_ID,SEVERITY,RESOURCE_ID,STATUS,CREATED\n" + + "iom-001,rule-abc-123,high,arn:aws:s3:::my-bucket,open,2025-06-01\n")) + }) + It("rejects bare field name as invalid FQL", func() { server := newMockServer(nil) defer server.Close() From b08dac6495ea0706fee2ac2f33763e91cc544a6a Mon Sep 17 00:00:00 2001 From: Gabe Alford Date: Thu, 3 Dec 2026 14:29:47 -0700 Subject: [PATCH 2/2] fix(output): address csv review feedback - Write a lone empty field as `""` instead of a blank line. csv.Writer emits an empty line for a one-column record with an empty value, and readers such as csv.Reader and pandas skip blank lines, which silently dropped rows (e.g. `--columns name` on assets with no name). - Return ErrUnknownColumns, listing the valid column names, when --columns matches no column. Previously CSV printed nothing and exited 0. - Describe the format as RFC 4180-style quoting with LF line endings rather than claiming strict RFC 4180, which requires CRLF. - Document how to open UTF-8 CSV in Excel on Windows. - Add test cases for lone CR and CRLF in values, and a csv.Reader round-trip test. --- docs/usage.md | 19 +++++++--- pkg/output/csv.go | 30 +++++++++++++-- pkg/output/csv_test.go | 86 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 10 deletions(-) diff --git a/docs/usage.md b/docs/usage.md index cc82350..25e55f6 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -101,13 +101,15 @@ Most `fcs` list and get commands accept `--output` (default `table`): | `json` | Full API objects as an indented JSON array | | `jsonl` | One JSON object per line, for piping to `jq` | | `toon` | Token-Oriented Object Notation, a compact encoding of the JSON output | -| `csv` | RFC 4180 CSV with the same columns as `table` | +| `csv` | CSV with RFC 4180-style quoting and the same columns as `table` | -The `csv` format writes a header row followed by one row per item. Values that -contain commas, double quotes, or line breaks are quoted. Values are never -truncated, so `--max-col-width` and `--no-truncate` have no effect. `--columns` -and `--no-headers` apply to CSV as they do to the table. An empty result prints -only the header row. The `fcs doctor` command does not support `csv`. +The `csv` format writes a header row followed by one row per item, with LF +line endings. Values that contain commas, double quotes, or line breaks are +quoted. Values are never truncated, so `--max-col-width` and `--no-truncate` +have no effect. `--columns` and `--no-headers` apply to CSV as they do to the +table; with `--output csv`, a `--columns` list that matches no column is an +error that lists the valid names. An empty result prints only the header row. +The `fcs doctor` command does not support `csv`. ```bash falcon fcs iom list --output csv > iom.csv @@ -120,6 +122,11 @@ falcon fcs assets list --output csv --columns id,name,provider --no-headers > data as untrusted input, and import it as text when you open it in a > spreadsheet. +> **Note:** CSV output is UTF-8 without a byte order mark. Excel on Windows +> may show non-ASCII characters incorrectly when the file is opened by +> double-click. Use **Data > From Text/CSV** and choose UTF-8 (65001) as the +> file origin instead. + ## Authentication The CLI uses CrowdStrike API credentials (OAuth2 client ID and secret). Configure them interactively: diff --git a/pkg/output/csv.go b/pkg/output/csv.go index 4d1a164..7bc4b22 100644 --- a/pkg/output/csv.go +++ b/pkg/output/csv.go @@ -26,15 +26,21 @@ import ( "fmt" "io" "reflect" + "strings" ) // ErrNoTableDefinition is returned when a format that renders columns (such // as CSV) is requested from a command that has no TableDefinition. var ErrNoTableDefinition = errors.New("this command does not support column-based output") -// csvPrinter writes one RFC 4180 record per item using the TableDefinition -// headers and RowFunc. Values are written in full: the truncation and width -// options of the table format are ignored. Columns and NoHeaders are honoured. +// ErrUnknownColumns is returned by the CSV printer when --columns names no +// known column, so a typo fails loudly instead of producing an empty file. +var ErrUnknownColumns = errors.New("no known columns selected") + +// csvPrinter writes one record per item using the TableDefinition headers and +// RowFunc, with RFC 4180-style quoting and LF line endings. Values are written +// in full: the truncation and width options of the table format are ignored. +// Columns and NoHeaders are honoured. type csvPrinter struct { def *TableDefinition opts *TableOptions @@ -47,7 +53,12 @@ func (p *csvPrinter) Print(w io.Writer, data any) error { activeIdx := columnIndices(p.def.Headers, p.opts.Columns) if len(activeIdx) == 0 { - return nil + valid := make([]string, len(p.def.Headers)) + for i, h := range p.def.Headers { + valid[i] = strings.ToLower(h) + } + return fmt.Errorf("--columns %s: %w (valid columns: %s)", + strings.Join(p.opts.Columns, ","), ErrUnknownColumns, strings.Join(valid, ", ")) } cw := csv.NewWriter(w) @@ -59,6 +70,17 @@ func (p *csvPrinter) Print(w io.Writer, data any) error { record[j] = cols[i] } } + // csv.Writer renders a lone empty field as a blank line, which + // readers (including csv.Reader) skip, dropping the row. Write an + // explicit empty quoted field instead. + if len(record) == 1 && record[0] == "" { + cw.Flush() + if err := cw.Error(); err != nil { + return err + } + _, err := io.WriteString(w, `""`+"\n") + return err + } return cw.Write(record) } diff --git a/pkg/output/csv_test.go b/pkg/output/csv_test.go index d8dcdc9..049cbd9 100644 --- a/pkg/output/csv_test.go +++ b/pkg/output/csv_test.go @@ -22,6 +22,7 @@ package output import ( "bytes" + "encoding/csv" "errors" "strings" "testing" @@ -75,6 +76,22 @@ func TestCSVPrinter(t *testing.T) { data: []*csvItem{{ID: "a1", Name: "line1\nline2", Note: ""}}, want: "ID,NAME,NOTE\na1,\"line1\nline2\",\n", }, + { + name: "lone carriage return is quoted", + data: []*csvItem{{ID: "a1", Name: "line1\rline2", Note: ""}}, + want: "ID,NAME,NOTE\na1,\"line1\rline2\",\n", + }, + { + name: "CRLF in value is quoted and written as-is", + data: []*csvItem{{ID: "a1", Name: "line1\r\nline2", Note: ""}}, + want: "ID,NAME,NOTE\na1,\"line1\r\nline2\",\n", + }, + { + name: "single empty column is written as quoted empty field", + data: []*csvItem{{ID: "a1", Note: ""}, {ID: "a2", Note: "x"}}, + opts: &TableOptions{Columns: []string{"note"}}, + want: "NOTE\n\"\"\nx\n", + }, { name: "unicode passes through", data: []*csvItem{{ID: "ü1", Name: "東京", Note: "✅ café"}}, @@ -139,6 +156,75 @@ func TestCSVPrinter(t *testing.T) { } } +// TestCSVPrinter_RoundTrip parses the output back with csv.Reader and checks +// that every value survives, covering escaping beyond exact string matches. +func TestCSVPrinter_RoundTrip(t *testing.T) { + t.Parallel() + + values := []string{ + "", "plain", "smith, john", `say "hi"`, `"`, `""`, ",", " leading space", + "trailing space ", "\ttab", "line1\nline2", "line1\rline2", "line1\r\nline2", + "東京", "✅ café", "=1+1", `\.`, + } + + tests := []struct { + name string + columns []string + row func(v string) *csvItem + }{ + {name: "all columns", row: func(v string) *csvItem { return &csvItem{ID: "id", Name: v, Note: v} }}, + {name: "single column", columns: []string{"note"}, row: func(v string) *csvItem { return &csvItem{Note: v} }}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + items := make([]*csvItem, len(values)) + for i, v := range values { + items[i] = tt.row(v) + } + + var buf bytes.Buffer + opts := &TableOptions{Columns: tt.columns, NoHeaders: true} + if err := NewPrinter(FormatCSV, csvItemDef, opts).Print(&buf, items); err != nil { + t.Fatalf("Print: %v", err) + } + + records, err := csv.NewReader(&buf).ReadAll() + if err != nil { + t.Fatalf("ReadAll: %v", err) + } + if len(records) != len(values) { + t.Fatalf("got %d records, want %d: %q", len(records), len(values), records) + } + for i, v := range values { + // csv.Reader normalises \r\n inside quoted fields to \n. + want := strings.ReplaceAll(v, "\r\n", "\n") + if got := records[i][len(records[i])-1]; got != want { + t.Errorf("record %d: got %q, want %q", i, got, want) + } + } + }) + } +} + +func TestCSVPrinter_UnknownColumns(t *testing.T) { + t.Parallel() + + var buf bytes.Buffer + opts := &TableOptions{Columns: []string{"bogus", "nope"}} + err := NewPrinter(FormatCSV, csvItemDef, opts).Print(&buf, []*csvItem{{ID: "a1"}}) + if !errors.Is(err, ErrUnknownColumns) { + t.Fatalf("got error %v, want ErrUnknownColumns", err) + } + if want := "valid columns: id, name, note"; !strings.Contains(err.Error(), want) { + t.Errorf("error %q does not contain %q", err, want) + } + if buf.Len() != 0 { + t.Errorf("expected no output, got %q", buf.String()) + } +} + func TestCSVPrinter_NoTableDefinition(t *testing.T) { t.Parallel()