Skip to content

Commit 75ce22a

Browse files
committed
[14/1/23] testing fix about controller
1 parent 1a79175 commit 75ce22a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

golang-website-example.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ time="2023-01-14T15:14:15+07:00" level=info msg="models.User: [+]success" route=
3838
v login
3939
v user controller
4040
v home controller
41+
v about controller
4142

4243
2. [v] controller UpdateUser: validation
4344

tests/about_controller_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,39 @@ 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 TestAboutSuccess(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
}{
2423
{
2524
name: "about [no-auth] success",
26-
expect: no_auth,
25+
expect: "",
2726
html_navbar: regex{
2827
must_compile: `<a href="/login" class="btn btn-outline-success my-2 my-sm-0">(.*)</a>`,
2928
actual: `<a href="/login" class="btn btn-outline-success my-2 my-sm-0">Login</a>`,
3029
},
3130
},
3231
{
3332
name: "about [admin] success",
34-
expect: auth_admin,
33+
expect: ADMIN,
3534
html_navbar: regex{
3635
must_compile: `<a class="btn">(.*)</a>`,
3736
actual: `<a class="btn">ADMIN</a>`,
3837
},
3938
},
4039
{
4140
name: "home [user] success",
42-
expect: auth_sugriwa,
41+
expect: SUGRIWA,
4342
html_navbar: regex{
4443
must_compile: `<a href="/users" class="btn btn-outline-secondary my-2 my-sm-0">(.*)</a>`,
4544
actual: `<a href="/users" class="btn btn-outline-secondary my-2 my-sm-0">Users</a>`,
@@ -49,10 +48,10 @@ func TestAboutSuccess(t *testing.T) {
4948

5049
for _, test := range test_cases {
5150
var result *httpexpect.Response
52-
expect := test.expect // auth_admin, auth_sugriwa or no-auth
51+
modelsTest.UserSelectTest = test.expect // auth_admin, auth_sugriwa or no-auth
5352

5453
t.Run(test.name, func(t *testing.T) {
55-
result = expect.GET("/about").
54+
result = no_auth.GET("/about").
5655
Expect().
5756
Status(http.StatusOK)
5857

0 commit comments

Comments
 (0)