-
Notifications
You must be signed in to change notification settings - Fork 1
/
error_test.go
105 lines (96 loc) · 1.68 KB
/
error_test.go
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
// Package aiven provides a client for interacting with the Aiven API.
package aiven
import (
"context"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestIsNotFound(t *testing.T) {
cases := []struct {
name string
err error
expect bool
}{
{
name: "not found",
err: Error{
Message: "Not Found",
Status: 404,
},
expect: true,
},
{
name: "conflict",
err: Error{
Message: "already exists",
Status: 409,
},
expect: false,
},
{
name: "nil",
expect: false,
},
}
for _, opt := range cases {
t.Run(opt.name, func(t *testing.T) {
assert.Equal(t, opt.expect, IsNotFound(opt.err))
})
}
}
func TestIsNotFoundIntegration(t *testing.T) {
token := os.Getenv("AIVEN_TOKEN")
if token == "" {
t.Skip("token is required for the test")
}
c, err := NewClient()
require.NoError(t, err)
ctx := context.Background()
out, err := c.AccountGet(ctx, "does_not_exist")
assert.Nil(t, out)
assert.NotNil(t, err)
assert.True(t, IsNotFound(err))
}
func TestIsAlreadyExists(t *testing.T) {
cases := []struct {
name string
err error
expect bool
}{
{
name: "not found",
err: Error{
Message: "Not Found",
Status: 404,
},
expect: false,
},
{
name: "already exists",
err: Error{
Message: "already exists",
Status: 409,
},
expect: true,
},
{
name: "conflict",
err: Error{
Message: "conflict",
Status: 409,
},
expect: false,
},
{
name: "nil",
expect: false,
},
}
for _, opt := range cases {
t.Run(opt.name, func(t *testing.T) {
assert.Equal(t, opt.expect, IsAlreadyExists(opt.err))
})
}
}