-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved test suite for bindings (#323)
* Changed UpdateAttribute signature to support failures Signed-off-by: Francesco Guardiani <[email protected]> * Changed signature of RunTranscoderTest + made public CopyEventContext Signed-off-by: Francesco Guardiani <[email protected]> * Moved RunTranscoderTest Signed-off-by: Francesco Guardiani <[email protected]> * Fixed wrong stuff in tests Signed-off-by: Francesco Guardiani <[email protected]> * Now MockBinaryMessage and MockStructuredMessage implements BinaryEncoder and StructuredEncoder Signed-off-by: Francesco Guardiani <[email protected]>
- Loading branch information
1 parent
b72bc2a
commit bb1235c
Showing
10 changed files
with
338 additions
and
278 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
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,45 @@ | ||
package test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
cloudevents "github.com/cloudevents/sdk-go" | ||
"github.com/cloudevents/sdk-go/pkg/binding" | ||
) | ||
|
||
type TranscoderTestArgs struct { | ||
Name string | ||
InputMessage binding.Message | ||
WantEvent cloudevents.Event | ||
Transformers []binding.TransformerFactory | ||
} | ||
|
||
func RunTranscoderTests(t *testing.T, ctx context.Context, tests []TranscoderTestArgs) { | ||
for _, tt := range tests { | ||
tt := tt // Don't use range variable inside scope | ||
t.Run(tt.Name, func(t *testing.T) { | ||
|
||
mockStructured := MockStructuredMessage{} | ||
mockBinary := MockBinaryMessage{} | ||
|
||
enc, err := binding.Encode(ctx, tt.InputMessage, &mockStructured, &mockBinary, tt.Transformers) | ||
require.NoError(t, err) | ||
|
||
var e cloudevents.Event | ||
if enc == binding.EncodingStructured { | ||
e, _, err = binding.ToEvent(ctx, &mockStructured) | ||
require.NoError(t, err) | ||
} else if enc == binding.EncodingBinary { | ||
e, _, err = binding.ToEvent(ctx, &mockBinary) | ||
require.NoError(t, err) | ||
} else { | ||
t.Fatalf("Unexpected encoding %v", enc) | ||
} | ||
require.NoError(t, err) | ||
AssertEventEquals(t, tt.WantEvent, e) | ||
}) | ||
} | ||
} |
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.