-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdatasource_test.go
82 lines (60 loc) · 1.74 KB
/
datasource_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
//go:build integration
package main
import (
"context"
"fmt"
"os"
"testing"
"github.com/leighmacdonald/steamid/v4/steamid"
"github.com/stretchr/testify/require"
)
func TestDataSource(t *testing.T) {
t.Parallel()
var (
testIDb4nny = steamid.New("76561197970669109")
testIDCamper = steamid.New("76561197992870439")
)
ctx := context.Background()
testIDs := steamid.Collection{testIDb4nny, testIDCamper}
testableDS := map[string]DataSource{}
key, found := os.LookupEnv("BD_API_KEY")
if found {
lds, errLDS := createLocalDataSource(key)
require.NoError(t, errLDS)
testableDS["local"] = lds
}
baseURL := ""
if apiURL, isTest := os.LookupEnv("API_URL"); isTest {
baseURL = apiURL
}
apiDataSource, errAPI := createAPIDataSource(baseURL)
require.NoError(t, errAPI)
testableDS["api"] = apiDataSource
for name, ds := range testableDS {
dataSource := ds
t.Run(fmt.Sprintf("%s_summary", name), func(t *testing.T) {
t.Parallel()
summaries, errSum := dataSource.summaries(ctx, testIDs)
require.NoError(t, errSum)
require.Equal(t, len(testIDs), len(summaries))
})
t.Run(fmt.Sprintf("%s_friends", name), func(t *testing.T) {
t.Parallel()
friends, errSum := dataSource.friends(ctx, testIDs)
require.NoError(t, errSum)
require.Equal(t, len(testIDs), len(friends))
})
t.Run(fmt.Sprintf("%s_bans", name), func(t *testing.T) {
t.Parallel()
vacBans, errSum := dataSource.Bans(ctx, testIDs)
require.NoError(t, errSum)
require.Equal(t, len(testIDs), len(vacBans))
})
t.Run(fmt.Sprintf("%s_sourcebans", name), func(t *testing.T) {
t.Parallel()
sourcebans, errSum := dataSource.sourceBans(ctx, testIDs)
require.NoError(t, errSum)
require.Equal(t, len(testIDs), len(sourcebans))
})
}
}