Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

jobs:
lint:
uses: endobit/ci/.github/workflows/go-lint.yaml@main
uses: endobit/ci/.github/workflows/go-lint.yaml@v1.3.1
test:
uses: endobit/ci/.github/workflows/go-test.yaml@main
uses: endobit/ci/.github/workflows/go-test.yaml@v1.3.1
secrets: inherit
3 changes: 2 additions & 1 deletion table.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ func New(opts ...func(*Table)) *Table {
// flushed if a new struct type is written. If a is not a struct, an error table
// will be added to the output.
func (t *Table) Write(a any) {
if reflect.TypeOf(a).Kind() != reflect.Struct {
typ := reflect.TypeOf(a)
if typ == nil || typ.Kind() != reflect.Struct {
msg := struct {
Error error
Type string
Expand Down
15 changes: 15 additions & 0 deletions table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,21 @@ func TestWriteNonStruct(t *testing.T) {
}
}

func TestWriteNil(t *testing.T) {
var buf bytes.Buffer

tbl := New(WithWriter(&buf))

tbl.Write(nil)
_ = tbl.Flush()

output := buf.String()

if !strings.Contains(output, "not a struct") {
t.Errorf("expected error message in output, got: %q", output)
}
}

func TestEmptyTable(t *testing.T) {
var buf bytes.Buffer

Expand Down