29 lines
623 B
Go
29 lines
623 B
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func TestConsultationStrPtr(t *testing.T) {
|
|
if consultationStrPtr("") != nil {
|
|
t.Error("空字符串应为 nil")
|
|
}
|
|
if got := consultationStrPtr("原因"); got == nil || *got != "原因" {
|
|
t.Errorf("非空字符串应返回指针: %v", got)
|
|
}
|
|
}
|
|
|
|
func TestCanReviewKnowledge(t *testing.T) {
|
|
gin.SetMode(gin.TestMode)
|
|
rec := httptest.NewRecorder()
|
|
c, _ := gin.CreateTestContext(rec)
|
|
c.Request = httptest.NewRequest(http.MethodGet, "/", nil)
|
|
if canReviewKnowledge(c) {
|
|
t.Error("nil context 不应通过")
|
|
}
|
|
}
|