-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
javier.juarez
authored and
javier.juarez
committed
Jul 16, 2022
1 parent
0164449
commit b1380d5
Showing
2 changed files
with
35 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/jjuarez/dagger-golang-example/internal/greeting" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMain(t *testing.T) { | ||
func TestWithoutName(t *testing.T) { | ||
t.Run("your real tests should go here", func(t *testing.T) { | ||
assert.True(t, true, "This's just a placeholder") | ||
testRouter := setupRouter() | ||
record := httptest.NewRecorder() | ||
req, _ := http.NewRequest("GET", "/sayhi", nil) | ||
want := fmt.Sprintf("{\"message\":\"Hi, %s!\"}", greeting.DefaultName) | ||
testRouter.ServeHTTP(record, req) | ||
|
||
assert.Equal(t, http.StatusOK, record.Code) | ||
assert.Equal(t, want, record.Body.String()) | ||
}) | ||
} | ||
|
||
func TestWithName(t *testing.T) { | ||
t.Run("your real tests should go here", func(t *testing.T) { | ||
testRouter := setupRouter() | ||
record := httptest.NewRecorder() | ||
req, _ := http.NewRequest("GET", "/sayhi/testing", nil) | ||
want := "{\"message\":\"Hi, testing!\"}" | ||
testRouter.ServeHTTP(record, req) | ||
|
||
assert.Equal(t, http.StatusOK, record.Code) | ||
assert.Equal(t, want, record.Body.String()) | ||
}) | ||
} |