-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtop_city_test.go
51 lines (45 loc) · 1.17 KB
/
top_city_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
package qweather
import (
"log/slog"
"os"
"testing"
)
const QWEATHER_KEY string = "QWEATHER_KEY"
func TestTopCity(t *testing.T) {
t.Run("V2TopCity", func(t *testing.T) {
req := NewV2TopCityRequest()
req.Key = os.Getenv(QWEATHER_KEY)
client := NewClient()
resp, err := client.V2TopCity(req)
if err != nil {
t.Fatal(err)
}
t.Logf("V2TopCity resp:%s", resp.String())
// {"code":"401","refer":{}}
})
t.Run("V2TopCity-with-enbaled-log", func(t *testing.T) {
req := NewV2TopCityRequest()
req.Key = os.Getenv(QWEATHER_KEY)
client := NewClient(WithLogEnabled(true))
resp, err := client.V2TopCity(req)
if err != nil {
t.Fatal(err)
}
t.Logf("V2TopCity resp:%s", resp.String())
// {"code":"401","refer":{}}
})
t.Run("V2TopCity-with-logger", func(t *testing.T) {
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelInfo,
}))
req := NewV2TopCityRequest()
req.Key = os.Getenv(QWEATHER_KEY)
client := NewClient(WithLogger(logger), WithLogEnabled(true))
resp, err := client.V2TopCity(req)
if err != nil {
t.Fatal(err)
}
t.Logf("V2TopCity resp:%s", resp.String())
// {"code":"401","refer":{}}
})
}