generated from keptn-sandbox/keptn-service-template-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
eventhandler_test.go
58 lines (46 loc) · 1.41 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"testing"
_ "github.com/keptn/go-utils/pkg/lib"
keptn "github.com/keptn/go-utils/pkg/lib"
"github.com/cloudevents/sdk-go/pkg/cloudevents"
)
/**
* loads a cloud event from the passed test json file and initializes a keptn object with it
*/
func initializeTestObjects(eventFileName string) (*keptn.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())
}
var keptnOptions = keptn.KeptnOpts{}
keptnOptions.UseLocalFileSystem = true
myKeptn, err := keptn.NewKeptn(incomingEvent, keptnOptions)
return myKeptn, incomingEvent, err
}
// Tests the InternalGetSLIEvent Handler
func TestHandleInternalGetSLIEvent(t *testing.T) {
myKeptn, incomingEvent, err := initializeTestObjects("test-events/get-sli.json")
if err != nil {
t.Error(err)
return
}
getSLIEventData := &keptn.InternalGetSLIEventData{}
err = incomingEvent.DataAs(getSLIEventData)
if err != nil {
t.Errorf("Error getting keptn event data")
}
err = HandleInternalGetSLIEvent(myKeptn, *incomingEvent, getSLIEventData)
if err != nil {
t.Errorf("Error: " + err.Error())
}
}