Этот коммит содержится в:
Carlos Tadeu Panato Junior
2017-01-06 18:10:00 +01:00
коммит произвёл Joram Wilander
родитель c96a36e9b3
Коммит 61771a0fc5
2 изменённых файлов: 45 добавлений и 0 удалений

Просмотреть файл

@@ -1389,3 +1389,33 @@ func TestGetPostById(t *testing.T) {
t.Fatal(respMetadata.Error)
}
}
func TestGetPermalinkTmp(t *testing.T) {
th := Setup().InitBasic()
Client := th.BasicClient
channel1 := th.BasicChannel
time.Sleep(10 * time.Millisecond)
post1 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"}
post1 = Client.Must(Client.CreatePost(post1)).Data.(*model.Post)
time.Sleep(10 * time.Millisecond)
post2 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"}
post2 = Client.Must(Client.CreatePost(post2)).Data.(*model.Post)
etag := Client.Must(Client.GetPost(channel1.Id, post1.Id, "")).Etag
// test etag caching
if cache_result, respMetadata := Client.GetPermalink(channel1.Id, post1.Id, etag); respMetadata.Error != nil {
t.Fatal(respMetadata.Error)
} else if cache_result != nil {
t.Log(cache_result)
t.Fatal("cache should be empty")
}
if results, respMetadata := Client.GetPermalink(channel1.Id, post1.Id, ""); respMetadata.Error != nil {
t.Fatal(respMetadata.Error)
} else if results == nil {
t.Fatal("should not be empty")
}
}

Просмотреть файл

@@ -1471,6 +1471,21 @@ func (c *Client) GetPostById(postId string, etag string) (*PostList, *ResponseMe
}
}
// GetPermalink returns a post list, based on the provided channel and post ID.
func (c *Client) GetPermalink(channelId string, postId string, etag string) (*PostList, *ResponseMetadata) {
if r, err := c.DoApiGet(c.GetTeamRoute()+fmt.Sprintf("/pltmp/%v", postId), "", etag); err != nil {
return nil, &ResponseMetadata{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
return PostListFromJson(r.Body),
&ResponseMetadata{
StatusCode: r.StatusCode,
RequestId: r.Header.Get(HEADER_REQUEST_ID),
Etag: r.Header.Get(HEADER_ETAG_SERVER),
}
}
}
func (c *Client) DeletePost(channelId string, postId string) (*Result, *AppError) {
if r, err := c.DoApiPost(c.GetChannelRoute(channelId)+fmt.Sprintf("/posts/%v/delete", postId), ""); err != nil {
return nil, err