Skip to content

Commit bb58df6

Browse files
authored
fix: use input data as the expected values for "CloudEvents to CloudEvents" tests (#55)
* fix: use input data as the expected values for "CloudEvents to CloudEvents" tests As issue #54, this allow modifying the CloudEvent "input" files without breaking the "CloudEvents to CloudEvents" tests. * fix: update validators_test.go
1 parent 34efb45 commit bb58df6

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

client/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (v validator) validateEvents(url string, inputType, outputType events.Event
140140
if err != nil {
141141
return fmt.Errorf("reading output file from function for %q: %v", name, err)
142142
}
143-
if vi := events.ValidateEvent(name, outputType, output); vi != nil {
143+
if vi := events.ValidateEvent(name, inputType, outputType, output); vi != nil {
144144
vis = append(vis, vi)
145145
}
146146
}

events/validators.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,24 @@ func PrintValidationInfos(vis []*ValidationInfo) (string, error) {
6767
}
6868

6969
// ValidateEvent validates that a particular function output matches the expected contents.
70-
func ValidateEvent(name string, t EventType, got []byte) *ValidationInfo {
71-
want := OutputData(name, t)
70+
func ValidateEvent(name string, it EventType, ot EventType, got []byte) *ValidationInfo {
71+
want := OutputData(name, ot)
72+
73+
// If validating CloudEvent to CloudEvent (no event conversions),
74+
// the output data should be exactly the same as the input data.
75+
if it == CloudEvent && ot == CloudEvent {
76+
want = InputData(name, it)
77+
}
78+
7279
if want == nil {
7380
// Include the possibilities in the error.
7481
return &ValidationInfo{
7582
Name: name,
76-
SkippedReason: fmt.Sprintf("no expected output value of type %s", t),
83+
SkippedReason: fmt.Sprintf("no expected output value of type %s", ot),
7784
}
7885
}
7986

80-
switch t {
87+
switch ot {
8188
case LegacyEvent:
8289
return validateLegacyEvent(name, got, want)
8390
case CloudEvent:

events/validators_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ func TestValidateLegacyEvent(t *testing.T) {
2626
t.Fatalf("no legacy event data")
2727
}
2828
// Validate the event output against itself.
29-
if vi := ValidateEvent(testName, LegacyEvent, data); vi.Errs != nil {
29+
if vi := ValidateEvent(testName, LegacyEvent, LegacyEvent, data); vi.Errs != nil {
3030
t.Errorf("validating legacy event: %v", vi.Errs)
3131
}
3232
}
3333

3434
func TestValidateCloudEvent(t *testing.T) {
3535
testName := "firebase-auth"
36-
data := OutputData(testName, CloudEvent)
36+
data := InputData(testName, CloudEvent)
3737
if data == nil {
3838
t.Fatalf("no cloudevent data")
3939
}
4040
// Validate the event output against itself.
41-
if vi := ValidateEvent(testName, CloudEvent, data); vi.Errs != nil {
41+
if vi := ValidateEvent(testName, CloudEvent, CloudEvent, data); vi.Errs != nil {
4242
t.Errorf("validating cloudevent: %v", vi.Errs)
4343
}
4444
}

0 commit comments

Comments
 (0)