Skip to content

Commit bedf165

Browse files
committed
# update dockerfile e port
1 parent fdaf1c1 commit bedf165

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

cmd/main_test.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,37 @@
11
package main
22

3-
import "testing"
3+
import (
4+
"bytes"
5+
"net/http"
6+
"testing"
7+
)
48

59
func Test_main(t *testing.T) {
610
tests := []struct {
711
name string
812
}{
913
{name: "Test case 1"},
10-
{name: "Test case 2"},
1114
}
1215
for _, tt := range tests {
1316
t.Run(tt.name, func(t *testing.T) {
1417
main()
18+
jsonStr := []byte(`{"name":"Notebook Gamer","description":"Notebook para jogos","price":5999.99,"category":"Eletronicos"}`)
19+
req, err := http.NewRequest("POST", "http://localhost:8080/products", bytes.NewBuffer(jsonStr))
20+
if err != nil {
21+
t.Fatalf("Failed to create request: %v", err)
22+
}
23+
req.Header.Set("Content-Type", "application/json")
24+
25+
client := &http.Client{}
26+
resp, err := client.Do(req)
27+
if err != nil {
28+
t.Fatalf("Failed to send request: %v", err)
29+
}
30+
defer resp.Body.Close()
31+
32+
if resp.StatusCode != http.StatusOK {
33+
t.Errorf("Expected status code %d, got %d", http.StatusOK, resp.StatusCode)
34+
}
1535
})
1636
}
1737
}

0 commit comments

Comments
 (0)