mirror of
https://github.com/woodchen-ink/certimate.git
synced 2025-07-18 17:31:55 +08:00
test: add unit test cases
This commit is contained in:
parent
0b9312b549
commit
13582d1a7b
35
internal/deployer/factory.go
Normal file
35
internal/deployer/factory.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package deployer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/usual2970/certimate/internal/domain"
|
||||||
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
|
providerAliyunOss "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/aliyun-oss"
|
||||||
|
"github.com/usual2970/certimate/internal/pkg/utils/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TODO: 该方法目前未实际使用,将在后续迭代中替换
|
||||||
|
func createDeployer(target string, accessConfig string, deployConfig map[string]any) (deployer.Deployer, deployer.Logger, error) {
|
||||||
|
logger := deployer.NewDefaultLogger()
|
||||||
|
|
||||||
|
switch target {
|
||||||
|
case targetAliyunOSS:
|
||||||
|
access := &domain.AliyunAccess{}
|
||||||
|
if err := json.Unmarshal([]byte(accessConfig), access); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
deployer, err := providerAliyunOss.NewWithLogger(&providerAliyunOss.AliyunOSSDeployerConfig{
|
||||||
|
AccessKeyId: access.AccessKeyId,
|
||||||
|
AccessKeySecret: access.AccessKeySecret,
|
||||||
|
Region: maps.GetValueAsString(deployConfig, "region"),
|
||||||
|
Bucket: maps.GetValueAsString(deployConfig, "bucket"),
|
||||||
|
Domain: maps.GetValueAsString(deployConfig, "domain"),
|
||||||
|
}, logger)
|
||||||
|
return deployer, logger, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil, fmt.Errorf("unsupported deployer target: %s", target)
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package notify
|
package notify
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"fmt"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/domain"
|
"github.com/usual2970/certimate/internal/domain"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/notifier"
|
"github.com/usual2970/certimate/internal/pkg/core/notifier"
|
||||||
@ -62,5 +62,5 @@ func createNotifier(channel string, channelConfig map[string]any) (notifier.Noti
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.New("unsupported notifier channel")
|
return nil, fmt.Errorf("unsupported notifier channel: %s", channelConfig)
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,9 @@ type Logger interface {
|
|||||||
|
|
||||||
// 获取所有日志记录。
|
// 获取所有日志记录。
|
||||||
GetRecords() []string
|
GetRecords() []string
|
||||||
|
|
||||||
|
// 清空。
|
||||||
|
Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 表示默认的日志记录器类型。
|
// 表示默认的日志记录器类型。
|
||||||
@ -43,7 +46,9 @@ func (l *DefaultLogger) Appendt(tag string, data ...any) {
|
|||||||
temp[0] = tag
|
temp[0] = tag
|
||||||
for i, v := range data {
|
for i, v := range data {
|
||||||
s := ""
|
s := ""
|
||||||
if v != nil {
|
if v == nil {
|
||||||
|
s = "<nil>"
|
||||||
|
} else {
|
||||||
switch reflect.ValueOf(v).Kind() {
|
switch reflect.ValueOf(v).Kind() {
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
s = v.(string)
|
s = v.(string)
|
||||||
@ -78,6 +83,10 @@ func (l *DefaultLogger) GetRecords() []string {
|
|||||||
return temp
|
return temp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *DefaultLogger) Flush() {
|
||||||
|
l.records = make([]string, 0)
|
||||||
|
}
|
||||||
|
|
||||||
func (l *DefaultLogger) ensureInitialized() {
|
func (l *DefaultLogger) ensureInitialized() {
|
||||||
if l.records == nil {
|
if l.records == nil {
|
||||||
l.records = make([]string, 0)
|
l.records = make([]string, 0)
|
||||||
@ -101,6 +110,7 @@ func (l *NilLogger) Appendf(string, ...any) {}
|
|||||||
func (l *NilLogger) GetRecords() []string {
|
func (l *NilLogger) GetRecords() []string {
|
||||||
return make([]string, 0)
|
return make([]string, 0)
|
||||||
}
|
}
|
||||||
|
func (l *NilLogger) Flush() {}
|
||||||
|
|
||||||
func NewNilLogger() *NilLogger {
|
func NewNilLogger() *NilLogger {
|
||||||
return &NilLogger{}
|
return &NilLogger{}
|
||||||
|
56
internal/pkg/core/deployer/logger_test.go
Normal file
56
internal/pkg/core/deployer/logger_test.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package deployer_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
Shell command to run this test:
|
||||||
|
|
||||||
|
go test -v logger_test.go
|
||||||
|
*/
|
||||||
|
func TestLogger(t *testing.T) {
|
||||||
|
t.Run("Logger_Appendt", func(t *testing.T) {
|
||||||
|
logger := deployer.NewDefaultLogger()
|
||||||
|
|
||||||
|
logger.Appendt("test")
|
||||||
|
logger.Appendt("test_nil", nil)
|
||||||
|
logger.Appendt("test_int", 1024)
|
||||||
|
logger.Appendt("test_string", "certimate")
|
||||||
|
logger.Appendt("test_map", map[string]interface{}{"key": "value"})
|
||||||
|
logger.Appendt("test_struct", struct{ Name string }{Name: "certimate"})
|
||||||
|
logger.Appendt("test_slice", []string{"certimate"})
|
||||||
|
t.Log(logger.GetRecords())
|
||||||
|
if len(logger.GetRecords()) != 7 {
|
||||||
|
t.Errorf("expected 7 records, got %d", len(logger.GetRecords()))
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Flush()
|
||||||
|
if len(logger.GetRecords()) != 0 {
|
||||||
|
t.Errorf("expected 0 records, got %d", len(logger.GetRecords()))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Logger_Appendf", func(t *testing.T) {
|
||||||
|
logger := deployer.NewDefaultLogger()
|
||||||
|
|
||||||
|
logger.Appendf("test")
|
||||||
|
logger.Appendf("test_nil: %v", nil)
|
||||||
|
logger.Appendf("test_int: %v", 1024)
|
||||||
|
logger.Appendf("test_string: %v", "certimate")
|
||||||
|
logger.Appendf("test_map: %v", map[string]interface{}{"key": "value"})
|
||||||
|
logger.Appendf("test_struct: %v", struct{ Name string }{Name: "certimate"})
|
||||||
|
logger.Appendf("test_slice: %v", []string{"certimate"})
|
||||||
|
t.Log(logger.GetRecords())
|
||||||
|
if len(logger.GetRecords()) != 7 {
|
||||||
|
t.Errorf("expected 7 records, got %d", len(logger.GetRecords()))
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Flush()
|
||||||
|
if len(logger.GetRecords()) != 0 {
|
||||||
|
t.Errorf("expected 0 records, got %d", len(logger.GetRecords()))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
@ -45,7 +45,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_ALIYUNALB_LOADBALANCERID="your-alb-instance-id" \
|
--CERTIMATE_DEPLOYER_ALIYUNALB_LOADBALANCERID="your-alb-instance-id" \
|
||||||
--CERTIMATE_DEPLOYER_ALIYUNALB_LISTENERID="your-alb-listener-id"
|
--CERTIMATE_DEPLOYER_ALIYUNALB_LISTENERID="your-alb-listener-id"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy_ToLoadbalancer", func(t *testing.T) {
|
t.Run("Deploy_ToLoadbalancer", func(t *testing.T) {
|
||||||
|
@ -39,7 +39,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_ALIYUNCDN_ACCESSKEYSECRET="your-access-key-secret" \
|
--CERTIMATE_DEPLOYER_ALIYUNCDN_ACCESSKEYSECRET="your-access-key-secret" \
|
||||||
--CERTIMATE_DEPLOYER_ALIYUNCDN_DOMAIN="example.com"
|
--CERTIMATE_DEPLOYER_ALIYUNCDN_DOMAIN="example.com"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy", func(t *testing.T) {
|
t.Run("Deploy", func(t *testing.T) {
|
||||||
|
@ -45,7 +45,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_ALIYUNCLB_LOADBALANCERID="your-clb-instance-id" \
|
--CERTIMATE_DEPLOYER_ALIYUNCLB_LOADBALANCERID="your-clb-instance-id" \
|
||||||
--CERTIMATE_DEPLOYER_ALIYUNCLB_LISTENERPORT=443
|
--CERTIMATE_DEPLOYER_ALIYUNCLB_LISTENERPORT=443
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy_ToLoadbalancer", func(t *testing.T) {
|
t.Run("Deploy_ToLoadbalancer", func(t *testing.T) {
|
||||||
|
@ -39,7 +39,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_ALIYUNDCDN_ACCESSKEYSECRET="your-access-key-secret" \
|
--CERTIMATE_DEPLOYER_ALIYUNDCDN_ACCESSKEYSECRET="your-access-key-secret" \
|
||||||
--CERTIMATE_DEPLOYER_ALIYUNDCDN_DOMAIN="example.com"
|
--CERTIMATE_DEPLOYER_ALIYUNDCDN_DOMAIN="example.com"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy", func(t *testing.T) {
|
t.Run("Deploy", func(t *testing.T) {
|
||||||
|
@ -45,7 +45,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_ALIYUNNLB_LOADBALANCERID="your-nlb-instance-id" \
|
--CERTIMATE_DEPLOYER_ALIYUNNLB_LOADBALANCERID="your-nlb-instance-id" \
|
||||||
--CERTIMATE_DEPLOYER_ALIYUNNLB_LISTENERID="your-nlb-listener-id"
|
--CERTIMATE_DEPLOYER_ALIYUNNLB_LISTENERID="your-nlb-listener-id"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy_ToLoadbalancer", func(t *testing.T) {
|
t.Run("Deploy_ToLoadbalancer", func(t *testing.T) {
|
||||||
|
@ -45,7 +45,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_ALIYUNOSS_BUCKET="your-oss-bucket" \
|
--CERTIMATE_DEPLOYER_ALIYUNOSS_BUCKET="your-oss-bucket" \
|
||||||
--CERTIMATE_DEPLOYER_ALIYUNOSS_DOMAIN="example.com"
|
--CERTIMATE_DEPLOYER_ALIYUNOSS_DOMAIN="example.com"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy", func(t *testing.T) {
|
t.Run("Deploy", func(t *testing.T) {
|
||||||
|
@ -39,7 +39,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_BAIDUCLOUDCDN_SECRETACCESSKEY="your-secret-access-key" \
|
--CERTIMATE_DEPLOYER_BAIDUCLOUDCDN_SECRETACCESSKEY="your-secret-access-key" \
|
||||||
--CERTIMATE_DEPLOYER_BAIDUCLOUDCDN_DOMAIN="example.com"
|
--CERTIMATE_DEPLOYER_BAIDUCLOUDCDN_DOMAIN="example.com"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy", func(t *testing.T) {
|
t.Run("Deploy", func(t *testing.T) {
|
||||||
|
@ -39,7 +39,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_BYTEPLUSCDN_SECRETKEY="your-secret-key" \
|
--CERTIMATE_DEPLOYER_BYTEPLUSCDN_SECRETKEY="your-secret-key" \
|
||||||
--CERTIMATE_DEPLOYER_BYTEPLUSCDN_DOMAIN="example.com"
|
--CERTIMATE_DEPLOYER_BYTEPLUSCDN_DOMAIN="example.com"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy", func(t *testing.T) {
|
t.Run("Deploy", func(t *testing.T) {
|
||||||
|
@ -39,7 +39,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_DOGECLOUDCDN_SECRETKEY="your-secret-key" \
|
--CERTIMATE_DEPLOYER_DOGECLOUDCDN_SECRETKEY="your-secret-key" \
|
||||||
--CERTIMATE_DEPLOYER_DOGECLOUDCDN_DOMAIN="example.com"
|
--CERTIMATE_DEPLOYER_DOGECLOUDCDN_DOMAIN="example.com"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy", func(t *testing.T) {
|
t.Run("Deploy", func(t *testing.T) {
|
||||||
|
@ -42,7 +42,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_HUAWEICLOUDCDN_REGION="cn-north-1" \
|
--CERTIMATE_DEPLOYER_HUAWEICLOUDCDN_REGION="cn-north-1" \
|
||||||
--CERTIMATE_DEPLOYER_HUAWEICLOUDCDN_DOMAIN="example.com"
|
--CERTIMATE_DEPLOYER_HUAWEICLOUDCDN_DOMAIN="example.com"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy", func(t *testing.T) {
|
t.Run("Deploy", func(t *testing.T) {
|
||||||
|
@ -48,7 +48,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_HUAWEICLOUDELB_LOADBALANCERID="your-elb-loadbalancer-id" \
|
--CERTIMATE_DEPLOYER_HUAWEICLOUDELB_LOADBALANCERID="your-elb-loadbalancer-id" \
|
||||||
--CERTIMATE_DEPLOYER_HUAWEICLOUDELB_LISTENERID="your-elb-listener-id"
|
--CERTIMATE_DEPLOYER_HUAWEICLOUDELB_LISTENERID="your-elb-listener-id"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy_ToCertificate", func(t *testing.T) {
|
t.Run("Deploy_ToCertificate", func(t *testing.T) {
|
||||||
|
@ -42,7 +42,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_K8SSECRET_SECRETDATAKEYFORCRT="tls.crt" \
|
--CERTIMATE_DEPLOYER_K8SSECRET_SECRETDATAKEYFORCRT="tls.crt" \
|
||||||
--CERTIMATE_DEPLOYER_K8SSECRET_SECRETDATAKEYFORKEY="tls.key"
|
--CERTIMATE_DEPLOYER_K8SSECRET_SECRETDATAKEYFORKEY="tls.key"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy", func(t *testing.T) {
|
t.Run("Deploy", func(t *testing.T) {
|
||||||
|
@ -48,7 +48,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_LOCAL_JKSKEYPASS="your-jks-keypass" \
|
--CERTIMATE_DEPLOYER_LOCAL_JKSKEYPASS="your-jks-keypass" \
|
||||||
--CERTIMATE_DEPLOYER_LOCAL_JKSSTOREPASS="your-jks-storepass"
|
--CERTIMATE_DEPLOYER_LOCAL_JKSSTOREPASS="your-jks-storepass"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy_PEM", func(t *testing.T) {
|
t.Run("Deploy_PEM", func(t *testing.T) {
|
||||||
|
@ -39,7 +39,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_QINIUCDN_SECRETKEY="your-secret-key" \
|
--CERTIMATE_DEPLOYER_QINIUCDN_SECRETKEY="your-secret-key" \
|
||||||
--CERTIMATE_DEPLOYER_QINIUCDN_DOMAIN="example.com" \
|
--CERTIMATE_DEPLOYER_QINIUCDN_DOMAIN="example.com" \
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy", func(t *testing.T) {
|
t.Run("Deploy", func(t *testing.T) {
|
||||||
|
@ -48,7 +48,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_SSH_OUTPUTCERTPATH="/path/to/your-output-cert.pem" \
|
--CERTIMATE_DEPLOYER_SSH_OUTPUTCERTPATH="/path/to/your-output-cert.pem" \
|
||||||
--CERTIMATE_DEPLOYER_SSH_OUTPUTKEYPATH="/path/to/your-output-key.pem"
|
--CERTIMATE_DEPLOYER_SSH_OUTPUTKEYPATH="/path/to/your-output-key.pem"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy", func(t *testing.T) {
|
t.Run("Deploy", func(t *testing.T) {
|
||||||
|
@ -39,7 +39,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_TENCENTCLOUDCDN_SECRETKEY="your-secret-key" \
|
--CERTIMATE_DEPLOYER_TENCENTCLOUDCDN_SECRETKEY="your-secret-key" \
|
||||||
--CERTIMATE_DEPLOYER_TENCENTCLOUDCDN_DOMAIN="example.com"
|
--CERTIMATE_DEPLOYER_TENCENTCLOUDCDN_DOMAIN="example.com"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy", func(t *testing.T) {
|
t.Run("Deploy", func(t *testing.T) {
|
||||||
|
@ -48,7 +48,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_TENCENTCLOUDCLB_LISTENERID="your-clb-lbl-id" \
|
--CERTIMATE_DEPLOYER_TENCENTCLOUDCLB_LISTENERID="your-clb-lbl-id" \
|
||||||
--CERTIMATE_DEPLOYER_TENCENTCLOUDCLB_DOMAIN="example.com"
|
--CERTIMATE_DEPLOYER_TENCENTCLOUDCLB_DOMAIN="example.com"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy_UseSslDeploy", func(t *testing.T) {
|
t.Run("Deploy_UseSslDeploy", func(t *testing.T) {
|
||||||
|
@ -45,7 +45,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_TENCENTCLOUDCOS_BUCKET="your-cos-bucket" \
|
--CERTIMATE_DEPLOYER_TENCENTCLOUDCOS_BUCKET="your-cos-bucket" \
|
||||||
--CERTIMATE_DEPLOYER_TENCENTCLOUDCOS_DOMAIN="example.com"
|
--CERTIMATE_DEPLOYER_TENCENTCLOUDCOS_DOMAIN="example.com"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy", func(t *testing.T) {
|
t.Run("Deploy", func(t *testing.T) {
|
||||||
|
@ -39,7 +39,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_TENCENTCLOUDECDN_SECRETKEY="your-secret-key" \
|
--CERTIMATE_DEPLOYER_TENCENTCLOUDECDN_SECRETKEY="your-secret-key" \
|
||||||
--CERTIMATE_DEPLOYER_TENCENTCLOUDECDN_DOMAIN="example.com"
|
--CERTIMATE_DEPLOYER_TENCENTCLOUDECDN_DOMAIN="example.com"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy", func(t *testing.T) {
|
t.Run("Deploy", func(t *testing.T) {
|
||||||
|
@ -42,7 +42,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_TENCENTCLOUDETEO_ZONEID="your-zone-id" \
|
--CERTIMATE_DEPLOYER_TENCENTCLOUDETEO_ZONEID="your-zone-id" \
|
||||||
--CERTIMATE_DEPLOYER_TENCENTCLOUDETEO_DOMAIN="example.com"
|
--CERTIMATE_DEPLOYER_TENCENTCLOUDETEO_DOMAIN="example.com"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy", func(t *testing.T) {
|
t.Run("Deploy", func(t *testing.T) {
|
||||||
|
@ -39,7 +39,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_VOLCENGINECDN_SECRETKEY="your-secret-key" \
|
--CERTIMATE_DEPLOYER_VOLCENGINECDN_SECRETKEY="your-secret-key" \
|
||||||
--CERTIMATE_DEPLOYER_VOLCENGINECDN_DOMAIN="example.com"
|
--CERTIMATE_DEPLOYER_VOLCENGINECDN_DOMAIN="example.com"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy", func(t *testing.T) {
|
t.Run("Deploy", func(t *testing.T) {
|
||||||
|
@ -39,7 +39,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_VOLCENGINELIVE_SECRETKEY="your-secret-key" \
|
--CERTIMATE_DEPLOYER_VOLCENGINELIVE_SECRETKEY="your-secret-key" \
|
||||||
--CERTIMATE_DEPLOYER_VOLCENGINELIVE_DOMAIN="example.com"
|
--CERTIMATE_DEPLOYER_VOLCENGINELIVE_DOMAIN="example.com"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy", func(t *testing.T) {
|
t.Run("Deploy", func(t *testing.T) {
|
||||||
|
@ -33,7 +33,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_DEPLOYER_WEBHOOK_INPUTKEYPATH="/path/to/your-input-key.pem" \
|
--CERTIMATE_DEPLOYER_WEBHOOK_INPUTKEYPATH="/path/to/your-input-key.pem" \
|
||||||
--CERTIMATE_DEPLOYER_WEBHOOK_URL="https://example.com/your-webhook-url"
|
--CERTIMATE_DEPLOYER_WEBHOOK_URL="https://example.com/your-webhook-url"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestDeploy(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Deploy", func(t *testing.T) {
|
t.Run("Deploy", func(t *testing.T) {
|
||||||
|
64
internal/pkg/core/notifier/providers/bark/bark_test.go
Normal file
64
internal/pkg/core/notifier/providers/bark/bark_test.go
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package bark_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
provider "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/bark"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
mockSubject = "test_subject"
|
||||||
|
mockMessage = "test_message"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
fServerUrl string
|
||||||
|
fDeviceKey string
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
argsPrefix := "CERTIMATE_NOTIFIER_BARK_"
|
||||||
|
|
||||||
|
flag.StringVar(&fServerUrl, argsPrefix+"SERVERURL", "", "")
|
||||||
|
flag.StringVar(&fDeviceKey, argsPrefix+"DEVICEKEY", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Shell command to run this test:
|
||||||
|
|
||||||
|
go test -v bark_test.go -args \
|
||||||
|
--CERTIMATE_NOTIFIER_BARK_SERVERURL="https://example.com/your-server-url" \
|
||||||
|
--CERTIMATE_NOTIFIER_BARK_DEVICEKEY="your-device-key"
|
||||||
|
*/
|
||||||
|
func TestNotify(t *testing.T) {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
t.Run("Notify", func(t *testing.T) {
|
||||||
|
t.Log(strings.Join([]string{
|
||||||
|
"args:",
|
||||||
|
fmt.Sprintf("SERVERURL: %v", fServerUrl),
|
||||||
|
fmt.Sprintf("DEVICEKEY: %v", fDeviceKey),
|
||||||
|
}, "\n"))
|
||||||
|
|
||||||
|
notifier, err := provider.New(&provider.BarkNotifierConfig{
|
||||||
|
ServerUrl: fServerUrl,
|
||||||
|
DeviceKey: fDeviceKey,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := notifier.Notify(context.Background(), mockSubject, mockMessage)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("ok: %v", res)
|
||||||
|
})
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package dingtalk_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
provider "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/dingtalk"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
mockSubject = "test_subject"
|
||||||
|
mockMessage = "test_message"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
fAccessToken string
|
||||||
|
fSecret string
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
argsPrefix := "CERTIMATE_NOTIFIER_DINGTALK_"
|
||||||
|
|
||||||
|
flag.StringVar(&fAccessToken, argsPrefix+"ACCESSTOKEN", "", "")
|
||||||
|
flag.StringVar(&fSecret, argsPrefix+"SECRET", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Shell command to run this test:
|
||||||
|
|
||||||
|
go test -v dingtalk_test.go -args \
|
||||||
|
--CERTIMATE_NOTIFIER_DINGTALK_URL="https://example.com/your-webhook-url"
|
||||||
|
*/
|
||||||
|
func TestNotify(t *testing.T) {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
t.Run("Notify", func(t *testing.T) {
|
||||||
|
t.Log(strings.Join([]string{
|
||||||
|
"args:",
|
||||||
|
fmt.Sprintf("ACCESSTOKEN: %v", fAccessToken),
|
||||||
|
fmt.Sprintf("SECRET: %v", fSecret),
|
||||||
|
}, "\n"))
|
||||||
|
|
||||||
|
notifier, err := provider.New(&provider.DingTalkNotifierConfig{
|
||||||
|
AccessToken: fAccessToken,
|
||||||
|
Secret: fSecret,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := notifier.Notify(context.Background(), mockSubject, mockMessage)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("ok: %v", res)
|
||||||
|
})
|
||||||
|
}
|
@ -49,7 +49,7 @@ Shell command to run this test:
|
|||||||
--CERTIMATE_NOTIFIER_EMAIL_SENDERADDRESS="sender@example.com" \
|
--CERTIMATE_NOTIFIER_EMAIL_SENDERADDRESS="sender@example.com" \
|
||||||
--CERTIMATE_NOTIFIER_EMAIL_RECEIVERADDRESS="receiver@example.com"
|
--CERTIMATE_NOTIFIER_EMAIL_RECEIVERADDRESS="receiver@example.com"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestNotify(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Notify", func(t *testing.T) {
|
t.Run("Notify", func(t *testing.T) {
|
||||||
|
57
internal/pkg/core/notifier/providers/lark/lark_test.go
Normal file
57
internal/pkg/core/notifier/providers/lark/lark_test.go
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package lark_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
provider "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/lark"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
mockSubject = "test_subject"
|
||||||
|
mockMessage = "test_message"
|
||||||
|
)
|
||||||
|
|
||||||
|
var fWebhookUrl string
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
argsPrefix := "CERTIMATE_NOTIFIER_LARK_"
|
||||||
|
|
||||||
|
flag.StringVar(&fWebhookUrl, argsPrefix+"WEBHOOKURL", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Shell command to run this test:
|
||||||
|
|
||||||
|
go test -v lark_test.go -args \
|
||||||
|
--CERTIMATE_NOTIFIER_LARK_WEBHOOKURL="https://example.com/your-webhook-url"
|
||||||
|
*/
|
||||||
|
func TestNotify(t *testing.T) {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
t.Run("Notify", func(t *testing.T) {
|
||||||
|
t.Log(strings.Join([]string{
|
||||||
|
"args:",
|
||||||
|
fmt.Sprintf("WEBHOOKURL: %v", fWebhookUrl),
|
||||||
|
}, "\n"))
|
||||||
|
|
||||||
|
notifier, err := provider.New(&provider.LarkNotifierConfig{
|
||||||
|
WebhookUrl: fWebhookUrl,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := notifier.Notify(context.Background(), mockSubject, mockMessage)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("ok: %v", res)
|
||||||
|
})
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
package serverchan_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
provider "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/serverchan"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
mockSubject = "test_subject"
|
||||||
|
mockMessage = "test_message"
|
||||||
|
)
|
||||||
|
|
||||||
|
var fUrl string
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
argsPrefix := "CERTIMATE_NOTIFIER_SERVERCHAN_"
|
||||||
|
|
||||||
|
flag.StringVar(&fUrl, argsPrefix+"URL", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Shell command to run this test:
|
||||||
|
|
||||||
|
go test -v serverchan_test.go -args \
|
||||||
|
--CERTIMATE_NOTIFIER_SERVERCHAN_URL="https://example.com/your-webhook-url" \
|
||||||
|
*/
|
||||||
|
func TestNotify(t *testing.T) {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
t.Run("Notify", func(t *testing.T) {
|
||||||
|
t.Log(strings.Join([]string{
|
||||||
|
"args:",
|
||||||
|
fmt.Sprintf("URL: %v", fUrl),
|
||||||
|
}, "\n"))
|
||||||
|
|
||||||
|
notifier, err := provider.New(&provider.ServerChanNotifierConfig{
|
||||||
|
Url: fUrl,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := notifier.Notify(context.Background(), mockSubject, mockMessage)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("ok: %v", res)
|
||||||
|
})
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
package telegram_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
provider "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/telegram"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
mockSubject = "test_subject"
|
||||||
|
mockMessage = "test_message"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
fApiToken string
|
||||||
|
fChartId int64
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
argsPrefix := "CERTIMATE_NOTIFIER_TELEGRAM_"
|
||||||
|
|
||||||
|
flag.StringVar(&fApiToken, argsPrefix+"APITOKEN", "", "")
|
||||||
|
flag.Int64Var(&fChartId, argsPrefix+"CHATID", 0, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Shell command to run this test:
|
||||||
|
|
||||||
|
go test -v telegram_test.go -args \
|
||||||
|
--CERTIMATE_NOTIFIER_TELEGRAM_APITOKEN="your-api-token" \
|
||||||
|
--CERTIMATE_NOTIFIER_TELEGRAM_CHATID=123456
|
||||||
|
*/
|
||||||
|
func TestNotify(t *testing.T) {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
t.Run("Notify", func(t *testing.T) {
|
||||||
|
t.Log(strings.Join([]string{
|
||||||
|
"args:",
|
||||||
|
fmt.Sprintf("APITOKEN: %v", fApiToken),
|
||||||
|
fmt.Sprintf("CHATID: %v", fChartId),
|
||||||
|
}, "\n"))
|
||||||
|
|
||||||
|
notifier, err := provider.New(&provider.TelegramNotifierConfig{
|
||||||
|
ApiToken: fApiToken,
|
||||||
|
ChatId: fChartId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := notifier.Notify(context.Background(), mockSubject, mockMessage)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("ok: %v", res)
|
||||||
|
})
|
||||||
|
}
|
@ -29,7 +29,7 @@ Shell command to run this test:
|
|||||||
go test -v webhook_test.go -args \
|
go test -v webhook_test.go -args \
|
||||||
--CERTIMATE_NOTIFIER_WEBHOOK_URL="https://example.com/your-webhook-url"
|
--CERTIMATE_NOTIFIER_WEBHOOK_URL="https://example.com/your-webhook-url"
|
||||||
*/
|
*/
|
||||||
func Test(t *testing.T) {
|
func TestNotify(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
t.Run("Notify", func(t *testing.T) {
|
t.Run("Notify", func(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user