补齐空部署目标防护与进度清单
This commit is contained in:
1 parent
9414b5c5d8
commit
cb88602882
8 files changed
+77
No files matched your search
@@ -231,6 +231,9 @@ func (w *CertificateWorkflow) deploy(ctx context.Context, result certificate.Iss
|
||||
if err != nil {
|
||||
return deployment.Report{}, fmt.Errorf("查询域名部署服务器失败:%w", err)
|
||||
}
|
||||
if len(servers) == 0 {
|
||||
return deployment.Report{Status: "failed"}, errors.New("\u57df\u540d\u5c1a\u672a\u5173\u8054\u4efb\u4f55\u90e8\u7f72\u670d\u52a1\u5668")
|
||||
}
|
||||
targets := make([]deployment.Target, 0, len(servers))
|
||||
for _, server := range servers {
|
||||
resolved, resolveErr := deployment.ResolveServerPaths(server, domainItem.Name, string(domainItem.CertificateType))
|
||||
|
||||
@@ -125,6 +125,24 @@ func TestCertificateWorkflowDeploysIssuedCertificateToAssociatedServers(t *testi
|
||||
}
|
||||
}
|
||||
|
||||
func TestCertificateWorkflowRejectsDomainWithoutDeploymentServers(t *testing.T) {
|
||||
deployer := &workflowDeployer{report: deployment.Report{Total: 1, Success: 1, Status: "success"}}
|
||||
state := &workflowDomainState{item: domain.Domain{ID: "domain-1", Name: "example.com", CertificateType: domain.CertificateSingle}}
|
||||
workflow := &CertificateWorkflow{
|
||||
Domains: state,
|
||||
Servers: workflowServerLister{},
|
||||
Deployment: deployer,
|
||||
}
|
||||
|
||||
report, err := workflow.deploy(context.Background(), certificate.IssueResult{DomainID: "domain-1"})
|
||||
if err == nil || !strings.Contains(err.Error(), "\u5c1a\u672a\u5173\u8054\u4efb\u4f55\u90e8\u7f72\u670d\u52a1\u5668") {
|
||||
t.Fatalf("\u672a\u5173\u8054\u670d\u52a1\u5668\u65f6\u5e94\u8fd4\u56de\u660e\u786e\u9519\u8bef\xef\xbc\x9a%v", err)
|
||||
}
|
||||
if report.Status != "failed" || deployer.targets != nil {
|
||||
t.Fatalf("\u672a\u5173\u8054\u670d\u52a1\u5668\u65f6\u4e0d\u5f97\u6267\u884c\u8fdc\u7a0b\u90e8\u7f72\xef\xbc\x9a%+v %+v", report, deployer.targets)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCertificateWorkflowReturnsPartialDeploymentError(t *testing.T) {
|
||||
deployer := &workflowDeployer{report: deployment.Report{
|
||||
Total: 2, Success: 1, Failed: 1, Status: "partial",
|
||||
|
||||
@@ -57,6 +57,10 @@ func NewService(factory ClientFactory) *Service {
|
||||
|
||||
func (s *Service) Deploy(ctx context.Context, targets []Target, artifact Artifact) Report {
|
||||
report := Report{Total: len(targets), Results: make([]Result, 0, len(targets))}
|
||||
if len(targets) == 0 {
|
||||
report.Status = "failed"
|
||||
return report
|
||||
}
|
||||
if s == nil || s.factory == nil {
|
||||
report.Status = "failed"
|
||||
report.Failed = len(targets)
|
||||
|
||||
@@ -269,6 +269,14 @@ func TestDeployReportsPartialSuccess(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeployRejectsEmptyTargets(t *testing.T) {
|
||||
service := NewService(fixedClientFactory{client: newMemoryClient()})
|
||||
report := service.Deploy(context.Background(), nil, testArtifact(t))
|
||||
if report.Status != "failed" || report.Total != 0 || report.Success != 0 || report.Failed != 0 {
|
||||
t.Fatalf("\u7a7a\u90e8\u7f72\u76ee\u6807\u4e0d\u5f97\u88ab\u89c6\u4e3a\u6210\u529f\xef\xbc\x9a%+v", report)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeployCleansPartialPrivateKeyUploadWithoutReplacingCurrentFiles(t *testing.T) {
|
||||
client := newMemoryClient()
|
||||
client.uploadError = "key.pem"
|
||||
|
||||
Reference in new issue
Block a user