-
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.
new test and test update for http server
- Loading branch information
Michael Freeman
committed
Oct 6, 2024
1 parent
58ed061
commit f62b486
Showing
2 changed files
with
56 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package eventingest | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/assert" | ||
"go.uber.org/mock/gomock" | ||
"gofr.dev/pkg/gofr" | ||
"google.golang.org/protobuf/types/known/emptypb" | ||
) | ||
|
||
func TestGRPCEventForwarder_ForwardEvent(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mockClient := NewMockServiceClient(ctrl) | ||
forwarder := &GRPCEventForwarder{ | ||
client: mockClient, | ||
} | ||
|
||
ctx := &gofr.Context{} | ||
tenantID := uuid.New() | ||
customerID := uuid.New() | ||
eventData := []byte("test event data") | ||
|
||
expectedRequest := &IngestEventRequest{ | ||
TenantID: tenantID, | ||
CustomerID: customerID, | ||
EventData: eventData, | ||
} | ||
|
||
// Test successful forward | ||
mockClient.EXPECT(). | ||
IngestEvent(gomock.Any(), gomock.Eq(expectedRequest), gomock.Any()). | ||
Return(&emptypb.Empty{}, nil). | ||
Times(1) | ||
|
||
err := forwarder.ForwardEvent(ctx, tenantID, customerID, eventData) | ||
assert.NoError(t, err) | ||
|
||
// Test error case | ||
mockClient.EXPECT(). | ||
IngestEvent(gomock.Any(), gomock.Eq(expectedRequest), gomock.Any()). | ||
Return(nil, assert.AnError). | ||
Times(1) | ||
|
||
err = forwarder.ForwardEvent(ctx, tenantID, customerID, eventData) | ||
assert.Error(t, err) | ||
} |
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