all repos — telegram-bot-api @ 55f58bf98ebe0cb57c449c4dfa5f2e2ec10d33b4

Golang bindings for the Telegram Bot API

params_test.go (view raw)

 1package tgbotapi
 2
 3import (
 4	"testing"
 5)
 6
 7func assertLen(t *testing.T, params Params, l int) {
 8	actual := len(params)
 9	if actual != l {
10		t.Fatalf("Incorrect number of params, expected %d but found %d\n", l, actual)
11	}
12}
13
14func assertEq(t *testing.T, a interface{}, b interface{}) {
15	if a != b {
16		t.Fatalf("Values did not match, a: %v, b: %v\n", a, b)
17	}
18}
19
20func TestAddNonEmpty(t *testing.T) {
21	params := make(Params)
22	params.AddNonEmpty("value", "value")
23	assertLen(t, params, 1)
24	assertEq(t, params["value"], "value")
25	params.AddNonEmpty("test", "")
26	assertLen(t, params, 1)
27	assertEq(t, params["test"], "")
28}
29
30func TestAddNonZero(t *testing.T) {
31	params := make(Params)
32	params.AddNonZero("value", 1)
33	assertLen(t, params, 1)
34	assertEq(t, params["value"], "1")
35	params.AddNonZero("test", 0)
36	assertLen(t, params, 1)
37	assertEq(t, params["test"], "")
38}
39
40func TestAddNonZero64(t *testing.T) {
41	params := make(Params)
42	params.AddNonZero64("value", 1)
43	assertLen(t, params, 1)
44	assertEq(t, params["value"], "1")
45	params.AddNonZero64("test", 0)
46	assertLen(t, params, 1)
47	assertEq(t, params["test"], "")
48}
49
50func TestAddBool(t *testing.T) {
51	params := make(Params)
52	params.AddBool("value", true)
53	assertLen(t, params, 1)
54	assertEq(t, params["value"], "true")
55	params.AddBool("test", false)
56	assertLen(t, params, 1)
57	assertEq(t, params["test"], "")
58}
59
60func TestAddNonZeroFloat(t *testing.T) {
61	params := make(Params)
62	params.AddNonZeroFloat("value", 1)
63	assertLen(t, params, 1)
64	assertEq(t, params["value"], "1.000000")
65	params.AddNonZeroFloat("test", 0)
66	assertLen(t, params, 1)
67	assertEq(t, params["test"], "")
68}
69
70func TestAddInterface(t *testing.T) {
71	params := make(Params)
72	data := struct {
73		Name string `json:"name"`
74	}{
75		Name: "test",
76	}
77	params.AddInterface("value", data)
78	assertLen(t, params, 1)
79	assertEq(t, params["value"], `{"name":"test"}`)
80	params.AddInterface("test", nil)
81	assertLen(t, params, 1)
82	assertEq(t, params["test"], "")
83}
84
85func TestAddFirstValid(t *testing.T) {
86	params := make(Params)
87	params.AddFirstValid("value", 0, "", "test")
88	assertLen(t, params, 1)
89	assertEq(t, params["value"], "test")
90	params.AddFirstValid("value2", 3, "test")
91	assertLen(t, params, 2)
92	assertEq(t, params["value2"], "3")
93}