Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xpkg
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
屠思豪
xpkg
Commits
2a08a10c
提交
2a08a10c
authored
5月 13, 2025
作者:
mooncake9527
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
45807d0d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
134 行增加
和
0 行删除
+134
-0
.gitignore
.gitignore
+26
-0
app_test.go
app/app_test.go
+108
-0
没有找到文件。
.gitignore
0 → 100644
浏览文件 @
2a08a10c
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.log
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# idea
.idea/
.vscode/
*.iml
*.ipr
*.iws
__debug*
cmd/*/__debug*
app/app_test.go
0 → 100644
浏览文件 @
2a08a10c
package
app
import
(
"context"
"errors"
"fmt"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type
httpServer
struct
{}
func
(
h
*
httpServer
)
Start
()
error
{
fmt
.
Println
(
"running http server"
)
return
nil
}
func
(
h
*
httpServer
)
Stop
()
error
{
return
errors
.
New
(
"mock stop http server"
)
}
func
(
h
*
httpServer
)
String
()
string
{
return
":8081"
}
type
httpServer2
struct
{}
func
(
h
*
httpServer2
)
Start
()
error
{
fmt
.
Println
(
"running http server2"
)
return
nil
}
func
(
h
*
httpServer2
)
Stop
()
error
{
fmt
.
Println
(
"stop http server"
)
return
nil
}
func
(
h
*
httpServer2
)
String
()
string
{
return
":8082"
}
type
httpServer3
struct
{}
func
(
h
*
httpServer3
)
Start
()
error
{
return
errors
.
New
(
"mock running http server3 error"
)
}
func
(
h
*
httpServer3
)
Stop
()
error
{
fmt
.
Println
(
"stop http server3"
)
return
nil
}
func
(
h
*
httpServer3
)
String
()
string
{
return
":8083"
}
func
TestApp
(
t
*
testing
.
T
)
{
var
(
s
=
&
httpServer
{}
s2
=
&
httpServer2
{}
servers
=
[]
IServer
{
s
,
s2
}
closes
=
[]
Close
{
func
()
error
{
return
s
.
Stop
()
},
func
()
error
{
return
s2
.
Stop
()
},
}
)
a
:=
New
(
servers
,
closes
)
go
a
.
Run
()
time
.
Sleep
(
time
.
Second
)
// test watch
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Millisecond
*
100
)
defer
cancel
()
assert
.
Error
(
t
,
a
.
watch
(
ctx
))
time
.
Sleep
(
time
.
Second
)
t
.
Log
(
a
.
stop
())
}
func
TestAppError
(
t
*
testing
.
T
)
{
s3
:=
&
httpServer3
{}
servers
:=
[]
IServer
{
s3
}
closes
:=
[]
Close
{
func
()
error
{
return
s3
.
Stop
()
},
}
a
:=
New
(
servers
,
closes
)
go
func
()
{
defer
func
()
{
if
e
:=
recover
();
e
!=
nil
{
t
.
Log
(
e
)
}
}()
a
.
Run
()
}()
time
.
Sleep
(
time
.
Second
)
t
.
Log
(
a
.
stop
())
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论