/
bufferapi_test.go
82 lines (72 loc) · 1.85 KB
/
bufferapi_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package bufferapi
import (
"code.google.com/p/goauth2/oauth"
"encoding/json"
"io/ioutil"
. "launchpad.net/gocheck"
"math/rand"
"strconv"
"testing"
)
func Test(t *testing.T) { TestingT(t) }
type BufferSuite struct {
AuthToken string
ClientId string
ClientSecret string
Buffer *Client
UpdateIds []string
}
var _ = Suite(&BufferSuite{})
func loadConfig(config *BufferSuite) error {
filename := "config.json"
body, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
err = json.Unmarshal(body, &config)
if err != nil {
return err
}
return nil
}
func (s *BufferSuite) SetUpSuite(c *C) {
err := loadConfig(s)
if err != nil {
c.Fatalf("%v", err)
}
config := &oauth.Config{
ClientId: s.ClientId,
ClientSecret: s.ClientSecret,
Scope: "",
AuthURL: "",
TokenURL: "",
TokenCache: oauth.CacheFile(""),
}
transport := &oauth.Transport{Config: config}
s.Buffer = ClientFactory(s.AuthToken, transport)
}
func (s *BufferSuite) TestGetProfiles(c *C) {
_, err := s.Buffer.Profiles()
c.Assert(err, IsNil)
}
func (s *BufferSuite) TestGetUpdates(c *C) {
profiles, err := s.Buffer.Profiles()
_, err = s.Buffer.Get("profiles/" + (*profiles)[0].Id + "/updates/pending.json")
c.Assert(err, IsNil)
}
func (s *BufferSuite) TestNewUpdate(c *C) {
profiles, err := s.Buffer.Profiles()
u := NewUpdate{Text: "Test Update " + strconv.FormatInt(rand.Int63(), 10), Media: map[string]string{"link": "http://todaysvote.ca"}, ProfileIds: []string{(*profiles)[0].Id}}
resp, err := s.Buffer.Update(&u)
c.Assert(err, IsNil)
updateCount := len(resp.Updates)
id := resp.Updates[updateCount-1].Id
s.UpdateIds = append(s.UpdateIds, id)
c.Assert(err, IsNil)
}
func (s *BufferSuite) TearDownSuite(c *C) {
for _, u := range s.UpdateIds {
_, err := s.Buffer.Post("updates/"+u+"/destroy.json", nil)
c.Assert(err, IsNil)
}
}