mirror of
https://github.com/woodchen-ink/certimate.git
synced 2025-07-18 17:31:55 +08:00
test: add some unit test cases for new Deployer
This commit is contained in:
parent
6367785b1b
commit
51fb9dca58
@ -5,20 +5,20 @@ import (
|
|||||||
|
|
||||||
"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"
|
||||||
notifierBark "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/bark"
|
npBark "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/bark"
|
||||||
notifierDingTalk "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/dingtalk"
|
npDingTalk "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/dingtalk"
|
||||||
notifierEmail "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/email"
|
npEmail "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/email"
|
||||||
notifierLark "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/lark"
|
npLark "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/lark"
|
||||||
notifierServerChan "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/serverchan"
|
npServerChan "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/serverchan"
|
||||||
notifierTelegram "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/telegram"
|
npTelegram "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/telegram"
|
||||||
notifierWebhook "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/webhook"
|
npWebhook "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/webhook"
|
||||||
"github.com/usual2970/certimate/internal/pkg/utils/maps"
|
"github.com/usual2970/certimate/internal/pkg/utils/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
func createNotifier(channel string, channelConfig map[string]any) (notifier.Notifier, error) {
|
func createNotifier(channel string, channelConfig map[string]any) (notifier.Notifier, error) {
|
||||||
switch channel {
|
switch channel {
|
||||||
case domain.NotifyChannelEmail:
|
case domain.NotifyChannelEmail:
|
||||||
return notifierEmail.New(¬ifierEmail.EmailNotifierConfig{
|
return npEmail.New(&npEmail.EmailNotifierConfig{
|
||||||
SmtpHost: maps.GetValueAsString(channelConfig, "smtpHost"),
|
SmtpHost: maps.GetValueAsString(channelConfig, "smtpHost"),
|
||||||
SmtpPort: maps.GetValueAsInt32(channelConfig, "smtpPort"),
|
SmtpPort: maps.GetValueAsInt32(channelConfig, "smtpPort"),
|
||||||
SmtpTLS: maps.GetValueOrDefaultAsBool(channelConfig, "smtpTLS", true),
|
SmtpTLS: maps.GetValueOrDefaultAsBool(channelConfig, "smtpTLS", true),
|
||||||
@ -29,34 +29,34 @@ func createNotifier(channel string, channelConfig map[string]any) (notifier.Noti
|
|||||||
})
|
})
|
||||||
|
|
||||||
case domain.NotifyChannelWebhook:
|
case domain.NotifyChannelWebhook:
|
||||||
return notifierWebhook.New(¬ifierWebhook.WebhookNotifierConfig{
|
return npWebhook.New(&npWebhook.WebhookNotifierConfig{
|
||||||
Url: maps.GetValueAsString(channelConfig, "url"),
|
Url: maps.GetValueAsString(channelConfig, "url"),
|
||||||
})
|
})
|
||||||
|
|
||||||
case domain.NotifyChannelDingtalk:
|
case domain.NotifyChannelDingtalk:
|
||||||
return notifierDingTalk.New(¬ifierDingTalk.DingTalkNotifierConfig{
|
return npDingTalk.New(&npDingTalk.DingTalkNotifierConfig{
|
||||||
AccessToken: maps.GetValueAsString(channelConfig, "accessToken"),
|
AccessToken: maps.GetValueAsString(channelConfig, "accessToken"),
|
||||||
Secret: maps.GetValueAsString(channelConfig, "secret"),
|
Secret: maps.GetValueAsString(channelConfig, "secret"),
|
||||||
})
|
})
|
||||||
|
|
||||||
case domain.NotifyChannelLark:
|
case domain.NotifyChannelLark:
|
||||||
return notifierLark.New(¬ifierLark.LarkNotifierConfig{
|
return npLark.New(&npLark.LarkNotifierConfig{
|
||||||
WebhookUrl: maps.GetValueAsString(channelConfig, "webhookUrl"),
|
WebhookUrl: maps.GetValueAsString(channelConfig, "webhookUrl"),
|
||||||
})
|
})
|
||||||
|
|
||||||
case domain.NotifyChannelTelegram:
|
case domain.NotifyChannelTelegram:
|
||||||
return notifierTelegram.New(¬ifierTelegram.TelegramNotifierConfig{
|
return npTelegram.New(&npTelegram.TelegramNotifierConfig{
|
||||||
ApiToken: maps.GetValueAsString(channelConfig, "apiToken"),
|
ApiToken: maps.GetValueAsString(channelConfig, "apiToken"),
|
||||||
ChatId: maps.GetValueAsInt64(channelConfig, "chatId"),
|
ChatId: maps.GetValueAsInt64(channelConfig, "chatId"),
|
||||||
})
|
})
|
||||||
|
|
||||||
case domain.NotifyChannelServerChan:
|
case domain.NotifyChannelServerChan:
|
||||||
return notifierServerChan.New(¬ifierServerChan.ServerChanNotifierConfig{
|
return npServerChan.New(&npServerChan.ServerChanNotifierConfig{
|
||||||
Url: maps.GetValueAsString(channelConfig, "url"),
|
Url: maps.GetValueAsString(channelConfig, "url"),
|
||||||
})
|
})
|
||||||
|
|
||||||
case domain.NotifyChannelBark:
|
case domain.NotifyChannelBark:
|
||||||
return notifierBark.New(¬ifierBark.BarkNotifierConfig{
|
return npBark.New(&npBark.BarkNotifierConfig{
|
||||||
DeviceKey: maps.GetValueAsString(channelConfig, "deviceKey"),
|
DeviceKey: maps.GetValueAsString(channelConfig, "deviceKey"),
|
||||||
ServerUrl: maps.GetValueAsString(channelConfig, "serverUrl"),
|
ServerUrl: maps.GetValueAsString(channelConfig, "serverUrl"),
|
||||||
})
|
})
|
||||||
|
119
internal/pkg/core/deployer/providers/local/local_test.go
Normal file
119
internal/pkg/core/deployer/providers/local/local_test.go
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
package local_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
dLocal "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/local"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
Shell command to run this test:
|
||||||
|
|
||||||
|
CERTIMATE_DEPLOYER_LOCAL_INPUTCERTPATH="/path/to/your-input-cert.pem" \
|
||||||
|
CERTIMATE_DEPLOYER_LOCAL_INPUTKEYPATH="/path/to/your-input-key.pem" \
|
||||||
|
CERTIMATE_DEPLOYER_LOCAL_OUTPUTCERTPATH="/path/to/your-output-cert.pem" \
|
||||||
|
CERTIMATE_DEPLOYER_LOCAL_OUTPUTKEYPATH="/path/to/your-output-key.pem" \
|
||||||
|
go test -v -run TestDeploy local_test.go
|
||||||
|
*/
|
||||||
|
func TestDeploy(t *testing.T) {
|
||||||
|
envPrefix := "CERTIMATE_DEPLOYER_LOCAL_"
|
||||||
|
tInputCertData, _ := os.ReadFile(os.Getenv(envPrefix + "INPUTCERTPATH"))
|
||||||
|
tInputKeyData, _ := os.ReadFile(os.Getenv(envPrefix + "INPUTKEYPATH"))
|
||||||
|
tOutputCertPath := os.Getenv(envPrefix + "OUTPUTCERTPATH")
|
||||||
|
tOutputKeyPath := os.Getenv(envPrefix + "OUTPUTKEYPATH")
|
||||||
|
|
||||||
|
deployer, err := dLocal.New(&dLocal.LocalDeployerConfig{
|
||||||
|
OutputCertPath: tOutputCertPath,
|
||||||
|
OutputKeyPath: tOutputKeyPath,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := deployer.Deploy(context.Background(), string(tInputCertData), string(tInputKeyData))
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("ok: %v", res)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Shell command to run this test:
|
||||||
|
|
||||||
|
CERTIMATE_DEPLOYER_LOCAL_INPUTCERTPATH="/path/to/your-input-cert.pem" \
|
||||||
|
CERTIMATE_DEPLOYER_LOCAL_INPUTKEYPATH="/path/to/your-input-key.pem" \
|
||||||
|
CERTIMATE_DEPLOYER_LOCAL_OUTPUTCERTPATH="/path/to/your-output-cert.pem" \
|
||||||
|
CERTIMATE_DEPLOYER_LOCAL_PFXPASSWORD="your-pfx-password" \
|
||||||
|
go test -v -run TestDeploy_PFX local_test.go
|
||||||
|
*/
|
||||||
|
func TestDeploy_PFX(t *testing.T) {
|
||||||
|
envPrefix := "CERTIMATE_DEPLOYER_LOCAL_"
|
||||||
|
tInputCertData, _ := os.ReadFile(os.Getenv(envPrefix + "INPUTCERTPATH"))
|
||||||
|
tInputKeyData, _ := os.ReadFile(os.Getenv(envPrefix + "INPUTKEYPATH"))
|
||||||
|
tOutputCertPath := os.Getenv(envPrefix + "OUTPUTCERTPATH")
|
||||||
|
tPfxPassword := os.Getenv(envPrefix + "PFXPASSWORD")
|
||||||
|
|
||||||
|
deployer, err := dLocal.New(&dLocal.LocalDeployerConfig{
|
||||||
|
OutputFormat: dLocal.OUTPUT_FORMAT_PFX,
|
||||||
|
OutputCertPath: tOutputCertPath,
|
||||||
|
PfxPassword: tPfxPassword,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := deployer.Deploy(context.Background(), string(tInputCertData), string(tInputKeyData))
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("ok: %v", res)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Shell command to run this test:
|
||||||
|
|
||||||
|
CERTIMATE_DEPLOYER_LOCAL_INPUTCERTPATH="/path/to/your-input-cert.pem" \
|
||||||
|
CERTIMATE_DEPLOYER_LOCAL_INPUTKEYPATH="/path/to/your-input-key.pem" \
|
||||||
|
CERTIMATE_DEPLOYER_LOCAL_OUTPUTCERTPATH="/path/to/your-output-cert.pem" \
|
||||||
|
CERTIMATE_DEPLOYER_LOCAL_JKSALIAS="your-jks-alias" \
|
||||||
|
CERTIMATE_DEPLOYER_LOCAL_JKSKEYPASS="your-jks-keypass" \
|
||||||
|
CERTIMATE_DEPLOYER_LOCAL_JKSSTOREPASS="your-jks-storepass" \
|
||||||
|
go test -v -run TestDeploy_JKS local_test.go
|
||||||
|
*/
|
||||||
|
func TestDeploy_JKS(t *testing.T) {
|
||||||
|
envPrefix := "CERTIMATE_DEPLOYER_LOCAL_"
|
||||||
|
tInputCertData, _ := os.ReadFile(os.Getenv(envPrefix + "INPUTCERTPATH"))
|
||||||
|
tInputKeyData, _ := os.ReadFile(os.Getenv(envPrefix + "INPUTKEYPATH"))
|
||||||
|
tOutputCertPath := os.Getenv(envPrefix + "OUTPUTCERTPATH")
|
||||||
|
tJksAlias := os.Getenv(envPrefix + "JKSALIAS")
|
||||||
|
tJksKeypass := os.Getenv(envPrefix + "JKSKEYPASS")
|
||||||
|
tJksStorepass := os.Getenv(envPrefix + "JKSSTOREPASS")
|
||||||
|
|
||||||
|
deployer, err := dLocal.New(&dLocal.LocalDeployerConfig{
|
||||||
|
OutputFormat: dLocal.OUTPUT_FORMAT_JKS,
|
||||||
|
OutputCertPath: tOutputCertPath,
|
||||||
|
JksAlias: tJksAlias,
|
||||||
|
JksKeypass: tJksKeypass,
|
||||||
|
JksStorepass: tJksStorepass,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := deployer.Deploy(context.Background(), string(tInputCertData), string(tInputKeyData))
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("ok: %v", res)
|
||||||
|
}
|
56
internal/pkg/core/deployer/providers/ssh/ssh_test.go
Normal file
56
internal/pkg/core/deployer/providers/ssh/ssh_test.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package ssh_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
dSsh "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/ssh"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
Shell command to run this test:
|
||||||
|
|
||||||
|
CERTIMATE_DEPLOYER_SSH_INPUTCERTPATH="/path/to/your-input-cert.pem" \
|
||||||
|
CERTIMATE_DEPLOYER_SSH_INPUTKEYPATH="/path/to/your-input-key.pem" \
|
||||||
|
CERTIMATE_DEPLOYER_SSH_SSHHOST="localhost" \
|
||||||
|
CERTIMATE_DEPLOYER_SSH_SSHPORT=22 \
|
||||||
|
CERTIMATE_DEPLOYER_SSH_SSHUSERNAME="root" \
|
||||||
|
CERTIMATE_DEPLOYER_SSH_SSHPASSWORD="password" \
|
||||||
|
CERTIMATE_DEPLOYER_SSH_OUTPUTCERTPATH="/path/to/your-output-cert.pem" \
|
||||||
|
CERTIMATE_DEPLOYER_SSH_OUTPUTKEYPATH="/path/to/your-output-key.pem" \
|
||||||
|
go test -v -run TestDeploy ssh_test.go
|
||||||
|
*/
|
||||||
|
func TestDeploy(t *testing.T) {
|
||||||
|
envPrefix := "CERTIMATE_DEPLOYER_LOCAL_"
|
||||||
|
tInputCertData, _ := os.ReadFile(os.Getenv(envPrefix + "INPUTCERTPATH"))
|
||||||
|
tInputKeyData, _ := os.ReadFile(os.Getenv(envPrefix + "INPUTKEYPATH"))
|
||||||
|
tSshHost := os.Getenv(envPrefix + "SSHHOST")
|
||||||
|
tSshPort, _ := strconv.ParseInt(os.Getenv(envPrefix+"SSHPORT"), 10, 32)
|
||||||
|
tSshUsername := os.Getenv(envPrefix + "SSHUSERNAME")
|
||||||
|
tSshPassword := os.Getenv(envPrefix + "SSHPASSWORD")
|
||||||
|
tOutputCertPath := os.Getenv(envPrefix + "OUTPUTCERTPATH")
|
||||||
|
tOutputKeyPath := os.Getenv(envPrefix + "OUTPUTKEYPATH")
|
||||||
|
|
||||||
|
deployer, err := dSsh.New(&dSsh.SshDeployerConfig{
|
||||||
|
SshHost: tSshHost,
|
||||||
|
SshPort: int32(tSshPort),
|
||||||
|
SshUsername: tSshUsername,
|
||||||
|
SshPassword: tSshPassword,
|
||||||
|
OutputCertPath: tOutputCertPath,
|
||||||
|
OutputKeyPath: tOutputKeyPath,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := deployer.Deploy(context.Background(), string(tInputCertData), string(tInputKeyData))
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("ok: %v", res)
|
||||||
|
}
|
@ -77,5 +77,9 @@ func (d *WebhookDeployer) Deploy(ctx context.Context, certPem string, privkeyPem
|
|||||||
|
|
||||||
d.logger.Appendt("Webhook Response", string(resp))
|
d.logger.Appendt("Webhook Response", string(resp))
|
||||||
|
|
||||||
return &deployer.DeployResult{}, nil
|
return &deployer.DeployResult{
|
||||||
|
DeploymentData: map[string]any{
|
||||||
|
"responseText": string(resp),
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
40
internal/pkg/core/deployer/providers/webhook/webhook_test.go
Normal file
40
internal/pkg/core/deployer/providers/webhook/webhook_test.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package webhook_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
dpWebhook "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/webhook"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
Shell command to run this test:
|
||||||
|
|
||||||
|
CERTIMATE_DEPLOYER_WEBHOOK_INPUTCERTPATH="/path/to/your-input-cert.pem" \
|
||||||
|
CERTIMATE_DEPLOYER_WEBHOOK_INPUTKEYPATH="/path/to/your-input-key.pem" \
|
||||||
|
CERTIMATE_DEPLOYER_WEBHOOK_URL="https://example.com/your-webhook-url" \
|
||||||
|
go test -v -run TestDeploy webhook_test.go
|
||||||
|
*/
|
||||||
|
func TestDeploy(t *testing.T) {
|
||||||
|
envPrefix := "CERTIMATE_DEPLOYER_WEBHOOK_"
|
||||||
|
tInputCertData, _ := os.ReadFile(os.Getenv(envPrefix + "INPUTCERTPATH"))
|
||||||
|
tInputKeyData, _ := os.ReadFile(os.Getenv(envPrefix + "INPUTKEYPATH"))
|
||||||
|
tUrl := os.Getenv(envPrefix + "URL")
|
||||||
|
|
||||||
|
deployer, err := dpWebhook.New(&dpWebhook.WebhookDeployerConfig{
|
||||||
|
Url: tUrl,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := deployer.Deploy(context.Background(), string(tInputCertData), string(tInputKeyData))
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("ok: %v", res)
|
||||||
|
}
|
@ -1,19 +1,25 @@
|
|||||||
package email_test
|
package email_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
notifierEmail "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/email"
|
npEmail "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/email"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
MockSubject = "test_subject"
|
||||||
|
MockMessage = "test_message"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Shell command to run this test:
|
Shell command to run this test:
|
||||||
|
|
||||||
|
CERTIMATE_NOTIFIER_EMAIL_SMTPHOST="smtp.example.com" \
|
||||||
CERTIMATE_NOTIFIER_EMAIL_SMTPPORT=465 \
|
CERTIMATE_NOTIFIER_EMAIL_SMTPPORT=465 \
|
||||||
CERTIMATE_NOTIFIER_EMAIL_SMTPTLS=true \
|
CERTIMATE_NOTIFIER_EMAIL_SMTPTLS=true \
|
||||||
CERTIMATE_NOTIFIER_EMAIL_SMTPHOST="smtp.example.com" \
|
|
||||||
CERTIMATE_NOTIFIER_EMAIL_USERNAME="your-username" \
|
CERTIMATE_NOTIFIER_EMAIL_USERNAME="your-username" \
|
||||||
CERTIMATE_NOTIFIER_EMAIL_PASSWORD="your-password" \
|
CERTIMATE_NOTIFIER_EMAIL_PASSWORD="your-password" \
|
||||||
CERTIMATE_NOTIFIER_EMAIL_SENDERADDRESS="sender@example.com" \
|
CERTIMATE_NOTIFIER_EMAIL_SENDERADDRESS="sender@example.com" \
|
||||||
@ -21,31 +27,34 @@ Shell command to run this test:
|
|||||||
go test -v -run TestNotify email_test.go
|
go test -v -run TestNotify email_test.go
|
||||||
*/
|
*/
|
||||||
func TestNotify(t *testing.T) {
|
func TestNotify(t *testing.T) {
|
||||||
smtpPort, err := strconv.ParseInt(os.Getenv("CERTIMATE_NOTIFIER_EMAIL_SMTPPORT"), 10, 32)
|
envPrefix := "CERTIMATE_NOTIFIER_EMAIL_"
|
||||||
if err != nil {
|
tSmtpHost := os.Getenv(envPrefix + "SMTPHOST")
|
||||||
t.Errorf("invalid envvar: %+v", err)
|
tSmtpPort, _ := strconv.ParseInt(os.Getenv(envPrefix+"SMTPPORT"), 10, 32)
|
||||||
panic(err)
|
tSmtpTLS, _ := strconv.ParseBool(os.Getenv(envPrefix + "SMTPTLS"))
|
||||||
}
|
tSmtpUsername := os.Getenv(envPrefix + "USERNAME")
|
||||||
|
tSmtpPassword := os.Getenv(envPrefix + "PASSWORD")
|
||||||
|
tSenderAddress := os.Getenv(envPrefix + "SENDERADDRESS")
|
||||||
|
tReceiverAddress := os.Getenv(envPrefix + "RECEIVERADDRESS")
|
||||||
|
|
||||||
smtpTLS, err := strconv.ParseBool(os.Getenv("CERTIMATE_NOTIFIER_EMAIL_SMTPTLS"))
|
notifier, err := npEmail.New(&npEmail.EmailNotifierConfig{
|
||||||
if err != nil {
|
SmtpHost: tSmtpHost,
|
||||||
t.Errorf("invalid envvar: %+v", err)
|
SmtpPort: int32(tSmtpPort),
|
||||||
panic(err)
|
SmtpTLS: tSmtpTLS,
|
||||||
}
|
Username: tSmtpUsername,
|
||||||
|
Password: tSmtpPassword,
|
||||||
res, err := notifierEmail.New(¬ifierEmail.EmailNotifierConfig{
|
SenderAddress: tSenderAddress,
|
||||||
SmtpHost: os.Getenv("CERTIMATE_NOTIFIER_EMAIL_SMTPHOST"),
|
ReceiverAddress: tReceiverAddress,
|
||||||
SmtpPort: int32(smtpPort),
|
|
||||||
SmtpTLS: smtpTLS,
|
|
||||||
Username: os.Getenv("CERTIMATE_NOTIFIER_EMAIL_USERNAME"),
|
|
||||||
Password: os.Getenv("CERTIMATE_NOTIFIER_EMAIL_PASSWORD"),
|
|
||||||
SenderAddress: os.Getenv("CERTIMATE_NOTIFIER_EMAIL_SENDERADDRESS"),
|
|
||||||
ReceiverAddress: os.Getenv("CERTIMATE_NOTIFIER_EMAIL_RECEIVERADDRESS"),
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("invalid envvar: %+v", err)
|
t.Errorf("err: %+v", err)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("notify result: %v", res)
|
res, err := notifier.Notify(context.Background(), MockSubject, MockMessage)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("ok: %v", res)
|
||||||
}
|
}
|
||||||
|
41
internal/pkg/core/notifier/providers/webhook/webhook_test.go
Normal file
41
internal/pkg/core/notifier/providers/webhook/webhook_test.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package webhook_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
npWebhook "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/webhook"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
MockSubject = "test_subject"
|
||||||
|
MockMessage = "test_message"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
Shell command to run this test:
|
||||||
|
|
||||||
|
CERTIMATE_NOTIFIER_WEBHOOK_URL="https://example.com/your-webhook-url" \
|
||||||
|
go test -v -run TestNotify webhook_test.go
|
||||||
|
*/
|
||||||
|
func TestNotify(t *testing.T) {
|
||||||
|
envPrefix := "CERTIMATE_NOTIFIER_WEBHOOK_"
|
||||||
|
tUrl := os.Getenv(envPrefix + "URL")
|
||||||
|
|
||||||
|
notifier, err := npWebhook.New(&npWebhook.WebhookNotifierConfig{
|
||||||
|
Url: tUrl,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := notifier.Notify(context.Background(), MockSubject, MockMessage)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("err: %+v", err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("ok: %v", res)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user