populate a "test_name" clues field in the tester context, so that logs can be associated with the calling test. --- #### Does this PR need a docs update or release note? - [x] ⛔ No #### Type of change - [x] 🤖 Supportability/Tests #### Test Plan - [x] ⚡ Unit test - [x] 💚 E2E
57 lines
1.0 KiB
Go
57 lines
1.0 KiB
Go
package print
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/alcionai/clues"
|
|
"github.com/spf13/cobra"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"github.com/alcionai/corso/src/internal/tester"
|
|
)
|
|
|
|
type PrintUnitSuite struct {
|
|
tester.Suite
|
|
}
|
|
|
|
func TestPrintUnitSuite(t *testing.T) {
|
|
suite.Run(t, &PrintUnitSuite{Suite: tester.NewUnitSuite(t)})
|
|
}
|
|
|
|
func (suite *PrintUnitSuite) TestOnly() {
|
|
t := suite.T()
|
|
|
|
ctx, flush := tester.NewContext(t)
|
|
defer flush()
|
|
|
|
c := &cobra.Command{}
|
|
ctx = SetRootCmd(ctx, c)
|
|
|
|
err := Only(ctx, nil)
|
|
assert.NoError(t, err, clues.ToCore(err))
|
|
assert.True(t, c.SilenceUsage)
|
|
}
|
|
|
|
func (suite *PrintUnitSuite) TestOut() {
|
|
t := suite.T()
|
|
b := bytes.Buffer{}
|
|
msg := "I have seen the fnords!"
|
|
|
|
out(&b, msg)
|
|
assert.Contains(t, b.String(), msg)
|
|
}
|
|
|
|
func (suite *PrintUnitSuite) TestOutf() {
|
|
t := suite.T()
|
|
b := bytes.Buffer{}
|
|
msg := "I have seen the fnords!"
|
|
msg2 := "smarf"
|
|
|
|
outf(&b, msg, msg2)
|
|
bs := b.String()
|
|
assert.Contains(t, bs, msg)
|
|
assert.Contains(t, bs, msg2)
|
|
}
|