Fix accounts test
parent
a0232ea6ef
commit
39239ae270
107
accounts_test.go
107
accounts_test.go
|
@ -8,8 +8,12 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestAccountUpdate(t *testing.T) {
|
||||
func TestGetAccount(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/v1/accounts/1234567" {
|
||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
fmt.Fprintln(w, `{"Username": "zzz"}`)
|
||||
return
|
||||
}))
|
||||
|
@ -21,6 +25,74 @@ func TestAccountUpdate(t *testing.T) {
|
|||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
a, err := client.GetAccount(context.Background(), 1)
|
||||
if err == nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
a, err = client.GetAccount(context.Background(), 1234567)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
if a.Username != "zzz" {
|
||||
t.Fatalf("want %q but %q", "zzz", a.Username)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAccountCurrentUser(t *testing.T) {
|
||||
canErr := true
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if canErr {
|
||||
canErr = false
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
fmt.Fprintln(w, `{"Username": "zzz"}`)
|
||||
return
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
client := NewClient(&Config{
|
||||
Server: ts.URL,
|
||||
ClientID: "foo",
|
||||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
_, err := client.GetAccountCurrentUser(context.Background())
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
a, err := client.GetAccountCurrentUser(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
if a.Username != "zzz" {
|
||||
t.Fatalf("want %q but %q", "zzz", a.Username)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountUpdate(t *testing.T) {
|
||||
canErr := true
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if canErr {
|
||||
canErr = false
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
fmt.Fprintln(w, `{"Username": "zzz"}`)
|
||||
return
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
client := NewClient(&Config{
|
||||
Server: ts.URL,
|
||||
ClientID: "foo",
|
||||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
_, err := client.AccountUpdate(context.Background(), &Profile{})
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
a, err := client.AccountUpdate(context.Background(), &Profile{
|
||||
DisplayName: String("display_name"),
|
||||
Note: String("note"),
|
||||
|
@ -35,6 +107,39 @@ func TestAccountUpdate(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetAccountStatuses(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/v1/accounts/1234567/statuses" {
|
||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
fmt.Fprintln(w, `[{"Content": "foo"}, {"Content": "bar"}]`)
|
||||
return
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
client := NewClient(&Config{
|
||||
Server: ts.URL,
|
||||
ClientID: "foo",
|
||||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
_, err := client.GetAccountStatuses(context.Background(), 123)
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
ss, err := client.GetAccountStatuses(context.Background(), 1234567)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
if ss[0].Content != "foo" {
|
||||
t.Fatalf("want %q but %q", "foo", ss[0].Content)
|
||||
}
|
||||
if ss[1].Content != "bar" {
|
||||
t.Fatalf("want %q but %q", "bar", ss[1].Content)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetBlocks(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintln(w, `[{"Username": "foo"}, {"Username": "bar"}]`)
|
||||
|
|
|
@ -126,36 +126,6 @@ func TestForTheCoverages(t *testing.T) {
|
|||
_ = (&ErrorEvent{io.EOF}).Error()
|
||||
}
|
||||
|
||||
func TestGetAccount(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/v1/accounts/1234567" {
|
||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
fmt.Fprintln(w, `{"Username": "zzz"}`)
|
||||
return
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
client := NewClient(&Config{
|
||||
Server: ts.URL,
|
||||
ClientID: "foo",
|
||||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
a, err := client.GetAccount(context.Background(), 1)
|
||||
if err == nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
a, err = client.GetAccount(context.Background(), 1234567)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
if a.Username != "zzz" {
|
||||
t.Fatalf("want %q but %q", "zzz", a.Username)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAccountFollowing(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/v1/accounts/1234567/following" {
|
||||
|
|
Loading…
Reference in New Issue