-
Notifications
You must be signed in to change notification settings - Fork 0
/
subscription_test.go
109 lines (97 loc) · 3.46 KB
/
subscription_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
106
107
108
109
package govdata
import (
"net/http/httptest"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSubscribe(t *testing.T) {
mock := httptest.NewServer(
&Fixture{t,
map[string]string{
"/api/3/action/resource_show": "./test/resource.json",
},
})
BaseURL = mock.URL
timestamp, err := time.Parse(ResourceCreatedTimeFormat, "2019-11-12 01:00:00")
require.NoError(t, err)
expected := []Revision{
{
ID: "12112019_2",
ResourceID: "1235678-1234-1234-1234-000123456789",
MimeType: "application/json",
Name: "example.json",
Format: "JSON",
URL: "https://data.gov.ua/dataset/00000000-0000-0000-0000-000000000000/resource/1235678-1234-1234-1234-000123456789/revision/12112019_2",
ResourceCreated: ResourceCreatedTime{timestamp.Add(12 * time.Hour)},
Size: 10000000,
},
{
ID: "12112019_1",
ResourceID: "1235678-1234-1234-1234-000123456789",
MimeType: "application/json",
Name: "example.json",
Format: "JSON",
URL: "https://data.gov.ua/dataset/00000000-0000-0000-0000-000000000000/resource/1235678-1234-1234-1234-000123456789/revision/12112019_1",
ResourceCreated: ResourceCreatedTime{timestamp},
Size: 20000000,
},
}
revisions := Subscribe("1235678-1234-1234-1234-000123456789", timestamp.Add(time.Second))
select {
case r := <-revisions:
assert.Equal(t, expected[0], r)
case <-time.After(time.Second):
t.Error("expected revision")
}
}
func TestSubscribePackage(t *testing.T) {
mock := httptest.NewServer(
&Fixture{t,
map[string]string{
"/api/3/action/package_show": "./test/package.json",
"/api/3/action/resource_show": "./test/resource.json",
},
})
BaseURL = mock.URL
timestamp, err := time.Parse(ResourceCreatedTimeFormat, "2019-11-12 01:00:00")
require.NoError(t, err)
expected := Resource{
ID: "1235678-1234-1234-1234-000123456789",
MimeType: "application/json",
Name: "example.json",
URL: "https://data.gov.ua/dataset/00000000-0000-0000-0000-00000000000/resource/1235678-1234-1234-1234-000123456789/download/example.json",
Revisions: []Revision{
{
ID: "12112019_2",
ResourceID: "1235678-1234-1234-1234-000123456789",
MimeType: "application/json",
Name: "example.json",
Format: "JSON",
URL: "https://data.gov.ua/dataset/00000000-0000-0000-0000-000000000000/resource/1235678-1234-1234-1234-000123456789/revision/12112019_2",
ResourceCreated: ResourceCreatedTime{timestamp.Add(12 * time.Hour)},
Size: 10000000,
},
{
ID: "12112019_1",
ResourceID: "1235678-1234-1234-1234-000123456789",
MimeType: "application/json",
Name: "example.json",
Format: "JSON",
URL: "https://data.gov.ua/dataset/00000000-0000-0000-0000-000000000000/resource/1235678-1234-1234-1234-000123456789/revision/12112019_1",
ResourceCreated: ResourceCreatedTime{timestamp},
Size: 20000000,
},
},
PackageID: "00000000-0000-0000-0000-000000000000",
LastModified: LastModifiedTime{timestamp.Add(12 * time.Hour)},
}
events := SubscribePackage("00000000-0000-0000-0000-000000000000", map[string]time.Time{})
select {
case r := <-events:
assert.Equal(t, expected, r)
case <-time.After(time.Second):
t.Error("expected revision")
}
}