-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(strategy): 增加域名和 HTTP 策略的测试用例并优化相关逻辑
- 为域名和 HTTP 策略添加测试用例,提高代码覆盖率 - 优化域名策略中的证书和端口检测逻辑 - 修正 HTTP 策略中的状态码和响应时间判断条件- 更新数据源相关结构,增加额外信息字段
- Loading branch information
1 parent
fa3a1d5
commit 5bda63e
Showing
10 changed files
with
166 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package bo_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/aide-family/moon/cmd/server/houyi/internal/biz/bo" | ||
"github.com/aide-family/moon/pkg/util/types" | ||
"github.com/aide-family/moon/pkg/vobj" | ||
) | ||
|
||
func TestStrategyDomain_Eval(t *testing.T) { | ||
domainStrategy := &bo.StrategyDomain{ | ||
ReceiverGroupIDs: nil, | ||
LabelNotices: nil, | ||
ID: 1, | ||
LevelID: 1, | ||
TeamID: 1, | ||
Status: vobj.StatusEnable, | ||
Alert: "百度域名证书监控", | ||
Threshold: 1, | ||
Labels: vobj.NewLabels(map[string]string{"domain": "baidu.com"}), | ||
Annotations: vobj.NewAnnotations(map[string]string{ | ||
"summary": "百度域名证书监控", | ||
"description": "百度域名证书监控 明细 {{ . }}", | ||
}), | ||
Domain: "baidu.com", | ||
Port: 443, | ||
StrategyType: vobj.StrategyTypeDomainCertificate, | ||
Condition: vobj.ConditionGTE, | ||
} | ||
|
||
eval, err := domainStrategy.Eval(context.Background()) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
|
||
for indexer, point := range eval { | ||
bs, _ := types.Marshal(point.Values) | ||
t.Logf("indexer: %s, point: %+v, meet: ", indexer, string(bs)) | ||
t.Log(domainStrategy.IsCompletelyMeet(point.Values)) | ||
} | ||
} | ||
|
||
func TestStrategyDomainPort_Eval(t *testing.T) { | ||
domainStrategy := &bo.StrategyDomain{ | ||
ReceiverGroupIDs: nil, | ||
LabelNotices: nil, | ||
ID: 1, | ||
LevelID: 1, | ||
TeamID: 1, | ||
Status: vobj.StatusEnable, | ||
Alert: "百度域名端口监控", | ||
Threshold: 1, | ||
Labels: vobj.NewLabels(map[string]string{"domain": "baidu.com"}), | ||
Annotations: vobj.NewAnnotations(map[string]string{ | ||
"summary": "百度域名端口监控", | ||
"description": "百度域名端口监控 明细 {{ . }}", | ||
}), | ||
Domain: "baidu.com", | ||
Port: 1443, | ||
StrategyType: vobj.StrategyTypeDomainPort, | ||
Condition: vobj.ConditionGTE, | ||
} | ||
|
||
eval, err := domainStrategy.Eval(context.Background()) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
|
||
for indexer, point := range eval { | ||
bs, _ := types.Marshal(point.Values) | ||
t.Logf("indexer: %s, point: %+v, meet: ", indexer, string(bs)) | ||
t.Log(domainStrategy.IsCompletelyMeet(point.Values)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package bo_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/aide-family/moon/cmd/server/houyi/internal/biz/bo" | ||
"github.com/aide-family/moon/pkg/util/types" | ||
"github.com/aide-family/moon/pkg/vobj" | ||
) | ||
|
||
func TestStrategyHTTP_Eval(t *testing.T) { | ||
httpStrategy := &bo.StrategyHTTP{ | ||
StrategyType: vobj.StrategyTypeHTTP, | ||
URL: "https://baidu.com", | ||
StatusCode: "5xx", | ||
StatusCodeCondition: vobj.ConditionGT, | ||
Headers: map[string]string{"Content-Type": "application/json"}, | ||
Body: "", | ||
Method: vobj.HTTPMethodGet, | ||
ResponseTime: 1, | ||
ResponseTimeCondition: vobj.ConditionGTE, | ||
Labels: vobj.NewLabels(map[string]string{"http": "baidu.com"}), | ||
Annotations: vobj.NewAnnotations(map[string]string{ | ||
"summary": "baidu.com http 探测", | ||
"description": "baidu.com http 探测, 明细 {{ . }}", | ||
}), | ||
ReceiverGroupIDs: nil, | ||
LabelNotices: nil, | ||
TeamID: 1, | ||
Status: vobj.StatusEnable, | ||
Alert: "baidu http 探测", | ||
LevelID: 1, | ||
ID: 1, | ||
} | ||
eval, err := httpStrategy.Eval(context.Background()) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
|
||
for indexer, point := range eval { | ||
bs, _ := types.Marshal(point.Values) | ||
t.Logf("indexer: %s, point: %+v, meet: ", indexer, string(bs)) | ||
t.Log(httpStrategy.IsCompletelyMeet(point.Values)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters