This repository has been archived by the owner on May 2, 2024. It is now read-only.
forked from adshmh/meter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functional_test.go
96 lines (78 loc) · 2.34 KB
/
functional_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
package main
import (
"testing"
"time"
"github.com/gojektech/heimdall/httpclient"
"github.com/pokt-foundation/relay-meter/api"
"github.com/pokt-foundation/utils-go/environment"
"github.com/stretchr/testify/suite"
)
type RelayMeterFunctionalTestSuite struct {
suite.Suite
options FunctionalTestClientOptions
httpClient *httpclient.Client
todayDate, yesterdayDate string
}
type FunctionalTestClientOptions struct {
relayMeterURL, relayMeterAPIKey string
}
func (ts *RelayMeterFunctionalTestSuite) SetupSuite() {
ts.options = FunctionalTestClientOptions{
relayMeterURL: environment.MustGetString("RELAY_METER_URL"),
relayMeterAPIKey: environment.MustGetString("RELAY_METER_API_KEY"),
}
ts.httpClient = httpclient.NewClient(
httpclient.WithHTTPTimeout(5*time.Second), httpclient.WithRetryCount(0),
)
today, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
yesterday, _ := time.Parse("2006-01-02", time.Now().Add(-time.Hour*24).Format("2006-01-02"))
ts.todayDate = today.Format("2006-01-02T15:04:05Z")
ts.yesterdayDate = yesterday.Format("2006-01-02T15:04:05Z")
}
func Test_RunSuite_Functional(t *testing.T) {
if testing.Short() {
t.Skip("skipping functional test test")
}
testSuite := new(RelayMeterFunctionalTestSuite)
suite.Run(t, testSuite)
}
func (ts *RelayMeterFunctionalTestSuite) Test_TodayAllRelayApps() {
allAppsRelays, err := get[[]api.AppRelaysResponse](
getOptions{
baseURL: ts.options.relayMeterURL,
apiKey: ts.options.relayMeterAPIKey,
path: "v1/relays/apps",
id: "",
params: ts.todayDate,
httpClient: ts.httpClient,
})
ts.NoError(err)
allZero := true
for _, result := range allAppsRelays {
if (result.Count.Failure + result.Count.Success) > 0 {
allZero = false
break
}
}
ts.False(allZero)
}
func (ts *RelayMeterFunctionalTestSuite) Test_YesterdayAllRelayApps() {
allAppsRelays, err := get[[]api.AppRelaysResponse](
getOptions{
baseURL: ts.options.relayMeterURL,
apiKey: ts.options.relayMeterAPIKey,
path: "v1/relays/apps",
id: "",
params: ts.yesterdayDate,
httpClient: ts.httpClient,
})
ts.NoError(err)
allZero := true
for _, result := range allAppsRelays {
if (result.Count.Failure + result.Count.Success) > 0 {
allZero = false
break
}
}
ts.False(allZero)
}