refactor: tests use premade json files to test against.

Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
SoXX 2023-11-06 12:07:55 +01:00
parent 34b7b9346f
commit 517c7f595e
17 changed files with 129 additions and 517 deletions

View File

@ -2,6 +2,7 @@ package builder
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
@ -11,109 +12,13 @@ func TestGetFavorites(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
postResponse := model.PostResponse{
Post: model.Post{},
Posts: []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,
},
{
ID: 698418695,
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,
},
{
ID: 48976516894,
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,
},
},
response, err := utils.LoadJsonTestData[model.PostResponse]("../../../tests/posts.json")
if err != nil {
t.Error(err)
return
}
jsonResponser, err := httpmock.NewJsonResponder(200, postResponse)
jsonResponser, err := httpmock.NewJsonResponder(200, response)
if err != nil {
t.Error(err)
return
@ -134,10 +39,10 @@ func TestGetFavorites(t *testing.T) {
return
}
if len(posts) == 3 && posts[0].ID == postResponse.Posts[0].ID && posts[1].File.Md5 == postResponse.Posts[1].File.Md5 && posts[2].File.EXT == postResponse.Posts[2].File.EXT {
if posts[0].ID == response.Posts[0].ID && posts[1].File.Md5 == response.Posts[1].File.Md5 && posts[2].File.EXT == response.Posts[2].File.EXT {
return
}
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", posts, postResponse)
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", posts, response)
}

View File

@ -2,6 +2,7 @@ package builder
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
@ -11,28 +12,18 @@ func TestGetNote(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
noteResponse := model.Note{
ID: 385777,
CreatedAt: "2023-10-19T06:42:20.171-04:00",
UpdatedAt: "2023-10-19T06:42:20.171-04:00",
CreatorID: 1472475,
X: 277,
Y: 841,
Width: 101,
Height: 176,
Version: 2,
IsActive: true,
PostID: 2624329,
Body: "Well, isnt it just right to use them?",
CreatorName: "ponypussypounder",
}
jsonResponser, err := httpmock.NewJsonResponder(200, noteResponse)
response, err := utils.LoadJsonTestData[model.Note]("../../../tests/note.json")
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/notes/36957.json", jsonResponser)
responser, err := httpmock.NewJsonResponder(200, response)
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/notes/36957.json", responser)
requestContext := model.RequestContext{
Client: http.Client{},
@ -49,10 +40,10 @@ func TestGetNote(t *testing.T) {
return
}
if pool.ID == noteResponse.ID && pool.Body == noteResponse.Body {
if pool.ID == response.ID && pool.Body == response.Body {
return
}
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", pool, noteResponse)
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", pool, response)
}

View File

@ -2,6 +2,7 @@ package builder
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
@ -11,60 +12,18 @@ func TestGetNotes(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
noteResponse := []model.Note{
{
ID: 385777,
CreatedAt: "2023-10-19T06:42:20.171-04:00",
UpdatedAt: "2023-10-19T06:42:20.171-04:00",
CreatorID: 1472475,
X: 277,
Y: 841,
Width: 101,
Height: 176,
Version: 2,
IsActive: true,
PostID: 2624329,
Body: "Well, isnt it just right to use them?",
CreatorName: "ponypussypounder",
},
{
ID: 56782,
CreatedAt: "2023-10-19T06:42:20.171-04:00",
UpdatedAt: "2023-10-19T06:42:20.171-04:00",
CreatorID: 1472475,
X: 277,
Y: 841,
Width: 101,
Height: 176,
Version: 2,
IsActive: true,
PostID: 2624329,
Body: "Well, isnt it just right to use them?",
CreatorName: "ponypussypounder",
},
{
ID: 43847234,
CreatedAt: "2023-10-19T06:42:20.171-04:00",
UpdatedAt: "2023-10-19T06:42:20.171-04:00",
CreatorID: 1472475,
X: 277,
Y: 841,
Width: 101,
Height: 176,
Version: 2,
IsActive: true,
PostID: 2624329,
Body: "Well, isnt it just right to use them?",
CreatorName: "ponypussypounder",
},
}
jsonResponser, err := httpmock.NewJsonResponder(200, noteResponse)
response, err := utils.LoadJsonTestData[[]model.Note]("../../../tests/notes.json")
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/notes.json", jsonResponser)
responser, err := httpmock.NewJsonResponder(200, response)
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/notes.json", responser)
requestContext := model.RequestContext{
Client: http.Client{},
@ -81,10 +40,10 @@ func TestGetNotes(t *testing.T) {
return
}
if len(pools) == 3 && pools[0].ID == noteResponse[0].ID && pools[1].Body == noteResponse[1].Body && pools[2].UpdatedAt == noteResponse[2].UpdatedAt {
if pools[0].ID == response[0].ID && pools[1].Body == response[1].Body && pools[2].UpdatedAt == response[2].UpdatedAt {
return
}
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", pools, noteResponse)
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", pools, response)
}

View File

@ -2,6 +2,7 @@ package builder
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
@ -11,26 +12,18 @@ func TestGetPool(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
poolResponse := model.Pool{
ID: 36957,
Name: "MLP:His_Nocturnal_Excellency",
CreatedAt: "2023-10-13T19:24:00.576-04:00",
UpdatedAt: "2023-10-19T07:46:00.267-04:00",
CreatorID: 16883,
Description: "Two (un)lucky royal guards who saw something they didnt have to~",
IsActive: true,
Category: "series",
PostIDS: nil,
CreatorName: "2DUK",
PostCount: 11,
}
jsonResponser, err := httpmock.NewJsonResponder(200, poolResponse)
response, err := utils.LoadJsonTestData[model.Pool]("../../../tests/pool.json")
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/pools/36957.json", jsonResponser)
responser, err := httpmock.NewJsonResponder(200, response)
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/pools/36957.json", responser)
requestContext := model.RequestContext{
Client: http.Client{},
@ -47,10 +40,10 @@ func TestGetPool(t *testing.T) {
return
}
if pool.ID == poolResponse.ID && pool.Name == poolResponse.Name {
if pool.ID == response.ID && pool.Name == response.Name {
return
}
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", pool, poolResponse)
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", pool, response)
}

View File

@ -2,6 +2,7 @@ package builder
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
@ -11,67 +12,17 @@ func TestGetPools(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
poolResponse := []model.Pool{
{
ID: 36957,
Name: "MLP:His_Nocturnal_Excellency",
CreatedAt: "2023-10-13T19:24:00.576-04:00",
UpdatedAt: "2023-10-19T07:46:00.267-04:00",
CreatorID: 16883,
Description: "Two (un)lucky royal guards who saw something they didnt have to~",
IsActive: true,
Category: "series",
PostIDS: nil,
CreatorName: "2DUK",
PostCount: 11,
},
{
ID: 5772,
Name: "MLP:His_Nocturnal_Excellency",
CreatedAt: "2023-10-13T19:24:00.576-04:00",
UpdatedAt: "2023-10-19T07:46:00.267-04:00",
CreatorID: 16883,
Description: "Two (un)lucky royal guards who saw something they didnt have to~",
IsActive: true,
Category: "series",
PostIDS: nil,
CreatorName: "2DUK",
PostCount: 11,
},
{
ID: 453687,
Name: "MLP:His_Nocturnal_Excellency",
CreatedAt: "2023-10-13T19:24:00.576-04:00",
UpdatedAt: "2023-10-19T07:46:00.267-04:00",
CreatorID: 16883,
Description: "Two (un)lucky royal guards who saw something they didnt have to~",
IsActive: true,
Category: "series",
PostIDS: nil,
CreatorName: "2DUK",
PostCount: 11,
},
{
ID: 3456876,
Name: "MLP:His_Nocturnal_Excellency",
CreatedAt: "2023-10-13T19:24:00.576-04:00",
UpdatedAt: "2023-10-19T07:46:00.267-04:00",
CreatorID: 16883,
Description: "Two (un)lucky royal guards who saw something they didnt have to~",
IsActive: true,
Category: "series",
PostIDS: nil,
CreatorName: "2DUK",
PostCount: 11,
},
}
jsonResponser, err := httpmock.NewJsonResponder(200, poolResponse)
response, err := utils.LoadJsonTestData[[]model.Pool]("../../../tests/pools.json")
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/pools.json", jsonResponser)
responser, err := httpmock.NewJsonResponder(200, response)
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/pools.json", responser)
requestContext := model.RequestContext{
Client: http.Client{},
@ -88,10 +39,10 @@ func TestGetPools(t *testing.T) {
return
}
if len(pools) == 4 && pools[0].ID == poolResponse[0].ID && pools[1].Name == poolResponse[1].Name && pools[2].UpdatedAt == poolResponse[2].UpdatedAt {
if pools[0].ID == response[0].ID && pools[1].Name == response[1].Name && pools[2].UpdatedAt == response[2].UpdatedAt {
return
}
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", pools, poolResponse)
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", pools, response)
}

View File

@ -2,6 +2,7 @@ package builder
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
@ -11,48 +12,23 @@ 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)
data, err := utils.LoadJsonTestData[model.Post]("../../../tests/post.json")
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/posts/658415636580.json", jsonResponser)
response := model.PostResponse{
Post: data,
Posts: nil,
}
responser, err := httpmock.NewJsonResponder(200, response)
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/posts/658415636580.json", responser)
requestContext := model.RequestContext{
Client: http.Client{},
@ -69,10 +45,10 @@ func TestGetPost(t *testing.T) {
return
}
if post.ID == postResponse.Post.ID && post.File.URL == postResponse.Post.File.URL {
if post.ID == response.Post.ID && post.File.URL == response.Post.File.URL {
return
}
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", post, postResponse)
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", post, response)
}

View File

@ -2,6 +2,7 @@ package builder
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
@ -11,114 +12,18 @@ func TestGetPosts(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
postResponse := model.PostResponse{
Post: model.Post{},
Posts: []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,
},
{
ID: 698418695,
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,
},
{
ID: 48976516894,
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,
},
},
}
jsonResponser, err := httpmock.NewJsonResponder(200, postResponse)
response, err := utils.LoadJsonTestData[model.PostResponse]("../../../tests/posts.json")
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/posts.json", jsonResponser)
responser, err := httpmock.NewJsonResponder(200, response)
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/posts.json", responser)
requestContext := model.RequestContext{
Client: http.Client{},
@ -135,10 +40,10 @@ func TestGetPosts(t *testing.T) {
return
}
if len(posts) == 3 && posts[0].ID == postResponse.Posts[0].ID && posts[1].File.Md5 == postResponse.Posts[1].File.Md5 && posts[2].File.EXT == postResponse.Posts[2].File.EXT {
if posts[0].ID == response.Posts[0].ID && posts[1].File.Md5 == response.Posts[1].File.Md5 && posts[2].File.EXT == response.Posts[2].File.EXT {
return
}
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", posts, postResponse)
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", posts, response)
}

View File

@ -2,6 +2,7 @@ package builder
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
@ -11,24 +12,18 @@ func TestGetTag(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
tagResponse := model.Tag{
ID: 165165,
Name: "35ad13",
PostCount: 59,
RelatedTags: "[]",
RelatedTagsUpdatedAt: "2023-10-16T07:58:15.897+02:00",
Category: 0,
IsLocked: false,
CreatedAt: "2023-10-16T07:58:15.917+02:00",
UpdatedAt: "2023-10-16T07:58:23.310+02:00",
}
jsonResponser, err := httpmock.NewJsonResponder(200, tagResponse)
response, err := utils.LoadJsonTestData[model.Tag]("../../../tests/tag.json")
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/tags/165165.json", jsonResponser)
responser, err := httpmock.NewJsonResponder(200, response)
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/tags/165165.json", responser)
requestContext := model.RequestContext{
Client: http.Client{},
@ -45,10 +40,10 @@ func TestGetTag(t *testing.T) {
return
}
if tag.ID == tagResponse.ID && tag.Name == tagResponse.Name && tag.CreatedAt == tagResponse.CreatedAt {
if tag.ID == response.ID && tag.Name == response.Name && tag.CreatedAt == response.CreatedAt {
return
}
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", tag, tagResponse)
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", tag, response)
}

View File

@ -2,6 +2,7 @@ package builder
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
@ -11,39 +12,18 @@ func TestGetUser(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
userResponse := model.User{
WikiPageVersionCount: 0,
ArtistVersionCount: 0,
PoolVersionCount: 0,
ForumPostCount: 0,
CommentCount: 69,
FlagCount: 0,
FavoriteCount: 1337,
PositiveFeedbackCount: 0,
NeutralFeedbackCount: 0,
NegativeFeedbackCount: 0,
UploadLimit: 0,
ID: 1,
CreatedAt: "2020-04-07T07:16:40.286+02:00",
Name: "MaxMustermannDer69ste",
Level: 0,
BaseUploadLimit: 0,
PostUploadCount: 0,
PostUpdateCount: 0,
NoteUpdateCount: 0,
IsBanned: false,
CanApprovePosts: false,
CanUploadFree: false,
LevelString: "Member",
AvatarID: 7,
}
jsonResponser, err := httpmock.NewJsonResponder(200, userResponse)
response, err := utils.LoadJsonTestData[model.User]("../../../tests/user.json")
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/users/MaxMustermannDer69ste.json", jsonResponser)
responser, err := httpmock.NewJsonResponder(200, response)
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/users/MaxMustermannDer69ste.json", responser)
requestContext := model.RequestContext{
Client: http.Client{},
@ -60,10 +40,10 @@ func TestGetUser(t *testing.T) {
return
}
if user.ID == userResponse.ID && user.Name == userResponse.Name && user.CreatedAt == userResponse.CreatedAt {
if user.ID == response.ID && user.Name == response.Name && user.CreatedAt == response.CreatedAt {
return
}
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", user, userResponse)
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", user, response)
}

View File

@ -2,6 +2,7 @@ package builder
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
@ -11,68 +12,18 @@ func TestGetUsers(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
userResponse := []model.User{
{
WikiPageVersionCount: 0,
ArtistVersionCount: 0,
PoolVersionCount: 0,
ForumPostCount: 0,
CommentCount: 69,
FlagCount: 0,
FavoriteCount: 1337,
PositiveFeedbackCount: 0,
NeutralFeedbackCount: 0,
NegativeFeedbackCount: 0,
UploadLimit: 0,
ID: 1,
CreatedAt: "2020-04-07T07:16:40.286+02:00",
Name: "MaxMustermannDer69ste",
Level: 0,
BaseUploadLimit: 0,
PostUploadCount: 0,
PostUpdateCount: 0,
NoteUpdateCount: 0,
IsBanned: false,
CanApprovePosts: false,
CanUploadFree: false,
LevelString: "Member",
AvatarID: 7,
},
{
WikiPageVersionCount: 0,
ArtistVersionCount: 0,
PoolVersionCount: 0,
ForumPostCount: 0,
CommentCount: 1337,
FlagCount: 0,
FavoriteCount: 69,
PositiveFeedbackCount: 0,
NeutralFeedbackCount: 0,
NegativeFeedbackCount: 0,
UploadLimit: 0,
ID: 1,
CreatedAt: "2020-04-08T07:16:40.286+02:00",
Name: "HollaDieWaldfee",
Level: 0,
BaseUploadLimit: 0,
PostUploadCount: 0,
PostUpdateCount: 0,
NoteUpdateCount: 0,
IsBanned: false,
CanApprovePosts: false,
CanUploadFree: false,
LevelString: "Member",
AvatarID: 16,
},
}
jsonResponser, err := httpmock.NewJsonResponder(200, userResponse)
response, err := utils.LoadJsonTestData[[]model.User]("../../../tests/users.json")
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/users.json", jsonResponser)
responser, err := httpmock.NewJsonResponder(200, response)
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/users.json", responser)
requestContext := model.RequestContext{
Client: http.Client{},
@ -89,10 +40,10 @@ func TestGetUsers(t *testing.T) {
return
}
if len(user) == 2 && user[0].ID == userResponse[0].ID && user[1].Name == userResponse[1].Name {
if user[0].ID == response[0].ID && user[1].Name == response[1].Name {
return
}
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", user, userResponse)
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", user, response)
}

View File

@ -2,6 +2,7 @@ package endpoints
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
@ -11,7 +12,7 @@ func TestGetFavorites(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
response, err := loadJsonTestData[model.PostResponse]("../../../tests/posts.json")
response, err := utils.LoadJsonTestData[model.PostResponse]("../../../tests/posts.json")
if err != nil {
t.Error(err)
return

View File

@ -2,6 +2,7 @@ package endpoints
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
@ -11,7 +12,7 @@ func TestGetNote(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
response, err := loadJsonTestData[model.Note]("../../../tests/note.json")
response, err := utils.LoadJsonTestData[model.Note]("../../../tests/note.json")
if err != nil {
t.Error(err)
return
@ -50,7 +51,7 @@ func TestGetNotes(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
response, err := loadJsonTestData[[]model.Note]("../../../tests/notes.json")
response, err := utils.LoadJsonTestData[[]model.Note]("../../../tests/notes.json")
if err != nil {
t.Error(err)
return

View File

@ -2,6 +2,7 @@ package endpoints
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
@ -11,7 +12,7 @@ func TestGetPool(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
response, err := loadJsonTestData[model.Pool]("../../../tests/pool.json")
response, err := utils.LoadJsonTestData[model.Pool]("../../../tests/pool.json")
if err != nil {
t.Error(err)
return
@ -50,7 +51,7 @@ func TestGetPools(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
response, err := loadJsonTestData[[]model.Pool]("../../../tests/pools.json")
response, err := utils.LoadJsonTestData[[]model.Pool]("../../../tests/pools.json")
if err != nil {
t.Error(err)
return

View File

@ -2,6 +2,7 @@ package endpoints
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
@ -11,7 +12,7 @@ func TestGetPost(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
data, err := loadJsonTestData[model.Post]("../../../tests/post.json")
data, err := utils.LoadJsonTestData[model.Post]("../../../tests/post.json")
if err != nil {
t.Error(err)
return
@ -55,7 +56,7 @@ func TestGetPosts(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
response, err := loadJsonTestData[model.PostResponse]("../../../tests/posts.json")
response, err := utils.LoadJsonTestData[model.PostResponse]("../../../tests/posts.json")
if err != nil {
t.Error(err)
return

View File

@ -2,6 +2,7 @@ package endpoints
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
@ -11,7 +12,7 @@ func TestGetTag(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
response, err := loadJsonTestData[model.Tag]("../../../tests/tag.json")
response, err := utils.LoadJsonTestData[model.Tag]("../../../tests/tag.json")
if err != nil {
t.Error(err)
return

View File

@ -2,6 +2,7 @@ package endpoints
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
@ -11,7 +12,7 @@ func TestGetUser(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
response, err := loadJsonTestData[model.User]("../../../tests/user.json")
response, err := utils.LoadJsonTestData[model.User]("../../../tests/user.json")
if err != nil {
t.Error(err)
return
@ -50,7 +51,7 @@ func TestGetUsers(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
response, err := loadJsonTestData[[]model.User]("../../../tests/users.json")
response, err := utils.LoadJsonTestData[[]model.User]("../../../tests/users.json")
if err != nil {
t.Error(err)
return

View File

@ -1,11 +1,11 @@
package endpoints
package utils
import (
"encoding/json"
"os"
)
func loadJsonTestData[T any](testDataPath string) (T, error) {
func LoadJsonTestData[T any](testDataPath string) (T, error) {
// Create a variable to store the decoded JSON data
var jsonData T