Skip to content

Commit

Permalink
Add mocks with mockery for mqtt
Browse files Browse the repository at this point in the history
Signed-off-by: JeffMboya <[email protected]>
  • Loading branch information
JeffMboya committed Apr 11, 2024
1 parent 76788d3 commit 09dbde5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 20 deletions.
1 change: 1 addition & 0 deletions mqtt/events/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

const streamID = "magistrala.mqtt"

//go:generate mockery --name EventStore --output=../mocks --filename redis.go --quiet --note "Copyright (c) Abstract Machines"
type EventStore interface {
Connect(ctx context.Context, clientID string) error
Disconnect(ctx context.Context, clientID string) error
Expand Down
20 changes: 10 additions & 10 deletions mqtt/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var (
)

func TestAuthConnect(t *testing.T) {
handler, _ := newHandler()
handler, _ := newHandler(t)

cases := []struct {
desc string
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestAuthConnect(t *testing.T) {
}

func TestAuthPublish(t *testing.T) {
handler, auth := newHandler()
handler, auth := newHandler(t)

cases := []struct {
desc string
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestAuthPublish(t *testing.T) {
}

func TestAuthSubscribe(t *testing.T) {
handler, auth := newHandler()
handler, auth := newHandler(t)

cases := []struct {
desc string
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestAuthSubscribe(t *testing.T) {
}

func TestConnect(t *testing.T) {
handler, _ := newHandler()
handler, _ := newHandler(t)
logBuffer.Reset()

cases := []struct {
Expand Down Expand Up @@ -256,7 +256,7 @@ func TestConnect(t *testing.T) {
}

func TestPublish(t *testing.T) {
handler, _ := newHandler()
handler, _ := newHandler(t)
logBuffer.Reset()

malformedSubtopics := topic + "/" + subtopic + "%"
Expand Down Expand Up @@ -335,7 +335,7 @@ func TestPublish(t *testing.T) {
}

func TestSubscribe(t *testing.T) {
handler, _ := newHandler()
handler, _ := newHandler(t)
logBuffer.Reset()

cases := []struct {
Expand Down Expand Up @@ -371,7 +371,7 @@ func TestSubscribe(t *testing.T) {
}

func TestUnsubscribe(t *testing.T) {
handler, _ := newHandler()
handler, _ := newHandler(t)
logBuffer.Reset()

cases := []struct {
Expand Down Expand Up @@ -407,7 +407,7 @@ func TestUnsubscribe(t *testing.T) {
}

func TestDisconnect(t *testing.T) {
handler, _ := newHandler()
handler, _ := newHandler(t)
logBuffer.Reset()

cases := []struct {
Expand Down Expand Up @@ -442,12 +442,12 @@ func TestDisconnect(t *testing.T) {
}
}

func newHandler() (session.Handler, *authmocks.AuthClient) {
func newHandler(t *testing.T) (session.Handler, *authmocks.AuthClient) {
logger, err := mglog.New(&logBuffer, "debug")
if err != nil {
log.Fatalf("failed to create logger: %s", err)
}
auth := new(authmocks.AuthClient)
eventStore := mocks.NewEventStore()
eventStore := mocks.NewEventStore(t)
return mqtt.NewHandler(mocks.NewPublisher(), eventStore, logger, auth), auth
}
62 changes: 52 additions & 10 deletions mqtt/mocks/redis.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 09dbde5

Please sign in to comment.