forked from keptn-sandbox/artillery-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventhandler_test.go
40 lines (32 loc) · 1.08 KB
/
eventhandler_test.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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"github.com/keptn/go-utils/pkg/lib/v0_2_0/fake"
keptn "github.com/keptn/go-utils/pkg/lib/keptn"
keptnv2 "github.com/keptn/go-utils/pkg/lib/v0_2_0"
cloudevents "github.com/cloudevents/sdk-go/v2" // make sure to use v2 cloudevents here
)
/**
* loads a cloud event from the passed test json file and initializes a keptn object with it
*/
func initializeTestObjects(eventFileName string) (*keptnv2.Keptn, *cloudevents.Event, error) {
// load sample event
eventFile, err := ioutil.ReadFile(eventFileName)
if err != nil {
return nil, nil, fmt.Errorf("Cant load %s: %s", eventFileName, err.Error())
}
incomingEvent := &cloudevents.Event{}
err = json.Unmarshal(eventFile, incomingEvent)
if err != nil {
return nil, nil, fmt.Errorf("Error parsing: %s", err.Error())
}
// Add a Fake EventSender to KeptnOptions
var keptnOptions = keptn.KeptnOpts{
EventSender: &fake.EventSender{},
}
keptnOptions.UseLocalFileSystem = true
myKeptn, err := keptnv2.NewKeptn(incomingEvent, keptnOptions)
return myKeptn, incomingEvent, err
}