Improve error checking in integration tests
This commit is contained in:
parent
d346ec7bfe
commit
6f3fbbbe49
@ -138,11 +138,27 @@ func testSyncCluster(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prepare the expected state of folders after the sync
|
// Prepare the expected state of folders after the sync
|
||||||
e1 := mergeDirectoryContents(directoryContents("s1"),
|
c1, err := directoryContents("s1")
|
||||||
directoryContents("s2"),
|
if err != nil {
|
||||||
directoryContents("s3"))
|
t.Fatal(err)
|
||||||
e2 := directoryContents("s12-1")
|
}
|
||||||
e3 := directoryContents("s23-2")
|
c2, err := directoryContents("s2")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
c3, err := directoryContents("s3")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
e1 := mergeDirectoryContents(c1, c2, c3)
|
||||||
|
e2, err := directoryContents("s12-1")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
e3, err := directoryContents("s23-2")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
expected := [][]fileInfo{e1, e2, e3}
|
expected := [][]fileInfo{e1, e2, e3}
|
||||||
|
|
||||||
for count := 0; count < 5; count++ {
|
for count := 0; count < 5; count++ {
|
||||||
@ -212,9 +228,18 @@ func testSyncCluster(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prepare the expected state of folders after the sync
|
// Prepare the expected state of folders after the sync
|
||||||
e1 = directoryContents("s1")
|
e1, err = directoryContents("s1")
|
||||||
e2 = directoryContents("s12-1")
|
if err != nil {
|
||||||
e3 = directoryContents("s23-2")
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
e2, err = directoryContents("s12-1")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
e3, err = directoryContents("s23-2")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
expected = [][]fileInfo{e1, e2, e3}
|
expected = [][]fileInfo{e1, e2, e3}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,21 +326,30 @@ mainLoop:
|
|||||||
log.Println("Checking...")
|
log.Println("Checking...")
|
||||||
|
|
||||||
for _, dir := range []string{"s1", "s2", "s3"} {
|
for _, dir := range []string{"s1", "s2", "s3"} {
|
||||||
actual := directoryContents(dir)
|
actual, err := directoryContents(dir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := compareDirectoryContents(actual, expected[0]); err != nil {
|
if err := compareDirectoryContents(actual, expected[0]); err != nil {
|
||||||
return fmt.Errorf("%s: %v", dir, err)
|
return fmt.Errorf("%s: %v", dir, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, dir := range []string{"s12-1", "s12-2"} {
|
for _, dir := range []string{"s12-1", "s12-2"} {
|
||||||
actual := directoryContents(dir)
|
actual, err := directoryContents(dir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := compareDirectoryContents(actual, expected[1]); err != nil {
|
if err := compareDirectoryContents(actual, expected[1]); err != nil {
|
||||||
return fmt.Errorf("%s: %v", dir, err)
|
return fmt.Errorf("%s: %v", dir, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, dir := range []string{"s23-2", "s23-3"} {
|
for _, dir := range []string{"s23-2", "s23-3"} {
|
||||||
actual := directoryContents(dir)
|
actual, err := directoryContents(dir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := compareDirectoryContents(actual, expected[2]); err != nil {
|
if err := compareDirectoryContents(actual, expected[2]); err != nil {
|
||||||
return fmt.Errorf("%s: %v", dir, err)
|
return fmt.Errorf("%s: %v", dir, err)
|
||||||
}
|
}
|
||||||
|
|||||||
25
test/util.go
25
test/util.go
@ -227,10 +227,11 @@ func compareDirectories(dirs ...string) error {
|
|||||||
for i := range chans {
|
for i := range chans {
|
||||||
chans[i] = make(chan fileInfo)
|
chans[i] = make(chan fileInfo)
|
||||||
}
|
}
|
||||||
|
errcs := make([]chan error, len(dirs))
|
||||||
abort := make(chan struct{})
|
abort := make(chan struct{})
|
||||||
|
|
||||||
for i := range dirs {
|
for i := range dirs {
|
||||||
startWalker(dirs[i], chans[i], abort)
|
errcs[i] = startWalker(dirs[i], chans[i], abort)
|
||||||
}
|
}
|
||||||
|
|
||||||
res := make([]fileInfo, len(dirs))
|
res := make([]fileInfo, len(dirs))
|
||||||
@ -239,6 +240,11 @@ func compareDirectories(dirs ...string) error {
|
|||||||
for i := range chans {
|
for i := range chans {
|
||||||
fi, ok := <-chans[i]
|
fi, ok := <-chans[i]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
err, hasError := <-errcs[i]
|
||||||
|
if hasError {
|
||||||
|
close(abort)
|
||||||
|
return err
|
||||||
|
}
|
||||||
numDone++
|
numDone++
|
||||||
}
|
}
|
||||||
res[i] = fi
|
res[i] = fi
|
||||||
@ -257,16 +263,16 @@ func compareDirectories(dirs ...string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func directoryContents(dir string) []fileInfo {
|
func directoryContents(dir string) ([]fileInfo, error) {
|
||||||
res := make(chan fileInfo)
|
res := make(chan fileInfo)
|
||||||
startWalker(dir, res, nil)
|
errc := startWalker(dir, res, nil)
|
||||||
|
|
||||||
var files []fileInfo
|
var files []fileInfo
|
||||||
for f := range res {
|
for f := range res {
|
||||||
files = append(files, f)
|
files = append(files, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
return files
|
return files, <-errc
|
||||||
}
|
}
|
||||||
|
|
||||||
func mergeDirectoryContents(c ...[]fileInfo) []fileInfo {
|
func mergeDirectoryContents(c ...[]fileInfo) []fileInfo {
|
||||||
@ -325,7 +331,7 @@ func (l fileInfoList) Swap(a, b int) {
|
|||||||
l[a], l[b] = l[b], l[a]
|
l[a], l[b] = l[b], l[a]
|
||||||
}
|
}
|
||||||
|
|
||||||
func startWalker(dir string, res chan<- fileInfo, abort <-chan struct{}) {
|
func startWalker(dir string, res chan<- fileInfo, abort <-chan struct{}) chan error {
|
||||||
walker := func(path string, info os.FileInfo, err error) error {
|
walker := func(path string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -381,10 +387,17 @@ func startWalker(dir string, res chan<- fileInfo, abort <-chan struct{}) {
|
|||||||
return errors.New("abort")
|
return errors.New("abort")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errc := make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
filepath.Walk(dir, walker)
|
err := filepath.Walk(dir, walker)
|
||||||
close(res)
|
close(res)
|
||||||
|
if err != nil {
|
||||||
|
errc <- err
|
||||||
|
}
|
||||||
|
close(errc)
|
||||||
}()
|
}()
|
||||||
|
return errc
|
||||||
}
|
}
|
||||||
|
|
||||||
func md5file(fname string) (hash [16]byte, err error) {
|
func md5file(fname string) (hash [16]byte, err error) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user