(t *testing.T)
| 25 | ) |
| 26 | |
| 27 | func TestLogin(t *testing.T) { |
| 28 | type args struct { |
| 29 | code int |
| 30 | data map[string]interface{} |
| 31 | result string |
| 32 | } |
| 33 | tests := []struct { |
| 34 | name string |
| 35 | args args |
| 36 | }{ |
| 37 | { |
| 38 | name: "normal", |
| 39 | args: args{ |
| 40 | code: http.StatusOK, |
| 41 | data: map[string]interface{}{ |
| 42 | "_id": "admin", |
| 43 | "password": "Complexpass#123", |
| 44 | }, |
| 45 | result: "validated\":true", |
| 46 | }, |
| 47 | }, |
| 48 | { |
| 49 | name: "error", |
| 50 | args: args{ |
| 51 | code: http.StatusOK, |
| 52 | data: map[string]interface{}{ |
| 53 | "_id": "user_not_exists", |
| 54 | "password": "password", |
| 55 | }, |
| 56 | result: "validated\":false", |
| 57 | }, |
| 58 | }, |
| 59 | { |
| 60 | name: "error", |
| 61 | args: args{ |
| 62 | code: http.StatusBadRequest, |
| 63 | data: map[string]interface{}{ |
| 64 | "_id": 1233, |
| 65 | "password": "password", |
| 66 | }, |
| 67 | result: "error", |
| 68 | }, |
| 69 | }, |
| 70 | } |
| 71 | for _, tt := range tests { |
| 72 | t.Run(tt.name, func(t *testing.T) { |
| 73 | c, w := utils.NewGinContext() |
| 74 | utils.SetGinRequestData(c, tt.args.data) |
| 75 | Login(c) |
| 76 | assert.Equal(t, tt.args.code, w.Code) |
| 77 | assert.Contains(t, w.Body.String(), tt.args.result) |
| 78 | }) |
| 79 | } |
| 80 | } |
nothing calls this directly
no test coverage detected