This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
e621-sdk-go/pkg/e621/builder/post_test.go

79 lines
1.9 KiB
Go
Raw Normal View History

package builder
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
)
func TestGetPost(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
postResponse := model.PostResponse{
Post: model.Post{
ID: 658415636580,
CreatedAt: "2023-10-15T03:58:27.272-04:00",
UpdatedAt: "2023-10-19T02:47:33.597-04:00",
File: model.File{
Width: 759,
Height: 980,
EXT: "jpg",
Size: 640942,
Md5: "36e229e910638c7aebe65a500f16f3ee",
URL: "https://static1.e621.net/data/36/e2/36e229e910638c7aebe65a500f16f3ee.jpg",
},
Preview: model.Preview{},
Sample: model.Sample{},
Score: model.Score{},
Tags: model.Tags{},
LockedTags: nil,
ChangeSeq: 0,
Flags: model.Flags{},
Rating: "",
FavCount: 0,
Sources: nil,
Pools: nil,
Relationships: model.Relationships{},
ApproverID: nil,
UploaderID: 0,
Description: "",
CommentCount: 0,
IsFavorited: false,
HasNotes: false,
Duration: nil,
},
Posts: nil,
}
jsonResponser, err := httpmock.NewJsonResponder(200, postResponse)
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/posts/658415636580.json", jsonResponser)
requestContext := model.RequestContext{
Client: http.Client{},
Host: "https://e621.net",
UserAgent: "Go-e621-SDK (@username)",
Username: "memo",
APIKey: "123456",
}
getPost := NewGetPostBuilder(requestContext)
post, err := getPost.SetPostID(658415636580).Execute()
if err != nil {
t.Error(err)
return
}
if post.ID == postResponse.Post.ID && post.File.URL == postResponse.Post.File.URL {
return
}
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", post, postResponse)
}