-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetUpdates_test.go
61 lines (57 loc) · 1.12 KB
/
GetUpdates_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
package telegram
import (
"fmt"
"os"
"testing"
)
func TestGetUpdates(t *testing.T) {
type args struct {
botToken string
offset string
}
tests := []struct {
name string
args args
want error
}{
{
name: "TestGetUpdates",
args: args{
botToken: os.Getenv("TELEGRAM_BOT_TOKEN"),
offset: "0",
},
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := GetUpdates(tt.args.botToken, tt.args.offset)
if err != tt.want {
t.Errorf("GetUpdates() = %v, want %v", err, tt.want)
}
})
}
}
func ExampleGetUpdates() {
// Bot token generated from BotFather
botToken := os.Getenv("TELEGRAM_BOT_TOKEN")
// Retrieving all updates until the server returns empty response
var allUpdates Updates
offset := 0
for {
fmt.Println("Using offset: " + fmt.Sprint(offset))
updates, err := GetUpdates(botToken, fmt.Sprint(offset))
if err != nil {
panic(err)
}
if len(*updates) > 0 {
allUpdates = append(allUpdates, *updates...)
offset = int(allUpdates[len(*updates)-1].UpdateID) + 1
if len(*updates) < 100 {
break
}
} else {
break
}
}
}