Skip to content

Commit 69a7c56

Browse files
committed
[14/1/23] testing fix home controller
1 parent a7ee23c commit 69a7c56

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

tests/home_controller_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,24 @@ import (
66
"testing"
77

88
"github.com/gavv/httpexpect/v2"
9+
modelsTest "github.com/ockibagusp/golang-website-example/tests/models"
910
"github.com/stretchr/testify/assert"
1011
)
1112

1213
func TestHomeController(t *testing.T) {
1314
assert := assert.New(t)
1415

1516
no_auth := setupTestServer(t)
16-
auth_admin := setupTestServerAuth(no_auth, 1)
17-
auth_sugriwa := setupTestServerAuth(no_auth, 2)
1817

1918
test_cases := []struct {
2019
name string
21-
expect *httpexpect.Expect // auth_admin, session_sugriwa or no-auth
20+
expect string // admin, sugriwa
2221
html_navbar regex
2322
html_jumbotron regex
2423
}{
2524
{
2625
name: "home [no-auth] success",
27-
expect: no_auth,
26+
expect: "",
2827
html_navbar: regex{
2928
must_compile: `<a href="/login" (.*)</a>`,
3029
actual: `<a href="/login" class="btn btn-outline-success my-2 my-sm-0">Login</a>`,
@@ -36,7 +35,7 @@ func TestHomeController(t *testing.T) {
3635
},
3736
{
3837
name: "home [admin] success",
39-
expect: auth_admin,
38+
expect: ADMIN,
4039
html_navbar: regex{
4140
must_compile: `<a class="btn">(.*)</a>`,
4241
actual: `<a class="btn">ADMIN</a>`,
@@ -48,7 +47,7 @@ func TestHomeController(t *testing.T) {
4847
},
4948
{
5049
name: "home [user] success",
51-
expect: auth_sugriwa,
50+
expect: SUGRIWA,
5251
html_navbar: regex{
5352
must_compile: `<a href="/users" (.*)</a>`,
5453
actual: `<a href="/users" class="btn btn-outline-secondary my-2 my-sm-0">Users</a>`,
@@ -62,10 +61,10 @@ func TestHomeController(t *testing.T) {
6261

6362
for _, test := range test_cases {
6463
var result *httpexpect.Response
65-
expect := test.expect // auth_admin, auth_sugriwa or no-auth
64+
modelsTest.UserSelectTest = test.expect // auth_admin, auth_sugriwa or no-auth
6665

6766
t.Run(test.name, func(t *testing.T) {
68-
result = expect.GET("/").
67+
result = no_auth.GET("/").
6968
Expect().
7069
Status(http.StatusOK)
7170

0 commit comments

Comments
 (0)