| 1 | package slack |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func getBotInfo(rw http.ResponseWriter, r *http.Request) { |
| 9 | rw.Header().Set("Content-Type", "application/json") |
| 10 | response := []byte(`{"ok": true, "bot": { |
| 11 | "id":"B02875YLA", |
| 12 | "deleted":false, |
| 13 | "name":"github", |
| 14 | "updated": 1449272004, |
| 15 | "app_id":"A161CLERW", |
| 16 | "user_id": "U012ABCDEF", |
| 17 | "icons": { |
| 18 | "image_36":"https:\/\/a.slack-edge.com\/2fac\/plugins\/github\/assets\/service_36.png", |
| 19 | "image_48":"https:\/\/a.slack-edge.com\/2fac\/plugins\/github\/assets\/service_48.png", |
| 20 | "image_72":"https:\/\/a.slack-edge.com\/2fac\/plugins\/github\/assets\/service_72.png" |
| 21 | } |
| 22 | }}`) |
| 23 | rw.Write(response) |
| 24 | } |
| 25 | |
| 26 | func TestGetBotInfo(t *testing.T) { |
| 27 | http.HandleFunc("/bots.info", getBotInfo) |
| 28 | |
| 29 | once.Do(startServer) |
| 30 | api := New("testing-token", OptionAPIURL("http://"+serverAddr+"/")) |
| 31 | |
| 32 | bot, err := api.GetBotInfo("B02875YLA") |
| 33 | if err != nil { |
| 34 | t.Errorf("Unexpected error: %s", err) |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | if bot.ID != "B02875YLA" { |
| 39 | t.Fatal("Incorrect ID") |
| 40 | } |
| 41 | if bot.Name != "github" { |
| 42 | t.Fatal("Incorrect Name") |
| 43 | } |
| 44 | if bot.Deleted { |
| 45 | t.Fatal("Incorrect Deleted flag") |
| 46 | } |
| 47 | if bot.AppID != "A161CLERW" { |
| 48 | t.Fatal("Incorrect App ID") |
| 49 | } |
| 50 | if bot.UserID != "U012ABCDEF" { |
| 51 | t.Fatal("Incorrect User ID") |
| 52 | } |
| 53 | if bot.Updated != 1449272004 { |
| 54 | t.Fatal("Incorrect Updated") |
| 55 | } |
| 56 | if len(bot.Icons.Image36) == 0 { |
| 57 | t.Fatal("Missing Image36") |
| 58 | } |
| 59 | if len(bot.Icons.Image48) == 0 { |
| 60 | t.Fatal("Missing Image38") |
| 61 | } |
| 62 | if len(bot.Icons.Image72) == 0 { |
| 63 | t.Fatal("Missing Image72") |
| 64 | } |
| 65 | } |