Skip to content

Commit

Permalink
fix: review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bemilie committed Jul 31, 2023
1 parent ee82fda commit a76d3d7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
6 changes: 3 additions & 3 deletions functions/cors-go/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
8 changes: 4 additions & 4 deletions functions/go-mnq-sqs-publish/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}
22 changes: 12 additions & 10 deletions functions/go-upload-file-s3-multipart/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}

0 comments on commit a76d3d7

Please sign in to comment.