|
| 1 | +// Copyright 2024 FishGoddess. All rights reserved. |
| 2 | +// Use of this source code is governed by a MIT style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +package errors |
| 6 | + |
| 7 | +import "testing" |
| 8 | + |
| 9 | +// go test -v -cover -count=1 -test.cpu=1 -run=^TestBadRequest$ |
| 10 | +func TestBadRequest(t *testing.T) { |
| 11 | + testCases := []struct { |
| 12 | + message string |
| 13 | + code int32 |
| 14 | + }{ |
| 15 | + { |
| 16 | + message: "id is nil", |
| 17 | + code: CodeBadRequest, |
| 18 | + }, |
| 19 | + } |
| 20 | + |
| 21 | + for _, testCase := range testCases { |
| 22 | + err := BadRequest(testCase.message) |
| 23 | + if err.Code() != testCase.code { |
| 24 | + t.Errorf("err.Code() %d != testCase.code %d", err.Code(), testCase.code) |
| 25 | + } |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +// go test -v -cover -count=1 -test.cpu=1 -run=^TestForbidden$ |
| 30 | +func TestForbidden(t *testing.T) { |
| 31 | + testCases := []struct { |
| 32 | + message string |
| 33 | + code int32 |
| 34 | + }{ |
| 35 | + { |
| 36 | + message: "id is nil", |
| 37 | + code: CodeForbidden, |
| 38 | + }, |
| 39 | + } |
| 40 | + |
| 41 | + for _, testCase := range testCases { |
| 42 | + err := Forbidden(testCase.message) |
| 43 | + if err.Code() != testCase.code { |
| 44 | + t.Errorf("err.Code() %d != testCase.code %d", err.Code(), testCase.code) |
| 45 | + } |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +// go test -v -cover -count=1 -test.cpu=1 -run=^TestNotFound$ |
| 50 | +func TestNotFound(t *testing.T) { |
| 51 | + testCases := []struct { |
| 52 | + message string |
| 53 | + code int32 |
| 54 | + }{ |
| 55 | + { |
| 56 | + message: "id is nil", |
| 57 | + code: CodeNotFound, |
| 58 | + }, |
| 59 | + } |
| 60 | + |
| 61 | + for _, testCase := range testCases { |
| 62 | + err := NotFound(testCase.message) |
| 63 | + if err.Code() != testCase.code { |
| 64 | + t.Errorf("err.Code() %d != testCase.code %d", err.Code(), testCase.code) |
| 65 | + } |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +// go test -v -cover -count=1 -test.cpu=1 -run=^TestRequireLogin$ |
| 70 | +func TestRequireLogin(t *testing.T) { |
| 71 | + testCases := []struct { |
| 72 | + message string |
| 73 | + code int32 |
| 74 | + }{ |
| 75 | + { |
| 76 | + message: "id is nil", |
| 77 | + code: CodeRequireLogin, |
| 78 | + }, |
| 79 | + } |
| 80 | + |
| 81 | + for _, testCase := range testCases { |
| 82 | + err := RequireLogin(testCase.message) |
| 83 | + if err.Code() != testCase.code { |
| 84 | + t.Errorf("err.Code() %d != testCase.code %d", err.Code(), testCase.code) |
| 85 | + } |
| 86 | + } |
| 87 | +} |
0 commit comments