mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package gcode_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/gogf/gf/v2/errors/gcode"
|
|
"github.com/gogf/gf/v2/test/gtest"
|
|
)
|
|
|
|
func Test_Case(t *testing.T) {
|
|
gtest.C(t, func(t *gtest.T) {
|
|
t.Assert(gcode.CodeNil.String(), "-1")
|
|
t.Assert(gcode.CodeInternalError.String(), "50:Internal Error")
|
|
})
|
|
}
|
|
|
|
func Test_Nil(t *testing.T) {
|
|
gtest.C(t, func(t *gtest.T) {
|
|
c := gcode.New(1, "custom error", "detailed description")
|
|
t.Assert(c.Code(), 1)
|
|
t.Assert(c.Message(), "custom error")
|
|
t.Assert(c.Detail(), "detailed description")
|
|
})
|
|
}
|
|
|
|
func Test_WithCode(t *testing.T) {
|
|
gtest.C(t, func(t *gtest.T) {
|
|
c := gcode.WithCode(gcode.CodeInternalError, "CodeInternalError")
|
|
t.Assert(c.Code(), gcode.CodeInternalError.Code())
|
|
t.Assert(c.Detail(), "CodeInternalError")
|
|
})
|
|
}
|
|
|
|
func Test_String(t *testing.T) {
|
|
gtest.C(t, func(t *gtest.T) {
|
|
// Test with detail
|
|
c := gcode.New(100, "test message", "test detail")
|
|
t.Assert(c.(fmt.Stringer).String(), "100:test message test detail")
|
|
})
|
|
gtest.C(t, func(t *gtest.T) {
|
|
// Test with message but no detail
|
|
c := gcode.New(100, "test message", nil)
|
|
t.Assert(c.(fmt.Stringer).String(), "100:test message")
|
|
})
|
|
gtest.C(t, func(t *gtest.T) {
|
|
// Test with no message and no detail
|
|
c := gcode.New(100, "", nil)
|
|
t.Assert(c.(fmt.Stringer).String(), "100")
|
|
})
|
|
}
|