-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathip_test.go
50 lines (37 loc) · 852 Bytes
/
ip_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
//go:build ip
package main_test
import (
"encoding/json"
"io"
"net/http"
"testing"
"github.com/wakatime/wakatime-cli/pkg/api"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type (
Meta struct {
Data MetaData `json:"data"`
}
MetaData struct {
Ips MetaDataIps `json:"ips"`
}
MetaDataIps struct {
Api MetaDataIpsApi `json:"api"`
}
MetaDataIpsApi struct {
V4 []string `json:"v4"`
V6 []string `json:"v6"`
}
)
func TestHardCodedIPs(t *testing.T) {
resp, err := http.Get("https://wakatime.com/api/v1/meta")
require.NoError(t, err)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
var meta Meta
err = json.Unmarshal(body, &meta)
require.NoError(t, err)
assert.Contains(t, meta.Data.Ips.Api.V4, api.BaseIPAddrv4)
assert.Contains(t, meta.Data.Ips.Api.V6, api.BaseIPAddrv6)
}