-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsfloat_test.go
More file actions
137 lines (115 loc) · 2.58 KB
/
csfloat_test.go
File metadata and controls
137 lines (115 loc) · 2.58 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package csfloat_test
import (
"context"
"encoding/json"
"fmt"
"log"
"net"
"net/http"
"os"
"sync"
"testing"
"time"
csfloat "github.com/Bios-Marcel/csfloat_go"
"github.com/stretchr/testify/assert"
)
func TestDummy(t *testing.T) {
t.Skip()
dialer := &net.Dialer{
Timeout: 15 * time.Second,
}
transport := &http.Transport{
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
conn, err := dialer.DialContext(ctx, "tcp4", addr)
if err == nil {
log.Println(conn.RemoteAddr().String())
return conn, nil
}
return nil, fmt.Errorf("no IPv6 address could be dialed for %s", addr)
},
TLSHandshakeTimeout: 3 * time.Second,
ResponseHeaderTimeout: 15 * time.Second,
ExpectContinueTimeout: 3 * time.Second,
}
client := &http.Client{
Transport: transport,
Timeout: 15 * time.Second,
}
request, err := http.NewRequest("GET", "https://csfloat.com", nil)
if err != nil {
panic(err)
}
client.Do(request)
}
func TestJsonEncoder(t *testing.T) {
b := csfloat.ListRequest{
BuyNowRequest: &csfloat.BuyNowRequest{
Price: 5,
},
}
x, _ := json.MarshalIndent(b, "", " ")
t.Log(string(x))
}
var apiKey = os.Getenv("CSFLOAT_API_KEY")
var me = sync.OnceValue(func() *csfloat.MeResponse {
api := csfloat.New()
me, err := api.Me(apiKey)
if err != nil {
panic(err)
}
return me
})
func Test_Inventory(t *testing.T) {
ass := assert.New(t)
api := csfloat.New()
items, err := api.Inventory(apiKey)
if ass.NoError(err) {
t.Log(items)
ass.NotEmpty(items)
}
}
func Test_Stall(t *testing.T) {
ass := assert.New(t)
api := csfloat.New()
items, err := api.Stall(apiKey, me().User.SteamId)
if ass.NoError(err) {
t.Log(items)
ass.NotEmpty(items)
}
}
func Test_Listing(t *testing.T) {
ass := assert.New(t)
api := csfloat.New()
listing, err := api.Listing(apiKey, "869907646323492200")
if ass.NoError(err) {
t.Log(listing.Item)
ass.NotEmpty(listing)
}
}
func Test_Listings(t *testing.T) {
ass := assert.New(t)
api := csfloat.New()
items, err := api.Listings(apiKey, csfloat.ListingsRequest{})
if ass.NoError(err) {
t.Log(items)
ass.NotEmpty(items)
}
}
func Test_BuyIncorrectPrice(t *testing.T) {
// ass := assert.New(t)
api := csfloat.New()
response, err := api.Buy(apiKey, csfloat.BuyRequestPayload{
ContractIds: []string{"861537163265837281"},
TotalPrice: 1,
})
t.Log(response.Error, err)
}
func Test_BulkDelist(t *testing.T) {
api := csfloat.New()
response, err := api.BulkUnlist(apiKey, []string{
"892909870007846613",
"892909870007846614",
"892909870012040919",
}...)
t.Log(response.Error, err)
}