corso/src/internal/common/configs_test.go
Keepers 9d73d0c8e2
replace errors.* with clues.* (#2924)
Mostly find/replace on errors.N and errors.W. Also turns all wrapf into wrap, and removes as many errorf calls as possible.

Might follow up with a linter to enforce this change.

---

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

- [x]  No

#### Type of change

- [x] 🧹 Tech Debt/Cleanup

#### Issue(s)

* #1970

#### Test Plan

- [x]  Unit test
- [x] 💚 E2E
2023-03-28 04:01:54 +00:00

78 lines
2.0 KiB
Go

package common_test
import (
"testing"
"github.com/alcionai/clues"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/alcionai/corso/src/internal/common"
"github.com/alcionai/corso/src/internal/tester"
)
type CommonConfigsSuite struct {
tester.Suite
}
func TestCommonConfigsSuite(t *testing.T) {
s := &CommonConfigsSuite{Suite: tester.NewUnitSuite(t)}
suite.Run(t, s)
}
const (
keyExpect = "expect"
keyExpect2 = "expect2"
)
type stringConfig struct {
expectA string
err error
}
func (c stringConfig) StringConfig() (map[string]string, error) {
return map[string]string{keyExpect: c.expectA}, c.err
}
type stringConfig2 struct {
expectB string
err error
}
func (c stringConfig2) StringConfig() (map[string]string, error) {
return map[string]string{keyExpect2: c.expectB}, c.err
}
func (suite *CommonConfigsSuite) TestUnionConfigs_string() {
table := []struct {
name string
ac stringConfig
bc stringConfig2
errCheck assert.ErrorAssertionFunc
}{
{"no error", stringConfig{keyExpect, nil}, stringConfig2{keyExpect2, nil}, assert.NoError},
{"tc error", stringConfig{keyExpect, assert.AnError}, stringConfig2{keyExpect2, nil}, assert.Error},
{"fc error", stringConfig{keyExpect, nil}, stringConfig2{keyExpect2, assert.AnError}, assert.Error},
}
for _, test := range table {
suite.Run(test.name, func() {
t := suite.T()
cs, err := common.UnionStringConfigs(test.ac, test.bc)
test.errCheck(t, err, clues.ToCore(err))
// remaining tests depend on error-free state
if test.ac.err != nil || test.bc.err != nil {
return
}
assert.Equalf(t,
test.ac.expectA,
cs[keyExpect],
"expected unioned config to have value [%s] at key [%s], got [%s]", test.ac.expectA, keyExpect, cs[keyExpect])
assert.Equalf(t,
test.bc.expectB,
cs[keyExpect2],
"expected unioned config to have value [%s] at key [%s], got [%s]", test.bc.expectB, keyExpect2, cs[keyExpect2])
})
}
}