forked from letsencrypt/boulder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use custom mocks instead of mocks.StorageAuthority (letsencrypt#7494)
Replace "mocks.StorageAuthority" with "sapb.StorageAuthorityClient" in our test mocks. The improves them by removing implementations of the methods the tests don't actually need, instead of inheriting lots of extraneous methods from the huge and cumbersome mocks.StorageAuthority. This reduces our usage of mocks.StorageAuthority to only the WFE tests (which create one in the frequently-used setup() function), which will make refactoring those mocks in the pursuit of letsencrypt#7476 much easier. Part of letsencrypt#7476
- Loading branch information
1 parent
d2d4f4a
commit 4663b98
Showing
12 changed files
with
404 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package mocks | ||
|
||
import ( | ||
"io" | ||
|
||
"google.golang.org/grpc" | ||
) | ||
|
||
// ServerStreamClient is a mock which satisfies the grpc.ClientStream interface, | ||
// allowing it to be returned by methods where the server returns a stream of | ||
// results. This simple mock will always return zero results. | ||
type ServerStreamClient[T any] struct { | ||
grpc.ClientStream | ||
} | ||
|
||
// Recv immediately returns the EOF error, indicating that the stream is done. | ||
func (c *ServerStreamClient[T]) Recv() (*T, error) { | ||
return nil, io.EOF | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package mocks | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/letsencrypt/boulder/mail" | ||
) | ||
|
||
// Mailer is a mock | ||
type Mailer struct { | ||
sync.Mutex | ||
Messages []MailerMessage | ||
} | ||
|
||
var _ mail.Mailer = &Mailer{} | ||
|
||
// mockMailerConn is a mock that satisfies the mail.Conn interface | ||
type mockMailerConn struct { | ||
parent *Mailer | ||
} | ||
|
||
var _ mail.Conn = &mockMailerConn{} | ||
|
||
// MailerMessage holds the captured emails from SendMail() | ||
type MailerMessage struct { | ||
To string | ||
Subject string | ||
Body string | ||
} | ||
|
||
// Clear removes any previously recorded messages | ||
func (m *Mailer) Clear() { | ||
m.Lock() | ||
defer m.Unlock() | ||
m.Messages = nil | ||
} | ||
|
||
// SendMail is a mock | ||
func (m *mockMailerConn) SendMail(to []string, subject, msg string) error { | ||
m.parent.Lock() | ||
defer m.parent.Unlock() | ||
for _, rcpt := range to { | ||
m.parent.Messages = append(m.parent.Messages, MailerMessage{ | ||
To: rcpt, | ||
Subject: subject, | ||
Body: msg, | ||
}) | ||
} | ||
return nil | ||
} | ||
|
||
// Close is a mock | ||
func (m *mockMailerConn) Close() error { | ||
return nil | ||
} | ||
|
||
// Connect is a mock | ||
func (m *Mailer) Connect() (mail.Conn, error) { | ||
return &mockMailerConn{parent: m}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package mocks | ||
|
||
import ( | ||
"context" | ||
|
||
"google.golang.org/grpc" | ||
|
||
pubpb "github.com/letsencrypt/boulder/publisher/proto" | ||
) | ||
|
||
// PublisherClient is a mock | ||
type PublisherClient struct { | ||
// empty | ||
} | ||
|
||
// SubmitToSingleCTWithResult is a mock | ||
func (*PublisherClient) SubmitToSingleCTWithResult(_ context.Context, _ *pubpb.Request, _ ...grpc.CallOption) (*pubpb.Result, error) { | ||
return &pubpb.Result{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.