From 69df8f252a2407c97670b42db20321e0fe3e0f11 Mon Sep 17 00:00:00 2001 From: Lena Fuhrimann <6780471+cloudlena@users.noreply.github.com> Date: Tue, 8 May 2018 17:55:26 +0200 Subject: [PATCH] Remove buffered channels --- Gopkg.lock | 4 +- internal/app/s3manager/bucket_view_test.go | 50 ++++++++++++++-------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 5874d30..21f9a73 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -88,7 +88,7 @@ "blake2b", "ssh/terminal" ] - revision = "4ec37c66abab2c7e02ae775328b2ff001c3f025a" + revision = "2d027ae1dddd4694d54f7a8b6cbe78dca8720226" [[projects]] branch = "release-branch.go1.10" @@ -107,7 +107,7 @@ "unix", "windows" ] - revision = "7db1c3b1a98089d0071c84f646ff5c96aad43682" + revision = "7dfd1290c7917b7ba22824b9d24954ab3002fe24" [[projects]] name = "golang.org/x/text" diff --git a/internal/app/s3manager/bucket_view_test.go b/internal/app/s3manager/bucket_view_test.go index 7840efb..8f6397e 100644 --- a/internal/app/s3manager/bucket_view_test.go +++ b/internal/app/s3manager/bucket_view_test.go @@ -24,9 +24,11 @@ func TestBucketViewHandler(t *testing.T) { }{ "renders a bucket containing a file": { listObjectsV2Func: func(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo { - objCh := make(chan minio.ObjectInfo, 1) - defer close(objCh) - objCh <- minio.ObjectInfo{Key: "testFile"} + objCh := make(chan minio.ObjectInfo) + go func() { + objCh <- minio.ObjectInfo{Key: "testFile"} + close(objCh) + }() return objCh }, bucketName: "testBucket", @@ -36,7 +38,7 @@ func TestBucketViewHandler(t *testing.T) { "renders placeholder for an empty bucket": { listObjectsV2Func: func(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo { objCh := make(chan minio.ObjectInfo) - defer close(objCh) + close(objCh) return objCh }, bucketName: "testBucket", @@ -45,9 +47,11 @@ func TestBucketViewHandler(t *testing.T) { }, "renders a bucket containing an archive": { listObjectsV2Func: func(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo { - objCh := make(chan minio.ObjectInfo, 1) - defer close(objCh) - objCh <- minio.ObjectInfo{Key: "archive.tar.gz"} + objCh := make(chan minio.ObjectInfo) + go func() { + objCh <- minio.ObjectInfo{Key: "archive.tar.gz"} + close(objCh) + }() return objCh }, bucketName: "testBucket", @@ -56,9 +60,11 @@ func TestBucketViewHandler(t *testing.T) { }, "renders a bucket containing an image": { listObjectsV2Func: func(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo { - objCh := make(chan minio.ObjectInfo, 1) - defer close(objCh) - objCh <- minio.ObjectInfo{Key: "testImage.png"} + objCh := make(chan minio.ObjectInfo) + go func() { + objCh <- minio.ObjectInfo{Key: "testImage.png"} + close(objCh) + }() return objCh }, bucketName: "testBucket", @@ -67,9 +73,11 @@ func TestBucketViewHandler(t *testing.T) { }, "renders a bucket containing a sound file": { listObjectsV2Func: func(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo { - objCh := make(chan minio.ObjectInfo, 1) - defer close(objCh) - objCh <- minio.ObjectInfo{Key: "testSound.mp3"} + objCh := make(chan minio.ObjectInfo) + go func() { + objCh <- minio.ObjectInfo{Key: "testSound.mp3"} + close(objCh) + }() return objCh }, bucketName: "testBucket", @@ -78,9 +86,11 @@ func TestBucketViewHandler(t *testing.T) { }, "returns error if the bucket doesn't exist": { listObjectsV2Func: func(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo { - objCh := make(chan minio.ObjectInfo, 1) - defer close(objCh) - objCh <- minio.ObjectInfo{Err: s3manager.ErrBucketDoesNotExist} + objCh := make(chan minio.ObjectInfo) + go func() { + objCh <- minio.ObjectInfo{Err: s3manager.ErrBucketDoesNotExist} + close(objCh) + }() return objCh }, bucketName: "testBucket", @@ -89,9 +99,11 @@ func TestBucketViewHandler(t *testing.T) { }, "returns error if there is an S3 error": { listObjectsV2Func: func(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo { - objCh := make(chan minio.ObjectInfo, 1) - defer close(objCh) - objCh <- minio.ObjectInfo{Err: errors.New("mocked S3 error")} + objCh := make(chan minio.ObjectInfo) + go func() { + objCh <- minio.ObjectInfo{Err: errors.New("mocked S3 error")} + close(objCh) + }() return objCh }, bucketName: "testBucket",