-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_test.go
52 lines (47 loc) · 1.22 KB
/
command_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
package go_system_api
import (
"encoding/json"
"testing"
"time"
)
func TestCommand(t *testing.T) {
// Create an example ProcessingEvent
var eventRaw string = "Test Raw"
timeNow := time.Now()
derived := make(map[string]interface{})
derived["test"] = "test"
derived["test2"] = 40
derived["test3"] = make(map[string]interface{})
derived["test3"].(map[string]interface{})["test4"] = "test4"
var pe = ProcessingEvent{
Commands: CommandList{
QueryId: "Test Command 1",
Commands: []CommandStep{
{CommandName: "Command 1", Args: "args 1", Url: "Url 1"},
{CommandName: "Command 2", Args: "args 2", Url: "Url 2"},
{CommandName: "Command 3", Args: "args 3", Url: "Url 3"},
},
Step: 0,
ErrorUrl: "Error Url",
},
Event: EventData{
Raw: &eventRaw,
IndexTime: &timeNow,
TimeStamp: &timeNow,
EventType: nil,
Category: nil,
Derived: derived,
},
}
jsonData, err := json.Marshal(pe)
if err != nil {
t.Errorf("Error marshalling ProcessingEvent: %s", err)
}
println(string(jsonData))
// Parse the jsonData back into a ProcessingEvent
var pe2 ProcessingEvent
err = json.Unmarshal(jsonData, &pe2)
if err != nil {
t.Errorf("Error unmarshalling ProcessingEvent: %s", err)
}
}