This repository has been archived by the owner on Jun 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
/
main.go
66 lines (53 loc) · 1.64 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"os"
cloudevents "github.com/cloudevents/sdk-go/v2"
"github.com/google/knative-gcp/test/e2e/lib"
"github.com/google/knative-gcp/test/test_images/internal/knockdown"
"github.com/kelseyhightower/envconfig"
)
func main() {
os.Exit(mainWithExitCode())
}
func mainWithExitCode() int {
r := &storageReceiver{}
if err := envconfig.Process("", r); err != nil {
panic(err)
}
fmt.Printf("Type to match: %q.\n", r.Type)
fmt.Printf("Source to match: %q.\n", r.Source)
fmt.Printf("Subject to match: %q.\n", r.Subject)
return knockdown.Main(r.Config, r)
}
type storageReceiver struct {
knockdown.Config
Type string `envconfig:"TYPE" required:"true"`
Source string `envconfig:"SOURCE" required:"true"`
Subject string `envconfig:"SUBJECT" required:"true"`
}
func (r *storageReceiver) Knockdown(event cloudevents.Event) bool {
// Print out event received to log
fmt.Printf("storage target received event\n")
fmt.Printf(event.Context.String())
incorrectAttributes := make(map[string]lib.PropPair)
// Check type
if event.Type() != r.Type {
incorrectAttributes[lib.EventType] = lib.PropPair{Expected: r.Type, Received: event.Type()}
}
// Check source
if event.Source() != r.Source {
incorrectAttributes[lib.EventSource] = lib.PropPair{Expected: r.Source, Received: event.Source()}
}
// Check subject
if event.Subject() != r.Subject {
incorrectAttributes[lib.EventSubject] = lib.PropPair{Expected: r.Subject, Received: event.Subject()}
}
if len(incorrectAttributes) == 0 {
return true
}
for k, v := range incorrectAttributes {
fmt.Println(k, "expected:", v.Expected, "got:", v.Received)
}
return false
}