File: account_events_test.go

package info (click to toggle)
golang-github-linode-linodego 1.55.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,112 kB
  • sloc: makefile: 96; sh: 52; python: 24
file content (48 lines) | stat: -rw-r--r-- 1,395 bytes parent folder | download | duplicates (2)
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
package integration

import (
	"context"
	"testing"

	"github.com/linode/linodego"
)

func TestAccountEvents_List_smoke(t *testing.T) {
	client, instance, teardown, err := setupInstance(t, "fixtures/TestAccountEvents_List", true)
	defer teardown()
	if err != nil {
		t.Error(err)
	}
	configOpts := linodego.InstanceConfigCreateOptions{
		Label: "test-config",
	}
	instanceConfig, err := client.CreateInstanceConfig(context.Background(), instance.ID, configOpts)
	if err != nil {
		t.Error(err)
	}

	f := linodego.Filter{}
	f.AddField(linodego.Eq, "entity.id", instance.ID)
	f.AddField(linodego.Eq, "entity.type", "linode")
	f.AddField(linodego.Eq, "action", "linode_config_create")
	filter, err := f.MarshalJSON()
	if err != nil {
		t.Fatalf("failed to marshal filter: %v", err)
	}
	events, err := client.ListEvents(context.Background(), &linodego.ListOptions{Filter: string(filter)})
	if err != nil {
		t.Errorf("Error getting Events, expected struct, got error %v", err)
	}

	if len(events) == 0 {
		t.Errorf("Expected to see at least one event")
	} else {
		event := events[0]
		assertDateSet(t, event.Created)
		if event.SecondaryEntity == nil {
			t.Errorf("Expected Secondary Entity to be set")
		} else if event.SecondaryEntity.Label != instanceConfig.Label {
			t.Errorf("Expected Secondary Entity label to be '%s', got '%s'", instanceConfig.Label, event.SecondaryEntity.Label)
		}
	}
}