diff --git a/awsiotdev.go b/awsiotdev.go index af9cea3a..1eb8063e 100644 --- a/awsiotdev.go +++ b/awsiotdev.go @@ -23,12 +23,12 @@ import ( // Device is an AWS IoT device. type Device interface { - mqtt.Client + mqtt.ReconnectClient ThingName() string } type device struct { - mqtt.Client + mqtt.ReconnectClient thingName string } @@ -39,8 +39,8 @@ func New(thingName string, dialer mqtt.Dialer, opts ...mqtt.ReconnectOption) (De return nil, ioterr.New(err, "creating MQTT connection") } return &device{ - Client: cli, - thingName: thingName, + ReconnectClient: cli, + thingName: thingName, }, nil } diff --git a/jobs/jobs_test.go b/jobs/jobs_test.go index ca4b7ef5..66b21060 100644 --- a/jobs/jobs_test.go +++ b/jobs/jobs_test.go @@ -30,8 +30,14 @@ import ( var errPublish = errors.New("publish failure") +type mockClient interface { + mqtt.Client + mqtt.Handler +} + type mockDevice struct { - *mockmqtt.Client + mockClient + mqtt.Retryer } func (d *mockDevice) ThingName() string { @@ -45,7 +51,7 @@ func TestNew(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - cli := &mockDevice{&mockmqtt.Client{ + cli := &mockDevice{mockClient: &mockmqtt.Client{ SubscribeFn: func(ctx context.Context, subs ...mqtt.Subscription) ([]mqtt.Subscription, error) { return nil, errDummy }, @@ -65,7 +71,7 @@ func TestNotify(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - cli := &mockDevice{&mockmqtt.Client{}} + cli := &mockDevice{mockClient: &mockmqtt.Client{}} j, err := New(ctx, cli) if err != nil { t.Fatal(err) @@ -152,7 +158,7 @@ func TestGetPendingJobs(t *testing.T) { var j Jobs cli := &mockDevice{ - Client: &mockmqtt.Client{ + mockClient: &mockmqtt.Client{ PublishFn: func(ctx context.Context, msg *mqtt.Message) error { if testCase.publishFailure { return errPublish @@ -267,7 +273,7 @@ func TestDescribeJob(t *testing.T) { var j Jobs cli := &mockDevice{ - Client: &mockmqtt.Client{ + mockClient: &mockmqtt.Client{ PublishFn: func(ctx context.Context, msg *mqtt.Message) error { if testCase.publishFailure { return errPublish @@ -458,7 +464,7 @@ func TestUpdateJob(t *testing.T) { var j Jobs cli := &mockDevice{ - Client: &mockmqtt.Client{ + mockClient: &mockmqtt.Client{ PublishFn: func(ctx context.Context, msg *mqtt.Message) error { if testCase.publishFailure { return errPublish @@ -530,7 +536,7 @@ func TestHandlers_InvalidResponse(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - cli := &mockDevice{Client: &mockmqtt.Client{}} + cli := &mockDevice{mockClient: &mockmqtt.Client{}} j, err := New(ctx, cli) if err != nil { diff --git a/shadow/shadow_test.go b/shadow/shadow_test.go index 2b81dfac..8659ceca 100644 --- a/shadow/shadow_test.go +++ b/shadow/shadow_test.go @@ -29,8 +29,14 @@ import ( "github.com/seqsense/aws-iot-device-sdk-go/v6/internal/ioterr" ) +type mockClient interface { + mqtt.Client + mqtt.Handler +} + type mockDevice struct { - *mockmqtt.Client + mockClient + mqtt.Retryer } func (d *mockDevice) ThingName() string { @@ -44,7 +50,7 @@ func TestNew(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - cli := &mockDevice{&mockmqtt.Client{ + cli := &mockDevice{mockClient: &mockmqtt.Client{ SubscribeFn: func(ctx context.Context, subs ...mqtt.Subscription) ([]mqtt.Subscription, error) { return nil, errDummy }, @@ -64,7 +70,7 @@ func TestNew(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - cli := &mockDevice{&mockmqtt.Client{}} + cli := &mockDevice{mockClient: &mockmqtt.Client{}} operation := "foo/bar" testCases := map[string]struct { @@ -400,7 +406,7 @@ func TestHandlers_InvalidResponse(t *testing.T) { defer cancel() var cli *mockDevice - cli = &mockDevice{Client: &mockmqtt.Client{}} + cli = &mockDevice{mockClient: &mockmqtt.Client{}} s, err := New(ctx, cli) if err != nil { @@ -432,7 +438,7 @@ func TestOnDelta(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - cli := &mockDevice{&mockmqtt.Client{}} + cli := &mockDevice{mockClient: &mockmqtt.Client{}} s, err := New(ctx, cli) if err != nil { t.Fatal(err) @@ -658,7 +664,7 @@ func TestGet(t *testing.T) { var s Shadow var cli *mockDevice cli = &mockDevice{ - Client: &mockmqtt.Client{ + mockClient: &mockmqtt.Client{ PublishFn: func(ctx context.Context, msg *mqtt.Message) error { req := &simpleRequest{} if err := json.Unmarshal(msg.Payload, req); err != nil { @@ -766,7 +772,7 @@ func TestDesire(t *testing.T) { var s Shadow var cli *mockDevice cli = &mockDevice{ - Client: &mockmqtt.Client{ + mockClient: &mockmqtt.Client{ PublishFn: func(ctx context.Context, msg *mqtt.Message) error { req := &simpleRequest{} if err := json.Unmarshal(msg.Payload, req); err != nil { @@ -873,7 +879,7 @@ func TestReport(t *testing.T) { var s Shadow var cli *mockDevice cli = &mockDevice{ - Client: &mockmqtt.Client{ + mockClient: &mockmqtt.Client{ PublishFn: func(ctx context.Context, msg *mqtt.Message) error { req := &simpleRequest{} if err := json.Unmarshal(msg.Payload, req); err != nil { @@ -952,7 +958,7 @@ func TestDelete(t *testing.T) { var s Shadow var cli *mockDevice cli = &mockDevice{ - Client: &mockmqtt.Client{ + mockClient: &mockmqtt.Client{ PublishFn: func(ctx context.Context, msg *mqtt.Message) error { req := &simpleRequest{} if err := json.Unmarshal(msg.Payload, req); err != nil { diff --git a/tunnel/tunnel_test.go b/tunnel/tunnel_test.go index 17aefb6d..4e02f95b 100644 --- a/tunnel/tunnel_test.go +++ b/tunnel/tunnel_test.go @@ -27,8 +27,14 @@ import ( "github.com/seqsense/aws-iot-device-sdk-go/v6/internal/ioterr" ) +type mockClient interface { + mqtt.Client + mqtt.Handler +} + type mockDevice struct { - *mockmqtt.Client + mockClient + mqtt.Retryer } func (d *mockDevice) ThingName() string { @@ -42,7 +48,7 @@ func TestNew(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - cli := &mockDevice{&mockmqtt.Client{}} + cli := &mockDevice{mockClient: &mockmqtt.Client{}} _, err := New(ctx, cli, map[string]Dialer{}, func(opts *Options) error { return errDummy }) @@ -58,7 +64,7 @@ func TestNew(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - cli := &mockDevice{&mockmqtt.Client{ + cli := &mockDevice{mockClient: &mockmqtt.Client{ SubscribeFn: func(ctx context.Context, subs ...mqtt.Subscription) ([]mqtt.Subscription, error) { return nil, errDummy }, @@ -76,7 +82,7 @@ func TestNew(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - cli := &mockDevice{&mockmqtt.Client{}} + cli := &mockDevice{mockClient: &mockmqtt.Client{}} _, err := New(ctx, cli, map[string]Dialer{}, func(opts *Options) error { opts.TopicFunc = func(operation string) string { return "##" @@ -98,7 +104,7 @@ func TestHandlers(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - cli := &mockDevice{&mockmqtt.Client{}} + cli := &mockDevice{mockClient: &mockmqtt.Client{}} tu, err := New(ctx, cli, map[string]Dialer{}) if err != nil { t.Fatal(err) @@ -156,7 +162,7 @@ func TestHandlers_InvalidResponse(t *testing.T) { defer cancel() var cli *mockDevice - cli = &mockDevice{Client: &mockmqtt.Client{}} + cli = &mockDevice{mockClient: &mockmqtt.Client{}} s, err := New(ctx, cli, map[string]Dialer{}) if err != nil {