Some checks are pending
Docs Deploy / build_and_deploy (push) Waiting to run
Generate Docs / cli (push) Waiting to run
Generate Config Doc / cli (push) Waiting to run
Go formatting / go-formatting (push) Waiting to run
Check links / markdown-link-check (push) Waiting to run
Integration / pre-test (push) Waiting to run
Integration / test on (push) Blocked by required conditions
Integration / status (push) Blocked by required conditions
Lint / Lint Go code (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package entrywriter_test
|
|
|
|
import (
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/ignite/cli/v29/ignite/pkg/cliui/entrywriter"
|
|
"github.com/ignite/cli/v29/ignite/pkg/errors"
|
|
)
|
|
|
|
type WriterWithError struct{}
|
|
|
|
func (WriterWithError) Write(_ []byte) (n int, err error) {
|
|
return 0, errors.New("writer with error")
|
|
}
|
|
|
|
func TestWrite(t *testing.T) {
|
|
header := []string{"foobar", "bar", "foo"}
|
|
|
|
entries := [][]string{
|
|
{"foo", "bar", "foobar"},
|
|
{"bar", "foobar", "foo"},
|
|
{"foobar", "foo", "bar"},
|
|
}
|
|
|
|
require.NoError(t, entrywriter.Write(io.Discard, header, entries...))
|
|
require.NoError(t, entrywriter.Write(io.Discard, header), "should allow no entry")
|
|
|
|
err := entrywriter.Write(io.Discard, []string{})
|
|
require.ErrorIs(t, err, entrywriter.ErrInvalidFormat, "should prevent no header")
|
|
|
|
entries[0] = []string{"foo", "bar"}
|
|
err = entrywriter.Write(io.Discard, header, entries...)
|
|
require.ErrorIs(t, err, entrywriter.ErrInvalidFormat, "should prevent entry length mismatch")
|
|
|
|
var wErr WriterWithError
|
|
require.Error(t, entrywriter.Write(wErr, header, entries...), "should catch writer errors")
|
|
}
|