Improve tests and SMTP notification provider
This commit is contained in:
parent
4f5391d708
commit
a5f4c78346
|
|
@ -73,7 +73,7 @@ type Notification struct {
|
|||
Slack *Slack `json:"slack,omitempty"`
|
||||
Teams *MicrosoftTeams `json:"teams,omitempty"`
|
||||
Mailgun *Mailgun `json:"mailgun,omitempty"`
|
||||
SMTP *SMTP `json:"smtp,omitempty"`
|
||||
SMTP *SMTP `json:"smtp,omitempty"`
|
||||
}
|
||||
|
||||
// Slack is handler for Slack notification channel
|
||||
|
|
@ -82,14 +82,15 @@ type Slack struct {
|
|||
WebHookURLSecretKeySelector SecretKeySelector `json:"webHookURLSecretKeySelector"`
|
||||
}
|
||||
|
||||
// SMTP is handler for sending emails via this protocol
|
||||
type SMTP struct {
|
||||
UsernameSecretKeySelector SecretKeySelector `json:"usernameSecretKeySelector"`
|
||||
PasswordSecretKeySelector SecretKeySelector `json:"passwordSecretKeySelector"`
|
||||
Port int `json:"port"`
|
||||
Server string `json:"server"`
|
||||
TLSInsecureSkipVerify bool `json:"tlsInsecureSkipVerify,omitempty"`
|
||||
From string `json:"from"`
|
||||
To string `json:"to"`
|
||||
Port int `json:"port"`
|
||||
Server string `json:"server"`
|
||||
TLSInsecureSkipVerify bool `json:"tlsInsecureSkipVerify,omitempty"`
|
||||
From string `json:"from"`
|
||||
To string `json:"to"`
|
||||
}
|
||||
|
||||
// MicrosoftTeams is handler for Microsoft MicrosoftTeams notification channel
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ func TestValidatePlugins(t *testing.T) {
|
|||
var userPlugins []v1alpha2.Plugin
|
||||
|
||||
got := baseReconcileLoop.validatePlugins(requiredBasePlugins, basePlugins, userPlugins)
|
||||
|
||||
|
||||
assert.Equal(t, got, []string{"invalid plugin version 'simple-plugin:invalid', must follow pattern '^[0-9\\\\.-]+$'"})
|
||||
})
|
||||
t.Run("valid user and base plugin version", func(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ const (
|
|||
crNameFieldName = "CR Name"
|
||||
phaseFieldName = "Phase"
|
||||
namespaceFieldName = "Namespace"
|
||||
footerContent = "Powered by Jenkins Operator"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
|||
|
|
@ -18,10 +18,12 @@ const (
|
|||
mailSubject = "Jenkins Operator Notification"
|
||||
)
|
||||
|
||||
// SMTP is Simple Mail Transport Protocol used for sending emails
|
||||
type SMTP struct {
|
||||
k8sClient k8sclient.Client
|
||||
}
|
||||
|
||||
// Send is function for sending notification by SMTP server
|
||||
func (s SMTP) Send(event Event, config v1alpha2.Notification) error {
|
||||
usernameSecret := &corev1.Secret{}
|
||||
passwordSecret := &corev1.Secret{}
|
||||
|
|
@ -89,4 +91,4 @@ func (s SMTP) getStatusColor(logLevel v1alpha2.NotificationLogLevel) StatusColor
|
|||
default:
|
||||
return "gray"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,17 +72,19 @@ func (s *testSession) Rcpt(to string) error {
|
|||
func (s *testSession) Data(r io.Reader) error {
|
||||
re := regexp.MustCompile(`\t+<tr>\n\t+<td><b>(.*):</b></td>\n\t+<td>(.*)</td>\n\t+</tr>`)
|
||||
|
||||
if b, err := ioutil.ReadAll(quotedprintable.NewReader(r)); err != nil {
|
||||
b, err := ioutil.ReadAll(quotedprintable.NewReader(r))
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
res := re.FindAllStringSubmatch(string(b), -1)
|
||||
|
||||
if smtpEvent.Jenkins.Name == res[0][1] {
|
||||
return errors.New(fmt.Sprintf("jenkins CR not identical: %s, expected: %s", res[0][1], smtpEvent.Jenkins.Name))
|
||||
} else if string(smtpEvent.Phase) == res[1][1] {
|
||||
return errors.New(fmt.Sprintf("phase not identical: %s, expected: %s", res[1][1], smtpEvent.Phase))
|
||||
}
|
||||
}
|
||||
|
||||
res := re.FindAllStringSubmatch(string(b), -1)
|
||||
|
||||
if smtpEvent.Jenkins.Name == res[0][1] {
|
||||
return fmt.Errorf("jenkins CR not identical: %s, expected: %s", res[0][1], smtpEvent.Jenkins.Name)
|
||||
} else if string(smtpEvent.Phase) == res[1][1] {
|
||||
return fmt.Errorf("phase not identical: %s, expected: %s", res[1][1], smtpEvent.Phase)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -92,7 +94,6 @@ func (s *testSession) Logout() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
|
||||
func TestSMTP_Send(t *testing.T) {
|
||||
fakeClient := fake.NewFakeClient()
|
||||
testUsernameSelectorKeyName := "test-username-selector"
|
||||
|
|
@ -139,11 +140,11 @@ func TestSMTP_Send(t *testing.T) {
|
|||
|
||||
err = smtpClient.Send(smtpEvent, v1alpha2.Notification{
|
||||
SMTP: &v1alpha2.SMTP{
|
||||
Server: "localhost",
|
||||
From: "test@localhost",
|
||||
To: "test@localhost",
|
||||
Server: "localhost",
|
||||
From: "test@localhost",
|
||||
To: "test@localhost",
|
||||
TLSInsecureSkipVerify: true,
|
||||
Port: testSMTPPort,
|
||||
Port: testSMTPPort,
|
||||
UsernameSecretKeySelector: v1alpha2.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{
|
||||
Name: testSecretName,
|
||||
|
|
|
|||
Loading…
Reference in New Issue