File: bots_test.go

package info (click to toggle)
golang-github-slack-go-slack 0.11.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 1,720 kB
  • sloc: makefile: 54
file content (65 lines) | stat: -rw-r--r-- 1,566 bytes parent folder | download
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
package slack

import (
	"net/http"
	"testing"
)

func getBotInfo(rw http.ResponseWriter, r *http.Request) {
	rw.Header().Set("Content-Type", "application/json")
	response := []byte(`{"ok": true, "bot": {
			"id":"B02875YLA",
			"deleted":false,
			"name":"github",
			"updated": 1449272004,
			"app_id":"A161CLERW",
			"user_id": "U012ABCDEF",
			"icons": {
              "image_36":"https:\/\/a.slack-edge.com\/2fac\/plugins\/github\/assets\/service_36.png",
              "image_48":"https:\/\/a.slack-edge.com\/2fac\/plugins\/github\/assets\/service_48.png",
              "image_72":"https:\/\/a.slack-edge.com\/2fac\/plugins\/github\/assets\/service_72.png"
            }
        }}`)
	rw.Write(response)
}

func TestGetBotInfo(t *testing.T) {
	http.HandleFunc("/bots.info", getBotInfo)

	once.Do(startServer)
	api := New("testing-token", OptionAPIURL("http://"+serverAddr+"/"))

	bot, err := api.GetBotInfo("B02875YLA")
	if err != nil {
		t.Errorf("Unexpected error: %s", err)
		return
	}

	if bot.ID != "B02875YLA" {
		t.Fatal("Incorrect ID")
	}
	if bot.Name != "github" {
		t.Fatal("Incorrect Name")
	}
	if bot.Deleted {
		t.Fatal("Incorrect Deleted flag")
	}
	if bot.AppID != "A161CLERW" {
		t.Fatal("Incorrect App ID")
	}
	if bot.UserID != "U012ABCDEF" {
		t.Fatal("Incorrect User ID")
	}
	if bot.Updated != 1449272004 {
		t.Fatal("Incorrect Updated")
	}
	if len(bot.Icons.Image36) == 0 {
		t.Fatal("Missing Image36")
	}
	if len(bot.Icons.Image48) == 0 {
		t.Fatal("Missing Image38")
	}
	if len(bot.Icons.Image72) == 0 {
		t.Fatal("Missing Image72")
	}
}