File: account_payments_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 (65 lines) | stat: -rw-r--r-- 1,741 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
package integration

import (
	"context"
	"testing"

	. "github.com/linode/linodego"
)

func TestPayment_GetMissing(t *testing.T) {
	client, teardown := createTestClient(t, "fixtures/TestPayment_GetMissing")
	defer teardown()

	i, err := client.GetPayment(context.Background(), -1)
	if err == nil {
		t.Errorf("should have received an error requesting a missing payment, got %v", i)
	}
	e, ok := err.(*Error)
	if !ok {
		t.Errorf("should have received an Error requesting a missing payment, got %v", e)
	}

	if e.Code != 404 {
		t.Errorf("should have received a 404 Code requesting a missing payment, got %v", e.Code)
	}
}

func TestPayment_GetFound(t *testing.T) {
	client, teardown := createTestClient(t, "fixtures/TestPayment_GetFound")
	defer teardown()

	p, err := client.ListPayments(context.Background(), nil)
	if err != nil {
		t.Errorf("Error listing payments, expected struct, got error %v", err)
	}
	if len(p) == 0 {
		t.Errorf("Expected a list of payments, but got none %v", p)
	}

	client, teardown = createTestClient(t, "fixtures/TestGetPayment_found")
	defer teardown()

	i, err := client.GetPayment(context.Background(), p[0].ID)
	if err != nil {
		t.Errorf("Error getting payment, expected struct, got %v and error %v", i, err)
	}
	if i.ID != p[0].ID {
		t.Errorf("Expected a specific payment, but got a different one %v", i)
	}

	assertDateSet(t, i.Date)
}

func TestPayments_List(t *testing.T) {
	client, teardown := createTestClient(t, "fixtures/TestPayments_List")
	defer teardown()

	i, err := client.ListPayments(context.Background(), nil)
	if err != nil {
		t.Errorf("Error listing payments, expected struct, got error %v", err)
	}
	if len(i) == 0 {
		t.Errorf("Expected a list of payments, but got none %v", i)
	}
}