File: organizations_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 (142 lines) | stat: -rw-r--r-- 2,899 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package packngo

import (
	"log"
	"testing"
)

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

	c := setup(t)
	defer organizationTeardown(c)

	rs := testProjectPrefix + randString8()
	ocr := OrganizationCreateRequest{
		Name:        rs,
		Description: "Managed by Packngo.",
		Website:     "http://example.com",
		Twitter:     "foo",
	}
	org, _, err := c.Organizations.Create(&ocr)
	if err != nil {
		t.Fatal(err)
	}
	if org.Name != rs {
		t.Fatalf("Expected new project name to be %s, not %s", rs, org.Name)
	}
	ol, _, err := c.Organizations.List(&ListOptions{PerPage: 1})
	if err != nil {
		t.Fatal(err)
	}
	found := false
	for _, o := range ol {
		if o.ID == org.ID {
			found = true
			break
		}
	}
	if !found {
		log.Println("Couldn't find created test org in org listing")
	}

	_, err = c.Organizations.Delete(org.ID)
	if err != nil {
		t.Fatal(err)
	}
}

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

	c := setup(t)
	defer organizationTeardown(c)

	rs := testProjectPrefix + randString8()
	ocr := OrganizationCreateRequest{
		Name:        rs,
		Description: "Managed by Packngo.",
		Website:     "http://example.com",
		Twitter:     "foo",
	}
	p, _, err := c.Organizations.Create(&ocr)
	if err != nil {
		t.Fatal(err)
	}
	if p.Name != rs {
		t.Fatalf("Expected new project name to be %s, not %s", rs, p.Name)
	}

	rs = testProjectPrefix + randString8()
	oDesc := "Managed by Packngo."
	oWeb := "http://quux.example.com"
	oTwi := "bar"
	pur := OrganizationUpdateRequest{
		Name:        &rs,
		Description: &oDesc,
		Website:     &oWeb,
		Twitter:     &oTwi,
	}
	org, _, err := c.Organizations.Update(p.ID, &pur)
	if err != nil {
		t.Fatal(err)
	}
	if org.Name != rs {
		t.Fatalf("Expected the name of the updated project to be %s, not %s", rs, p.Name)
	}
	gotOrg, _, err := c.Organizations.Get(org.ID, nil)
	if err != nil {
		t.Fatal(err)
	}
	if gotOrg.Name != rs {
		t.Fatalf("Expected the name of the GOT project to be %s, not %s", rs, gotOrg.Name)
	}

	_, _, err = c.Organizations.ListEvents(org.ID, nil)
	if err != nil {
		t.Fatal(err)
	}

	_, err = c.Organizations.Delete(org.ID)
	if err != nil {
		t.Fatal(err)
	}

}
func TestAccOrgListPaymentMethods(t *testing.T) {
	skipUnlessAcceptanceTestsAllowed(t)

	// setup
	c := setup(t)
	defer organizationTeardown(c)

	rs := testProjectPrefix + randString8()
	ocr := OrganizationCreateRequest{
		Name:        rs,
		Description: "Managed by Packngo.",
		Website:     "http://example.com",
		Twitter:     "foo",
	}
	org, _, err := c.Organizations.Create(&ocr)
	if err != nil {
		t.Fatal(err)
	}

	// tests
	pms, _, err := c.Organizations.ListPaymentMethods(org.ID)

	if err != nil {
		t.Fatal("error: ", err)
	}

	if len(pms) != 0 {
		t.Fatal("the new test org should have no payment methods")
	}

	// teardown
	_, err = c.Organizations.Delete(org.ID)
	if err != nil {
		t.Fatal(err)
	}

}