diff --git a/internal/circuitgentest/circuittest/gen_test.go b/internal/circuitgentest/circuittest/gen_test.go index 019c50c..01ecf9b 100644 --- a/internal/circuitgentest/circuittest/gen_test.go +++ b/internal/circuitgentest/circuittest/gen_test.go @@ -19,13 +19,13 @@ import ( "testing" "time" - "github.com/twitchtv/circuitgen/internal/circuitgentest" - "github.com/twitchtv/circuitgen/internal/circuitgentest/model" - "github.com/twitchtv/circuitgen/internal/circuitgentest/rep" "github.com/cep21/circuit" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + "github.com/twitchtv/circuitgen/internal/circuitgentest" + "github.com/twitchtv/circuitgen/internal/circuitgentest/model" + "github.com/twitchtv/circuitgen/internal/circuitgentest/rep" ) // Test generated clients @@ -50,7 +50,7 @@ func TestPublisherInterface(t *testing.T) { opt := rep.PublishOption{Sample: 0.1} opt2 := rep.PublishOption{Sample: 0.2} - m.On("Publish", mock.Anything, grants, topics, opt, opt2).Return(nil).Once() + m.On("Publish", mock.Anything, grants, topics, opt, opt2).Return(nil, nil).Once() m.On("Close", mock.Anything).Return(nil).Once() @@ -87,7 +87,7 @@ func TestPublisherInterface(t *testing.T) { require.Equal(t, 1*time.Second, manager.GetCircuit("Publisher.PublishWithResult").Config().Execution.Timeout) require.Equal(t, 2*time.Second, manager.GetCircuit("Publisher.Publish").Config().Execution.Timeout) - err = publisher.Publish(ctx, grants, topics, opt, opt2) + _, err = publisher.Publish(ctx, grants, topics, opt, opt2) require.NoError(t, err) res, err := publisher.PublishWithResult(ctx, publishInput) @@ -109,7 +109,7 @@ func TestPublisherInterfaceErrors(t *testing.T) { testError := errors.New("test error") m := &circuitgentest.MockPublisher{} - m.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(testError).Once() + m.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil, testError).Once() publishCounter := &runMetricsCounter{} publisher, err := NewCircuitWrapperPublisher(manager, m, CircuitWrapperPublisherConfig{ @@ -123,7 +123,7 @@ func TestPublisherInterfaceErrors(t *testing.T) { require.NotNil(t, publisher) ctx := context.Background() - err = publisher.Publish(ctx, map[circuitgentest.Seed][][]circuitgentest.Grant{}, circuitgentest.TopicsList{}) + _, err = publisher.Publish(ctx, map[circuitgentest.Seed][][]circuitgentest.Grant{}, circuitgentest.TopicsList{}) require.Equal(t, testError, err) // Check embedded called @@ -138,7 +138,7 @@ func TestPublisherInterfaceBadRequest(t *testing.T) { testError := errors.New("bad request error") m := &circuitgentest.MockPublisher{} - m.On("Publish", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(testError).Once() + m.On("Publish", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, testError).Once() publishCounter := &runMetricsCounter{} publisher, err := NewCircuitWrapperPublisher(manager, m, CircuitWrapperPublisherConfig{ @@ -155,7 +155,7 @@ func TestPublisherInterfaceBadRequest(t *testing.T) { require.NotNil(t, publisher) ctx := context.Background() - err = publisher.Publish(ctx, map[circuitgentest.Seed][][]circuitgentest.Grant{}, circuitgentest.TopicsList{}) + _, err = publisher.Publish(ctx, map[circuitgentest.Seed][][]circuitgentest.Grant{}, circuitgentest.TopicsList{}) require.Equal(t, testError, err) // Check embedded called @@ -171,7 +171,7 @@ func TestPubsubInterface(t *testing.T) { m := &circuitgentest.MockPublisher{} m.On("PublishWithResult", mock.Anything, mock.Anything).Return(nil, nil).Once() - m.On("Publish", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once() + m.On("Publish", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil).Once() m.On("Close", mock.Anything).Return(nil).Once() pubsub, err := NewCircuitWrapperPubsub(manager, m, CircuitWrapperPubsubConfig{}) @@ -184,7 +184,7 @@ func TestPubsubInterface(t *testing.T) { require.Contains(t, names, "Pubsub.Publish") ctx := context.Background() - err = pubsub.Publish(ctx, map[circuitgentest.Seed][][]circuitgentest.Grant{}, circuitgentest.TopicsList{}) + _, err = pubsub.Publish(ctx, map[circuitgentest.Seed][][]circuitgentest.Grant{}, circuitgentest.TopicsList{}) require.NoError(t, err) _, err = pubsub.PublishWithResult(ctx, rep.PublishInput{}) diff --git a/internal/circuitgentest/circuittest/publisher.gen.go b/internal/circuitgentest/circuittest/publisher.gen.go index b3646e2..691bfe2 100644 --- a/internal/circuitgentest/circuittest/publisher.gen.go +++ b/internal/circuitgentest/circuittest/publisher.gen.go @@ -74,9 +74,11 @@ func NewCircuitWrapperPublisher( } // Publish calls the embedded circuitgentest.Publisher's method Publish with CircuitPublish -func (w *CircuitWrapperPublisher) Publish(ctx context.Context, p1 map[circuitgentest.Seed][][]circuitgentest.Grant, p2 circuitgentest.TopicsList, p3 ...rep.PublishOption) error { +func (w *CircuitWrapperPublisher) Publish(ctx context.Context, p1 map[circuitgentest.Seed][][]circuitgentest.Grant, p2 circuitgentest.TopicsList, p3 ...rep.PublishOption) (map[string]struct{}, error) { + var r0 map[string]struct{} err := w.CircuitPublish.Run(ctx, func(ctx context.Context) error { - err := w.Publisher.Publish(ctx, p1, p2, p3...) + var err error + r0, err = w.Publisher.Publish(ctx, p1, p2, p3...) if w.IsBadRequest(err) { return &circuit.SimpleBadRequest{Err: err} @@ -88,7 +90,7 @@ func (w *CircuitWrapperPublisher) Publish(ctx context.Context, p1 map[circuitgen err = berr.Err } - return err + return r0, err } // PublishWithResult calls the embedded circuitgentest.Publisher's method PublishWithResult with CircuitPublishWithResult diff --git a/internal/circuitgentest/circuittest/pubsub.gen.go b/internal/circuitgentest/circuittest/pubsub.gen.go index 17072cc..8771622 100644 --- a/internal/circuitgentest/circuittest/pubsub.gen.go +++ b/internal/circuitgentest/circuittest/pubsub.gen.go @@ -74,9 +74,11 @@ func NewCircuitWrapperPubsub( } // Publish calls the embedded circuitgentest.Publisher's method Publish with CircuitPublish -func (w *CircuitWrapperPubsub) Publish(ctx context.Context, p1 map[circuitgentest.Seed][][]circuitgentest.Grant, p2 circuitgentest.TopicsList, p3 ...rep.PublishOption) error { +func (w *CircuitWrapperPubsub) Publish(ctx context.Context, p1 map[circuitgentest.Seed][][]circuitgentest.Grant, p2 circuitgentest.TopicsList, p3 ...rep.PublishOption) (map[string]struct{}, error) { + var r0 map[string]struct{} err := w.CircuitPublish.Run(ctx, func(ctx context.Context) error { - err := w.Publisher.Publish(ctx, p1, p2, p3...) + var err error + r0, err = w.Publisher.Publish(ctx, p1, p2, p3...) if w.IsBadRequest(err) { return &circuit.SimpleBadRequest{Err: err} @@ -88,7 +90,7 @@ func (w *CircuitWrapperPubsub) Publish(ctx context.Context, p1 map[circuitgentes err = berr.Err } - return err + return r0, err } // PublishWithResult calls the embedded circuitgentest.Publisher's method PublishWithResult with CircuitPublishWithResult diff --git a/internal/circuitgentest/publisher.gen.go b/internal/circuitgentest/publisher.gen.go index fe584f6..3eee51b 100644 --- a/internal/circuitgentest/publisher.gen.go +++ b/internal/circuitgentest/publisher.gen.go @@ -73,9 +73,11 @@ func NewCircuitWrapperPublisher( } // Publish calls the embedded Publisher's method Publish with CircuitPublish -func (w *CircuitWrapperPublisher) Publish(ctx context.Context, p1 map[Seed][][]Grant, p2 TopicsList, p3 ...rep.PublishOption) error { +func (w *CircuitWrapperPublisher) Publish(ctx context.Context, p1 map[Seed][][]Grant, p2 TopicsList, p3 ...rep.PublishOption) (map[string]struct{}, error) { + var r0 map[string]struct{} err := w.CircuitPublish.Run(ctx, func(ctx context.Context) error { - err := w.Publisher.Publish(ctx, p1, p2, p3...) + var err error + r0, err = w.Publisher.Publish(ctx, p1, p2, p3...) if w.IsBadRequest(err) { return &circuit.SimpleBadRequest{Err: err} @@ -87,7 +89,7 @@ func (w *CircuitWrapperPublisher) Publish(ctx context.Context, p1 map[Seed][][]G err = berr.Err } - return err + return r0, err } // PublishWithResult calls the embedded Publisher's method PublishWithResult with CircuitPublishWithResult diff --git a/internal/circuitgentest/publisher.go b/internal/circuitgentest/publisher.go index e3cb71a..d63d227 100644 --- a/internal/circuitgentest/publisher.go +++ b/internal/circuitgentest/publisher.go @@ -16,9 +16,9 @@ package circuitgentest import ( "context" + "github.com/stretchr/testify/mock" "github.com/twitchtv/circuitgen/internal/circuitgentest/model" "github.com/twitchtv/circuitgen/internal/circuitgentest/rep" - "github.com/stretchr/testify/mock" ) // TopicsList is a test struct @@ -40,7 +40,7 @@ type Publisher interface { // PublishWithResult is a test method and should be wrapped PublishWithResult(context.Context, rep.PublishInput) (*model.Result, error) // PublishWithResult is a test method and should be wrapped - Publish(context.Context, map[Seed][][]Grant, TopicsList, ...rep.PublishOption) error + Publish(context.Context, map[Seed][][]Grant, TopicsList, ...rep.PublishOption) (map[string]struct{}, error) // PublishWithResult is a test method and should not be wrapped Close() error } @@ -65,7 +65,7 @@ func (m *MockPublisher) PublishWithResult(ctx context.Context, input rep.Publish } // Publish mocks the method -func (m *MockPublisher) Publish(ctx context.Context, g map[Seed][][]Grant, s TopicsList, opts ...rep.PublishOption) error { +func (m *MockPublisher) Publish(ctx context.Context, g map[Seed][][]Grant, s TopicsList, opts ...rep.PublishOption) (map[string]struct{}, error) { var ca []interface{} ca = append(ca, ctx, g, s) va := make([]interface{}, len(opts)) @@ -74,7 +74,17 @@ func (m *MockPublisher) Publish(ctx context.Context, g map[Seed][][]Grant, s Top } ca = append(ca, va...) args := m.Called(ca...) - return args.Error(0) + + var r0 map[string]struct{} + if args.Get(0) != nil { + var ok bool + r0, ok = args.Get(0).(map[string]struct{}) + if !ok { + panic("args.Get(0) is not a map[string]struct{}") + } + } + + return r0, args.Error(1) } // Close mocks the method diff --git a/parsing.go b/parsing.go index 34ab894..e4688b6 100644 --- a/parsing.go +++ b/parsing.go @@ -179,6 +179,7 @@ func resolvePkgPaths(p types.Type) ([]string, error) { } case *types.Basic: case *types.Interface: + case *types.Struct: // struct{} // Break out of the switch and return below default: return nil, fmt.Errorf("resolvePkgPaths: invalid type: %v", t)