-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuckets_test.go
More file actions
119 lines (99 loc) · 3.08 KB
/
buckets_test.go
File metadata and controls
119 lines (99 loc) · 3.08 KB
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
package webhookrelay
import (
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"testing"
"time"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func getIntegrationTestClient() (*API, error) {
key := os.Getenv("RELAY_KEY")
secret := os.Getenv("RELAY_SECRET")
if key == "" {
return nil, errors.New("RELAY_KEY must be set")
}
if secret == "" {
return nil, errors.New("RELAY_SECRET must be set")
}
return New(key, secret)
}
func TestListBuckets(t *testing.T) {
client, err := getIntegrationTestClient()
if err != nil {
t.Fatalf("failed to get API client: %s", err)
}
buckets, err := client.ListBuckets(&BucketListOptions{})
assert.Nil(t, err)
assert.True(t, len(buckets) > 0)
found := false
// Look for "test-bucket" in the buckets
for _, bucket := range buckets {
if bucket.Name == "test-bucket-1" {
found = true
}
}
assert.True(t, found, "test-bucket-1 not found in buckets")
}
func TestListBuckets_TimeFormats(t *testing.T) {
requestCount := 0
testTime := time.Date(2024, 1, 15, 10, 30, 0, 0, time.UTC)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "/buckets", r.URL.Path)
assert.Equal(t, http.MethodGet, r.Method)
var buckets []map[string]interface{}
if requestCount == 0 {
buckets = []map[string]interface{}{
{
"id": "bucket-1",
"name": "Test Bucket 1",
"description": "First bucket",
"created_at": testTime.Unix(),
"updated_at": testTime.Unix(),
"stream": false,
"ephemeral": false,
"auth": map[string]interface{}{"type": "none"},
"inputs": []interface{}{},
"outputs": []interface{}{},
},
}
requestCount++
} else {
buckets = []map[string]interface{}{
{
"id": "bucket-2",
"name": "Test Bucket 2",
"description": "Second bucket",
"created_at": testTime.Format(time.RFC3339),
"updated_at": testTime.Format(time.RFC3339),
"stream": true,
"ephemeral": true,
"auth": map[string]interface{}{"type": "basic", "username": "user", "password": "pass"},
"inputs": []interface{}{},
"outputs": []interface{}{},
},
}
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(buckets)
}))
defer server.Close()
client, err := New("test-key", "test-secret", WithAPIEndpointURL(server.URL))
assert.NoError(t, err)
buckets, err := client.ListBuckets(&BucketListOptions{})
assert.NoError(t, err)
assert.Len(t, buckets, 1)
assert.Equal(t, "bucket-1", buckets[0].ID)
assert.Equal(t, "Test Bucket 1", buckets[0].Name)
assert.Equal(t, testTime.Unix(), buckets[0].CreatedAt.Unix())
assert.Equal(t, testTime.Unix(), buckets[0].UpdatedAt.Unix())
buckets, err = client.ListBuckets(&BucketListOptions{})
assert.NoError(t, err)
assert.Len(t, buckets, 1)
assert.Equal(t, "bucket-2", buckets[0].ID)
assert.Equal(t, "Test Bucket 2", buckets[0].Name)
assert.Equal(t, testTime.Unix(), buckets[0].CreatedAt.Unix())
assert.Equal(t, testTime.Unix(), buckets[0].UpdatedAt.Unix())
}