Skip to content

Commit

Permalink
Using mocker 1.0.1
Browse files Browse the repository at this point in the history
Signed-off-by: Ulbrich Robert <[email protected]>
  • Loading branch information
robert-ulbrich-mercedes-benz committed Sep 16, 2024
1 parent 64f3333 commit 50ce320
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 331 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ func TestCreateClient(t *testing.T) {
MinVersion: tls.VersionTLS13,
}

smtpClient := notification_mocks.NewSMTPClient(t)
smtpClient.EXPECT().Hello("localhost").Return(nil).Times(1)
smtpClient.EXPECT().Extension("STARTTLS").Return(true, "").Times(1)
smtpClient.EXPECT().StartTLS(&tls.Config{
smtpClient := &notification_mocks.SMTPClient{}
smtpClient.On("Hello", "localhost").Return(nil)
smtpClient.On("Extension", "STARTTLS").Return(true, "")
smtpClient.On("StartTLS", &tls.Config{
InsecureSkipVerify: false,
ServerName: "localhost",
MinVersion: tls.VersionTLS13,
}).Return(nil).Times(1)
smtpClient.EXPECT().Extension("AUTH").Return(true, "").Times(1)
smtpClient.EXPECT().Auth(auth).Return(nil).Times(1)
}).Return(nil)
smtpClient.On("Extension", "AUTH").Return(true, "")
smtpClient.On("Auth", auth).Return(nil)

smtpEmailer := createSMTPEmailer(smtpClient, &tlsConf, &auth, nil)

Expand All @@ -124,7 +124,7 @@ func TestCreateClientErrorCreatingClient(t *testing.T) {
MinVersion: tls.VersionTLS13,
}

smtpClient := notification_mocks.NewSMTPClient(t)
smtpClient := &notification_mocks.SMTPClient{}

smtpEmailer := createSMTPEmailer(smtpClient, &tlsConf, &auth, errors.New("error creating client"))

Expand All @@ -144,8 +144,8 @@ func TestCreateClientErrorHello(t *testing.T) {
MinVersion: tls.VersionTLS13,
}

smtpClient := notification_mocks.NewSMTPClient(t)
smtpClient.EXPECT().Hello("localhost").Return(errors.New("Error with hello")).Times(1)
smtpClient := &notification_mocks.SMTPClient{}
smtpClient.On("Hello", "localhost").Return(errors.New("Error with hello"))

smtpEmailer := createSMTPEmailer(smtpClient, &tlsConf, &auth, nil)

Expand All @@ -165,10 +165,10 @@ func TestCreateClientErrorStartTLS(t *testing.T) {
MinVersion: tls.VersionTLS13,
}

smtpClient := notification_mocks.NewSMTPClient(t)
smtpClient.EXPECT().Hello("localhost").Return(nil).Times(1)
smtpClient.EXPECT().Extension("STARTTLS").Return(true, "").Times(1)
smtpClient.EXPECT().StartTLS(&tls.Config{
smtpClient := &notification_mocks.SMTPClient{}
smtpClient.On("Hello", "localhost").Return(nil).Times(1)
smtpClient.On("Extension", "STARTTLS").Return(true, "").Times(1)
smtpClient.On("StartTLS", &tls.Config{
InsecureSkipVerify: false,
ServerName: "localhost",
MinVersion: tls.VersionTLS13,
Expand All @@ -192,16 +192,16 @@ func TestCreateClientErrorAuth(t *testing.T) {
MinVersion: tls.VersionTLS13,
}

smtpClient := notification_mocks.NewSMTPClient(t)
smtpClient.EXPECT().Hello("localhost").Return(nil).Times(1)
smtpClient.EXPECT().Extension("STARTTLS").Return(true, "").Times(1)
smtpClient.EXPECT().StartTLS(&tls.Config{
smtpClient := &notification_mocks.SMTPClient{}
smtpClient.On("Hello", "localhost").Return(nil).Times(1)
smtpClient.On("Extension", "STARTTLS").Return(true, "").Times(1)
smtpClient.On("StartTLS", &tls.Config{
InsecureSkipVerify: false,
ServerName: "localhost",
MinVersion: tls.VersionTLS13,
}).Return(nil).Times(1)
smtpClient.EXPECT().Extension("AUTH").Return(true, "").Times(1)
smtpClient.EXPECT().Auth(auth).Return(errors.New("Error with hello")).Times(1)
smtpClient.On("Extension", "AUTH").Return(true, "").Times(1)
smtpClient.On("Auth", auth).Return(errors.New("Error with hello")).Times(1)

smtpEmailer := createSMTPEmailer(smtpClient, &tlsConf, &auth, nil)

Expand All @@ -223,22 +223,22 @@ func TestSendMail(t *testing.T) {

stringWriter := StringWriter{buffer: ""}

smtpClient := notification_mocks.NewSMTPClient(t)
smtpClient.EXPECT().Noop().Return(errors.New("no connection")).Times(1)
smtpClient.EXPECT().Close().Return(nil).Times(1)
smtpClient.EXPECT().Hello("localhost").Return(nil).Times(1)
smtpClient.EXPECT().Extension("STARTTLS").Return(true, "").Times(1)
smtpClient.EXPECT().StartTLS(&tls.Config{
smtpClient := &notification_mocks.SMTPClient{}
smtpClient.On("Noop").Return(errors.New("no connection")).Times(1)
smtpClient.On("Close").Return(nil).Times(1)
smtpClient.On("Hello", "localhost").Return(nil).Times(1)
smtpClient.On("Extension", "STARTTLS").Return(true, "").Times(1)
smtpClient.On("StartTLS", &tls.Config{
InsecureSkipVerify: false,
ServerName: "localhost",
MinVersion: tls.VersionTLS13,
}).Return(nil).Times(1)
smtpClient.EXPECT().Extension("AUTH").Return(true, "").Times(1)
smtpClient.EXPECT().Auth(auth).Return(nil).Times(1)
smtpClient.EXPECT().Mail("[email protected]").Return(nil).Times(1)
smtpClient.EXPECT().Rcpt("[email protected]").Return(nil).Times(1)
smtpClient.EXPECT().Rcpt("[email protected]").Return(nil).Times(1)
smtpClient.EXPECT().Data().Return(&stringWriter, nil).Times(1)
smtpClient.On("Extension", "AUTH").Return(true, "").Times(1)
smtpClient.On("Auth", auth).Return(nil).Times(1)
smtpClient.On("Mail", "[email protected]").Return(nil).Times(1)
smtpClient.On("Rcpt", "[email protected]").Return(nil).Times(1)
smtpClient.On("Rcpt", "[email protected]").Return(nil).Times(1)
smtpClient.On("Data").Return(&stringWriter, nil).Times(1)

smtpEmailer := createSMTPEmailer(smtpClient, &tlsConf, &auth, nil)

Expand Down Expand Up @@ -266,10 +266,10 @@ func TestSendMailCreateClientError(t *testing.T) {
MinVersion: tls.VersionTLS13,
}

smtpClient := notification_mocks.NewSMTPClient(t)
smtpClient.EXPECT().Noop().Return(errors.New("no connection")).Times(1)
smtpClient.EXPECT().Close().Return(nil).Times(1)
smtpClient.EXPECT().Hello("localhost").Return(errors.New("error hello")).Times(1)
smtpClient := &notification_mocks.SMTPClient{}
smtpClient.On("Noop").Return(errors.New("no connection")).Times(1)
smtpClient.On("Close").Return(nil).Times(1)
smtpClient.On("Hello", "localhost").Return(errors.New("error hello")).Times(1)

smtpEmailer := createSMTPEmailer(smtpClient, &tlsConf, &auth, nil)

Expand All @@ -292,19 +292,19 @@ func TestSendMailErrorMail(t *testing.T) {
MinVersion: tls.VersionTLS13,
}

smtpClient := notification_mocks.NewSMTPClient(t)
smtpClient.EXPECT().Noop().Return(errors.New("no connection")).Times(1)
smtpClient.EXPECT().Close().Return(nil).Times(1)
smtpClient.EXPECT().Hello("localhost").Return(nil).Times(1)
smtpClient.EXPECT().Extension("STARTTLS").Return(true, "").Times(1)
smtpClient.EXPECT().StartTLS(&tls.Config{
smtpClient := &notification_mocks.SMTPClient{}
smtpClient.On("Noop").Return(errors.New("no connection")).Times(1)
smtpClient.On("Close").Return(nil).Times(1)
smtpClient.On("Hello", "localhost").Return(nil).Times(1)
smtpClient.On("Extension", "STARTTLS").Return(true, "").Times(1)
smtpClient.On("StartTLS", &tls.Config{
InsecureSkipVerify: false,
ServerName: "localhost",
MinVersion: tls.VersionTLS13,
}).Return(nil).Times(1)
smtpClient.EXPECT().Extension("AUTH").Return(true, "").Times(1)
smtpClient.EXPECT().Auth(auth).Return(nil).Times(1)
smtpClient.EXPECT().Mail("[email protected]").Return(errors.New("error sending mail")).Times(1)
smtpClient.On("Extension", "AUTH").Return(true, "").Times(1)
smtpClient.On("Auth", auth).Return(nil).Times(1)
smtpClient.On("Mail", "[email protected]").Return(errors.New("error sending mail")).Times(1)

smtpEmailer := createSMTPEmailer(smtpClient, &tlsConf, &auth, nil)

Expand All @@ -327,20 +327,20 @@ func TestSendMailErrorRecipient(t *testing.T) {
MinVersion: tls.VersionTLS13,
}

smtpClient := notification_mocks.NewSMTPClient(t)
smtpClient.EXPECT().Noop().Return(errors.New("no connection")).Times(1)
smtpClient.EXPECT().Close().Return(nil).Times(1)
smtpClient.EXPECT().Hello("localhost").Return(nil).Times(1)
smtpClient.EXPECT().Extension("STARTTLS").Return(true, "").Times(1)
smtpClient.EXPECT().StartTLS(&tls.Config{
smtpClient := &notification_mocks.SMTPClient{}
smtpClient.On("Noop").Return(errors.New("no connection")).Times(1)
smtpClient.On("Close").Return(nil).Times(1)
smtpClient.On("Hello", "localhost").Return(nil).Times(1)
smtpClient.On("Extension", "STARTTLS").Return(true, "").Times(1)
smtpClient.On("StartTLS", &tls.Config{
InsecureSkipVerify: false,
ServerName: "localhost",
MinVersion: tls.VersionTLS13,
}).Return(nil).Times(1)
smtpClient.EXPECT().Extension("AUTH").Return(true, "").Times(1)
smtpClient.EXPECT().Auth(auth).Return(nil).Times(1)
smtpClient.EXPECT().Mail("[email protected]").Return(nil).Times(1)
smtpClient.EXPECT().Rcpt("[email protected]").Return(errors.New("error adding recipient")).Times(1)
smtpClient.On("Extension", "AUTH").Return(true, "").Times(1)
smtpClient.On("Auth", auth).Return(nil).Times(1)
smtpClient.On("Mail", "[email protected]").Return(nil).Times(1)
smtpClient.On("Rcpt", "[email protected]").Return(errors.New("error adding recipient")).Times(1)

smtpEmailer := createSMTPEmailer(smtpClient, &tlsConf, &auth, nil)

Expand All @@ -363,22 +363,22 @@ func TestSendMailErrorData(t *testing.T) {
MinVersion: tls.VersionTLS13,
}

smtpClient := notification_mocks.NewSMTPClient(t)
smtpClient.EXPECT().Noop().Return(errors.New("no connection")).Times(1)
smtpClient.EXPECT().Close().Return(nil).Times(1)
smtpClient.EXPECT().Hello("localhost").Return(nil).Times(1)
smtpClient.EXPECT().Extension("STARTTLS").Return(true, "").Times(1)
smtpClient.EXPECT().StartTLS(&tls.Config{
smtpClient := &notification_mocks.SMTPClient{}
smtpClient.On("Noop").Return(errors.New("no connection")).Times(1)
smtpClient.On("Close").Return(nil).Times(1)
smtpClient.On("Hello", "localhost").Return(nil).Times(1)
smtpClient.On("Extension", "STARTTLS").Return(true, "").Times(1)
smtpClient.On("StartTLS", &tls.Config{
InsecureSkipVerify: false,
ServerName: "localhost",
MinVersion: tls.VersionTLS13,
}).Return(nil).Times(1)
smtpClient.EXPECT().Extension("AUTH").Return(true, "").Times(1)
smtpClient.EXPECT().Auth(auth).Return(nil).Times(1)
smtpClient.EXPECT().Mail("[email protected]").Return(nil).Times(1)
smtpClient.EXPECT().Rcpt("[email protected]").Return(nil).Times(1)
smtpClient.EXPECT().Rcpt("[email protected]").Return(nil).Times(1)
smtpClient.EXPECT().Data().Return(nil, errors.New("error creating data writer")).Times(1)
smtpClient.On("Extension", "AUTH").Return(true, "").Times(1)
smtpClient.On("Auth", auth).Return(nil).Times(1)
smtpClient.On("Mail", "[email protected]").Return(nil).Times(1)
smtpClient.On("Rcpt", "[email protected]").Return(nil).Times(1)
smtpClient.On("Rcpt", "[email protected]").Return(nil).Times(1)
smtpClient.On("Data").Return(nil, errors.New("error creating data writer")).Times(1)

smtpEmailer := createSMTPEmailer(smtpClient, &tlsConf, &auth, nil)

Expand All @@ -404,22 +404,22 @@ func TestSendMailErrorWriting(t *testing.T) {

stringWriter := StringWriter{buffer: "", writeErr: errors.New("error writing"), closeErr: nil}

smtpClient := notification_mocks.NewSMTPClient(t)
smtpClient.EXPECT().Noop().Return(errors.New("no connection")).Times(1)
smtpClient.EXPECT().Close().Return(nil).Times(1)
smtpClient.EXPECT().Hello("localhost").Return(nil).Times(1)
smtpClient.EXPECT().Extension("STARTTLS").Return(true, "").Times(1)
smtpClient.EXPECT().StartTLS(&tls.Config{
smtpClient := &notification_mocks.SMTPClient{}
smtpClient.On("Noop").Return(errors.New("no connection")).Times(1)
smtpClient.On("Close").Return(nil).Times(1)
smtpClient.On("Hello", "localhost").Return(nil).Times(1)
smtpClient.On("Extension", "STARTTLS").Return(true, "").Times(1)
smtpClient.On("StartTLS", &tls.Config{
InsecureSkipVerify: false,
ServerName: "localhost",
MinVersion: tls.VersionTLS13,
}).Return(nil).Times(1)
smtpClient.EXPECT().Extension("AUTH").Return(true, "").Times(1)
smtpClient.EXPECT().Auth(auth).Return(nil).Times(1)
smtpClient.EXPECT().Mail("[email protected]").Return(nil).Times(1)
smtpClient.EXPECT().Rcpt("[email protected]").Return(nil).Times(1)
smtpClient.EXPECT().Rcpt("[email protected]").Return(nil).Times(1)
smtpClient.EXPECT().Data().Return(&stringWriter, nil).Times(1)
smtpClient.On("Extension", "AUTH").Return(true, "").Times(1)
smtpClient.On("Auth", auth).Return(nil).Times(1)
smtpClient.On("Mail", "[email protected]").Return(nil).Times(1)
smtpClient.On("Rcpt", "[email protected]").Return(nil).Times(1)
smtpClient.On("Rcpt", "[email protected]").Return(nil).Times(1)
smtpClient.On("Data").Return(&stringWriter, nil).Times(1)

smtpEmailer := createSMTPEmailer(smtpClient, &tlsConf, &auth, nil)

Expand All @@ -445,22 +445,22 @@ func TestSendMailErrorClose(t *testing.T) {

stringWriter := StringWriter{buffer: "", writeErr: nil, closeErr: errors.New("error writing")}

smtpClient := notification_mocks.NewSMTPClient(t)
smtpClient.EXPECT().Noop().Return(errors.New("no connection")).Times(1)
smtpClient.EXPECT().Close().Return(nil).Times(1)
smtpClient.EXPECT().Hello("localhost").Return(nil).Times(1)
smtpClient.EXPECT().Extension("STARTTLS").Return(true, "").Times(1)
smtpClient.EXPECT().StartTLS(&tls.Config{
smtpClient := &notification_mocks.SMTPClient{}
smtpClient.On("Noop").Return(errors.New("no connection")).Times(1)
smtpClient.On("Close").Return(nil).Times(1)
smtpClient.On("Hello", "localhost").Return(nil).Times(1)
smtpClient.On("Extension", "STARTTLS").Return(true, "").Times(1)
smtpClient.On("StartTLS", &tls.Config{
InsecureSkipVerify: false,
ServerName: "localhost",
MinVersion: tls.VersionTLS13,
}).Return(nil).Times(1)
smtpClient.EXPECT().Extension("AUTH").Return(true, "").Times(1)
smtpClient.EXPECT().Auth(auth).Return(nil).Times(1)
smtpClient.EXPECT().Mail("[email protected]").Return(nil).Times(1)
smtpClient.EXPECT().Rcpt("[email protected]").Return(nil).Times(1)
smtpClient.EXPECT().Rcpt("[email protected]").Return(nil).Times(1)
smtpClient.EXPECT().Data().Return(&stringWriter, nil).Times(1)
smtpClient.On("Extension", "AUTH").Return(true, "").Times(1)
smtpClient.On("Auth", auth).Return(nil).Times(1)
smtpClient.On("Mail", "[email protected]").Return(nil).Times(1)
smtpClient.On("Rcpt", "[email protected]").Return(nil).Times(1)
smtpClient.On("Rcpt", "[email protected]").Return(nil).Times(1)
smtpClient.On("Data").Return(&stringWriter, nil).Times(1)

smtpEmailer := createSMTPEmailer(smtpClient, &tlsConf, &auth, nil)

Expand Down
Loading

0 comments on commit 50ce320

Please sign in to comment.