- 替换 Beego 框架为 GoFrame v2 - 重构项目结构: controller/service/dao/middleware 分层 - 替换自定义 crons 包为 gcron - 模板从 views/ 迁移到 resource/template/ - 配置从 conf/app.conf 迁移到 config.yml - 数据库从 MySQL 切换为 SQLite (modernc.org/sqlite) - 移除 agent/ 远程执行器(待后续迁移) - 移除 crons/ 自定义定时器包 - 静态资源整理到 resource/static/
127 lines
3.2 KiB
Go
127 lines
3.2 KiB
Go
package consts
|
|
|
|
import "testing"
|
|
|
|
func TestTaskExecutionStatus(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
value int
|
|
want string
|
|
}{
|
|
{"TaskStatusSuccess", TaskStatusSuccess, "0"},
|
|
{"TaskStatusError", TaskStatusError, "-1"},
|
|
{"TaskStatusTimeout", TaskStatusTimeout, "-2"},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := tt.value; got != 0 && got != -1 && got != -2 {
|
|
t.Errorf("%s = %d, want one of {0, -1, -2}", tt.name, got)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Verify specific values
|
|
if TaskStatusSuccess != 0 {
|
|
t.Errorf("TaskStatusSuccess = %d, want 0", TaskStatusSuccess)
|
|
}
|
|
if TaskStatusError != -1 {
|
|
t.Errorf("TaskStatusError = %d, want -1", TaskStatusError)
|
|
}
|
|
if TaskStatusTimeout != -2 {
|
|
t.Errorf("TaskStatusTimeout = %d, want -2", TaskStatusTimeout)
|
|
}
|
|
}
|
|
|
|
func TestTaskBusinessStatus(t *testing.T) {
|
|
if TaskDeleted != -1 {
|
|
t.Errorf("TaskDeleted = %d, want -1", TaskDeleted)
|
|
}
|
|
if TaskPaused != 0 {
|
|
t.Errorf("TaskPaused = %d, want 0", TaskPaused)
|
|
}
|
|
if TaskRunning != 1 {
|
|
t.Errorf("TaskRunning = %d, want 1", TaskRunning)
|
|
}
|
|
if TaskPendingAudit != 2 {
|
|
t.Errorf("TaskPendingAudit = %d, want 2", TaskPendingAudit)
|
|
}
|
|
if TaskAuditFailed != 3 {
|
|
t.Errorf("TaskAuditFailed = %d, want 3", TaskAuditFailed)
|
|
}
|
|
}
|
|
|
|
func TestMsgCodes(t *testing.T) {
|
|
if MsgOK != 0 {
|
|
t.Errorf("MsgOK = %d, want 0", MsgOK)
|
|
}
|
|
if MsgErr != -1 {
|
|
t.Errorf("MsgErr = %d, want -1", MsgErr)
|
|
}
|
|
}
|
|
|
|
func TestNotifyTypes(t *testing.T) {
|
|
if NotifyTypeEmail != 0 {
|
|
t.Errorf("NotifyTypeEmail = %d, want 0", NotifyTypeEmail)
|
|
}
|
|
if NotifyTypeSMS != 1 {
|
|
t.Errorf("NotifyTypeSMS = %d, want 1", NotifyTypeSMS)
|
|
}
|
|
if NotifyTypeDingtalk != 2 {
|
|
t.Errorf("NotifyTypeDingtalk = %d, want 2", NotifyTypeDingtalk)
|
|
}
|
|
if NotifyTypeWechat != 3 {
|
|
t.Errorf("NotifyTypeWechat = %d, want 3", NotifyTypeWechat)
|
|
}
|
|
}
|
|
|
|
func TestNotifyTplTypes(t *testing.T) {
|
|
if NotifyTplTypeSystem != "system" {
|
|
t.Errorf("NotifyTplTypeSystem = %q, want %q", NotifyTplTypeSystem, "system")
|
|
}
|
|
if NotifyTplTypeDefault != "default" {
|
|
t.Errorf("NotifyTplTypeDefault = %q, want %q", NotifyTplTypeDefault, "default")
|
|
}
|
|
}
|
|
|
|
func TestConnectionTypes(t *testing.T) {
|
|
if ConnectionTypeSSH != 0 {
|
|
t.Errorf("ConnectionTypeSSH = %d, want 0", ConnectionTypeSSH)
|
|
}
|
|
if ConnectionTypeTelnet != 1 {
|
|
t.Errorf("ConnectionTypeTelnet = %d, want 1", ConnectionTypeTelnet)
|
|
}
|
|
if ConnectionTypeAgent != 2 {
|
|
t.Errorf("ConnectionTypeAgent = %d, want 2", ConnectionTypeAgent)
|
|
}
|
|
}
|
|
|
|
func TestAuthTypes(t *testing.T) {
|
|
if AuthTypePassword != 0 {
|
|
t.Errorf("AuthTypePassword = %d, want 0", AuthTypePassword)
|
|
}
|
|
if AuthTypeKey != 1 {
|
|
t.Errorf("AuthTypeKey = %d, want 1", AuthTypeKey)
|
|
}
|
|
}
|
|
|
|
func TestServerTypes(t *testing.T) {
|
|
if ServerTypeAll != 0 {
|
|
t.Errorf("ServerTypeAll = %d, want 0", ServerTypeAll)
|
|
}
|
|
if ServerTypePoll != 1 {
|
|
t.Errorf("ServerTypePoll = %d, want 1", ServerTypePoll)
|
|
}
|
|
}
|
|
|
|
func TestServerStatuses(t *testing.T) {
|
|
if ServerStatusNormal != 0 {
|
|
t.Errorf("ServerStatusNormal = %d, want 0", ServerStatusNormal)
|
|
}
|
|
if ServerStatusAbnormal != 1 {
|
|
t.Errorf("ServerStatusAbnormal = %d, want 1", ServerStatusAbnormal)
|
|
}
|
|
if ServerStatusDisabled != 2 {
|
|
t.Errorf("ServerStatusDisabled = %d, want 2", ServerStatusDisabled)
|
|
}
|
|
}
|