mirror of
				https://gitlab.bertha.cloud/partitio/Nextcloud-Partitio/gonextcloud
				synced 2025-11-04 05:11:46 +00:00 
			
		
		
		
	Fix User UpdateError
This commit is contained in:
		@@ -40,17 +40,16 @@ func (e *UserUpdateError) Error() string {
 | 
			
		||||
	for k, e := range e.Errors {
 | 
			
		||||
		errors = append(errors, fmt.Sprintf("%s: %v", k, e))
 | 
			
		||||
	}
 | 
			
		||||
	return strings.Join(errors, ",")
 | 
			
		||||
	return strings.Join(errors, ", ")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//NewUpdateError returns an UpdateError based on an UpdateError channel
 | 
			
		||||
func NewUpdateError(errors chan UpdateError) *UserUpdateError {
 | 
			
		||||
	var ue UserUpdateError
 | 
			
		||||
func NewUpdateError(errors chan *UpdateError) *UserUpdateError {
 | 
			
		||||
	ue := UserUpdateError{map[string]error{}}
 | 
			
		||||
	for e := range errors {
 | 
			
		||||
		if ue.Errors == nil {
 | 
			
		||||
			ue.Errors = map[string]error{e.Field: e.Error}
 | 
			
		||||
		if e != nil {
 | 
			
		||||
			ue.Errors[e.Field] = e.Error
 | 
			
		||||
		}
 | 
			
		||||
		ue.Errors[e.Field] = e.Error
 | 
			
		||||
	}
 | 
			
		||||
	if len(ue.Errors) > 0 {
 | 
			
		||||
		return &ue
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										46
									
								
								types/errors_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								types/errors_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
package types
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
	"github.com/stretchr/testify/assert"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"sync"
 | 
			
		||||
	"testing"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
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)
 | 
			
		||||
	}()
 | 
			
		||||
	uerrs := NewUpdateError(errs)
 | 
			
		||||
	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)
 | 
			
		||||
	}()
 | 
			
		||||
	uerrs := NewUpdateError(errs)
 | 
			
		||||
	assert.Nil(t, uerrs)
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user