-
Notifications
You must be signed in to change notification settings - Fork 0
/
login_test.go
72 lines (68 loc) · 1.75 KB
/
login_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"context"
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDoLogin(t *testing.T) {
ctx := context.Background()
testcases := []struct {
name string
id string
password string
expectedError error
}{
{
name: "Test Employee Login",
id: "EMP_005",
password: "very-s3cret-passwd",
expectedError: nil,
},
{
name: "Test Customer Login",
id: "CUST_1245",
password: "very-s3cret-passwd",
expectedError: nil,
},
{
name: "Test Admin Login",
id: "ADMIN_652",
password: "very-s3cret-passwd",
expectedError: nil,
},
{
name: "Test Failed Employee Login",
id: "EMP_005",
password: "very-passwd",
expectedError: errors.New("login error response: employee login failed with wrong credentials , Code: 401 "),
},
{
name: "Test Failed Customer Login",
id: "CUST_1245",
password: "-s3cret-passwd",
expectedError: errors.New("login error response: customer login failed with wrong credentials , Code: 401 "),
},
{
name: "Test Failed Admin Login",
id: "ADMIN_652",
password: "very-s3cret",
expectedError: errors.New("login error response: admin login failed with wrong credentials , Code: 401 "),
},
{
name: "Unknown role",
id: "Unknown_123",
expectedError: errors.New("unsupported request type"),
},
}
for _, testcase := range testcases {
t.Run(testcase.name, func(t *testing.T) {
err := doLogin(ctx, testcase.id, testcase.password)
if err != nil {
assert.Equal(t, err, testcase.expectedError)
} else {
assert.Nil(t, err)
}
})
}
}