From a76d3d72eb9741820aa2153951346d85cced838c Mon Sep 17 00:00:00 2001 From: Emilie BOUIN Date: Mon, 31 Jul 2023 15:24:44 +0200 Subject: [PATCH] fix: review changes --- functions/cors-go/handler_test.go | 6 ++--- functions/go-mnq-sqs-publish/handler_test.go | 8 +++---- .../handler_test.go | 22 ++++++++++--------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/functions/cors-go/handler_test.go b/functions/cors-go/handler_test.go index 3fac6cc..e428fc3 100644 --- a/functions/cors-go/handler_test.go +++ b/functions/cors-go/handler_test.go @@ -8,16 +8,16 @@ import ( "github.com/stretchr/testify/assert" ) -func TestHandleWithCors(t *testing.T) { +const offlineTestingServer = "http://localhost:8080" - offlineTestingServer := "http://localhost:8080" +func TestHandleWithCors(t *testing.T) { resp, err := http.Get(offlineTestingServer) assert.Nil(t, err) defer resp.Body.Close() - assert.Equal(t, 200, resp.StatusCode) + assert.Equal(t, http.StatusOK, resp.StatusCode) assert.Equal(t, "*", resp.Header.Get("Access-Control-Allow-Headers")) assert.Equal(t, "*", resp.Header.Get("Access-Control-Allow-Methods")) assert.Equal(t, "*", resp.Header.Get("Access-Control-Allow-Origin")) diff --git a/functions/go-mnq-sqs-publish/handler_test.go b/functions/go-mnq-sqs-publish/handler_test.go index 909b10c..0f09f52 100644 --- a/functions/go-mnq-sqs-publish/handler_test.go +++ b/functions/go-mnq-sqs-publish/handler_test.go @@ -8,19 +8,19 @@ import ( "github.com/stretchr/testify/assert" ) -func TestHandle(t *testing.T) { +const offlineTestingServer = "http://localhost:8080" - offlineTestingServer := "http://localhost:8080" +func TestHandle(t *testing.T) { body := []byte(`{ "username": "Jane Doe", "message": "Hello World" }`) resp, err := http.Post(offlineTestingServer, "application/json", bytes.NewBuffer(body)) - assert.Nil(t, err) + assert.NoError(t, err) defer resp.Body.Close() - assert.Equal(t, 200, resp.StatusCode) + assert.Equal(t, http.StatusOK, resp.StatusCode) } diff --git a/functions/go-upload-file-s3-multipart/handler_test.go b/functions/go-upload-file-s3-multipart/handler_test.go index 451d9a0..714acef 100644 --- a/functions/go-upload-file-s3-multipart/handler_test.go +++ b/functions/go-upload-file-s3-multipart/handler_test.go @@ -12,35 +12,37 @@ import ( "github.com/stretchr/testify/assert" ) -func TestHandle(t *testing.T) { +const ( + offlineTestingServer = "http://localhost:8080" + fileToUpload = "go.sum" +) - offlineTestingServer := "http://localhost:8080" - fileToUpload := "go.sum" +func TestHandle(t *testing.T) { form := new(bytes.Buffer) writer := multipart.NewWriter(form) fw, err := writer.CreateFormFile("data", filepath.Base(fileToUpload)) - assert.Nil(t, err) + assert.NoError(t, err) fd, err := os.Open(fileToUpload) - assert.Nil(t, err) + assert.NoError(t, err) defer fd.Close() _, err = io.Copy(fw, fd) - assert.Nil(t, err) + assert.NoError(t, err) writer.Close() client := &http.Client{} - req, err := http.NewRequest("POST", offlineTestingServer, form) - assert.Nil(t, err) + req, err := http.NewRequest(http.MethodPost, offlineTestingServer, form) + assert.NoError(t, err) req.Header.Set("Content-Type", writer.FormDataContentType()) resp, err := client.Do(req) - assert.Nil(t, err) + assert.NoError(t, err) defer resp.Body.Close() - assert.Equal(t, 200, resp.StatusCode) + assert.Equal(t, http.StatusOK, resp.StatusCode) }