File: batches_test.go

package info (click to toggle)
golang-github-packethost-packngo 0.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 440 kB
  • sloc: makefile: 2
file content (69 lines) | stat: -rw-r--r-- 1,212 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package packngo

import (
	"testing"
	"time"
)

func TestAccInstanceBatches(t *testing.T) {
	skipUnlessAcceptanceTestsAllowed(t)

	c, projectID, teardown := setupWithProject(t)
	defer teardown()

	req := &BatchCreateRequest{
		Batches: []BatchCreateDevice{
			{
				DeviceCreateRequest: DeviceCreateRequest{
					Hostname:     "test1",
					Plan:         "baremetal_0",
					OS:           "ubuntu_16_04",
					Facility:     []string{"ewr1"},
					BillingCycle: "hourly",
					Tags:         []string{"abc"},
				},
				Quantity: 3,
			},
		},
	}

	batches, _, err := c.Batches.Create(projectID, req)
	if err != nil {
		t.Fatal(err)
	}

	var batchID string
	if len(batches) != 0 {
		batchID = batches[0].ID
	}

	batches, _, err = c.Batches.List(projectID, nil)

	if err != nil {
		t.Fatal(err)
	}

	if batches == nil {
		t.Fatal("No batches have been created")
	}
	time.Sleep(5 * time.Second)
	batch, _, err := c.Batches.Get(batchID, &GetOptions{Includes: []string{"devices"}})

	if err != nil {
		t.Fatal(err)
	}

	if batch == nil {
		t.Fatal("Batch not found")
	}

	for _, d := range batch.Devices {
		waitDeviceActive(d.ID, c)
	}

	_, err = c.Batches.Delete(batchID, true)

	if err != nil {
		t.Fatal(err)
	}
}