corso/src/cli/utils/utils_test.go
Keepers 76b3fe3b86
append ToCore to all errors tests (#2793)
In order to retrieve all clues structured error data in tests, we need to extract it from the error using the clues library.

This change appends `clues.ToCore(err)` to all
variations of `assert.NoError(t, err)`.  The only
other changes are those necessary to preserve
linting, or to produce an error variable for the
ToCore call.

---

#### Does this PR need a docs update or release note?

- [x]  No

#### Type of change

- [x] 🤖 Test
- [x] 🧹 Tech Debt/Cleanup

#### Issue(s)

* #1970

#### Test Plan

- [x]  Unit test
- [x] 💚 E2E
2023-03-15 19:02:47 +00:00

90 lines
1.9 KiB
Go

package utils
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/alcionai/clues"
"github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/pkg/selectors"
)
type CliUtilsSuite struct {
tester.Suite
}
func TestCliUtilsSuite(t *testing.T) {
suite.Run(t, &CliUtilsSuite{Suite: tester.NewUnitSuite(t)})
}
func (suite *CliUtilsSuite) TestRequireProps() {
table := []struct {
name string
props map[string]string
errCheck assert.ErrorAssertionFunc
}{
{
props: map[string]string{"exists": "I have seen the fnords!"},
errCheck: assert.NoError,
},
{
props: map[string]string{"not-exists": ""},
errCheck: assert.Error,
},
}
for _, test := range table {
err := RequireProps(test.props)
test.errCheck(suite.T(), err, clues.ToCore(err))
}
}
func (suite *CliUtilsSuite) TestSplitFoldersIntoContainsAndPrefix() {
table := []struct {
name string
input []string
expectC []string
expectP []string
}{
{
name: "empty",
expectC: selectors.Any(),
expectP: nil,
},
{
name: "only contains",
input: []string{"a", "b", "c"},
expectC: []string{"a", "b", "c"},
expectP: []string{},
},
{
name: "only leading slash counts as contains",
input: []string{"a/////", "\\/b", "\\//c\\/"},
expectC: []string{"a/////", "\\/b", "\\//c\\/"},
expectP: []string{},
},
{
name: "only prefix",
input: []string{"/a", "/b", "/\\/c"},
expectC: []string{},
expectP: []string{"/a", "/b", "/\\/c"},
},
{
name: "mixed",
input: []string{"/a", "b", "/c"},
expectC: []string{"b"},
expectP: []string{"/a", "/c"},
},
}
for _, test := range table {
suite.Run(test.name, func() {
t := suite.T()
c, p := splitFoldersIntoContainsAndPrefix(test.input)
assert.ElementsMatch(t, test.expectC, c, "contains set")
assert.ElementsMatch(t, test.expectP, p, "prefix set")
})
}
}