File: plans_test.go

package info (click to toggle)
golang-github-vultr-govultr 2.17.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 604 kB
  • sloc: makefile: 2
file content (97 lines) | stat: -rw-r--r-- 2,535 bytes parent folder | download
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package govultr

import (
	"fmt"
	"net/http"
	"reflect"
	"testing"
)

func TestPlanServiceHandler_List(t *testing.T) {
	setup()
	defer teardown()

	mux.HandleFunc("/v2/plans", func(writer http.ResponseWriter, request *http.Request) {
		response := `{ "plans":[{ "id": "vc2-16c-64gb", "vcpu_count": 16, "ram": 65536, "disk": 1280, "disk_count": 1, "bandwidth": 10240, "monthly_cost": 320, "type": "vc2", "locations": [  "dfw"]}], "meta": { "total": 19, "links": { "next": "", "prev": "" } }}`
		fmt.Fprint(writer, response)
	})

	plans, meta, err := client.Plan.List(ctx, "vc2", nil)
	if err != nil {
		t.Errorf("Plan.List returned %+v", err)
	}

	expectedPlan := []Plan{
		{
			ID:          "vc2-16c-64gb",
			VCPUCount:   16,
			RAM:         65536,
			Disk:        1280,
			DiskCount:   1,
			Bandwidth:   10240,
			MonthlyCost: 320.00,
			Type:        "vc2",
			Locations: []string{
				"dfw",
			},
		},
	}

	expectedMeta := &Meta{
		Total: 19,
		Links: &Links{},
	}

	if !reflect.DeepEqual(plans, expectedPlan) {
		t.Errorf("Plan.List  plans returned %+v, expected %+v", plans, expectedPlan)
	}

	if !reflect.DeepEqual(meta, expectedMeta) {
		t.Errorf("Plan.List  meta returned %+v, expected %+v", meta, expectedMeta)
	}
}

func TestPlanServiceHandler_GetBareMetalList(t *testing.T) {
	setup()
	defer teardown()
	mux.HandleFunc("/v2/plans-metal", func(writer http.ResponseWriter, request *http.Request) {
		response := `{ "plans_metal":[{"id": "vbm-4c-32gb","cpu_count": 4,"cpu_threads": 8,"cpu_model": "E3-1270v6","ram": 32768,"disk": 240, "disk_count": 1, "bandwidth": 5120,"monthly_cost": 300,"type": "SSD", "locations": [ "dwf"]}], "meta": { "total": 19, "links": { "next": "", "prev": "" } }}`
		fmt.Fprint(writer, response)
	})

	bareMetalPlans, meta, err := client.Plan.ListBareMetal(ctx, nil)
	if err != nil {
		t.Errorf("Plan.GetBareMetalList returned %+v", err)
	}

	expectedPlan := []BareMetalPlan{
		{
			ID:          "vbm-4c-32gb",
			CPUCount:    4,
			CPUModel:    "E3-1270v6",
			CPUThreads:  8,
			RAM:         32768,
			Disk:        240,
			DiskCount:   1,
			Bandwidth:   5120,
			MonthlyCost: 300,
			Type:        "SSD",
			Locations: []string{
				"dwf",
			},
		},
	}

	expectedMeta := &Meta{
		Total: 19,
		Links: &Links{},
	}

	if !reflect.DeepEqual(bareMetalPlans, expectedPlan) {
		t.Errorf("Plan.GetBareMetalList  returned %+v, expected %+v", bareMetalPlans, expectedPlan)
	}

	if !reflect.DeepEqual(meta, expectedMeta) {
		t.Errorf("Plan.List  meta returned %+v, expected %+v", meta, expectedMeta)
	}
}