2019-07-22 14:17:11 +00:00
|
|
|
package gonextcloud
|
2019-01-18 12:42:40 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"strconv"
|
|
|
|
"sync"
|
|
|
|
"testing"
|
2019-07-22 14:17:11 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-01-18 12:42:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestUserUpdateErrors(t *testing.T) {
|
|
|
|
exp := map[string]error{}
|
|
|
|
errs := make(chan *UpdateError)
|
|
|
|
go func() {
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
f := strconv.Itoa(i)
|
|
|
|
e := errors.New(f)
|
|
|
|
err := UpdateError{
|
|
|
|
Field: f,
|
|
|
|
Error: e,
|
|
|
|
}
|
|
|
|
exp[f] = e
|
|
|
|
errs <- &err
|
|
|
|
}
|
|
|
|
close(errs)
|
|
|
|
}()
|
2019-07-22 14:40:42 +00:00
|
|
|
uerrs := newUpdateError(errs)
|
2019-01-18 12:42:40 +00:00
|
|
|
assert.Equal(t, exp, uerrs.Errors)
|
|
|
|
assert.NotEmpty(t, uerrs.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUserUpdateErrorsNil(t *testing.T) {
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
errs := make(chan *UpdateError)
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
errs <- nil
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
go func() {
|
|
|
|
wg.Wait()
|
|
|
|
close(errs)
|
|
|
|
}()
|
2019-07-22 14:40:42 +00:00
|
|
|
uerrs := newUpdateError(errs)
|
2019-01-18 12:42:40 +00:00
|
|
|
assert.Nil(t, uerrs)
|
|
|
|
}
|