refactor: tests use premade json files to test against.
Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
parent
34b7b9346f
commit
517c7f595e
@ -2,6 +2,7 @@ package builder
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
||||||
"github.com/jarcoal/httpmock"
|
"github.com/jarcoal/httpmock"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@ -11,109 +12,13 @@ func TestGetFavorites(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
postResponse := model.PostResponse{
|
response, err := utils.LoadJsonTestData[model.PostResponse]("../../../tests/posts.json")
|
||||||
Post: model.Post{},
|
if err != nil {
|
||||||
Posts: []model.Post{
|
t.Error(err)
|
||||||
{
|
return
|
||||||
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)
|
jsonResponser, err := httpmock.NewJsonResponder(200, response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
@ -134,10 +39,10 @@ func TestGetFavorites(t *testing.T) {
|
|||||||
return
|
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
|
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package builder
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
||||||
"github.com/jarcoal/httpmock"
|
"github.com/jarcoal/httpmock"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@ -11,28 +12,18 @@ func TestGetNote(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
noteResponse := model.Note{
|
response, err := utils.LoadJsonTestData[model.Note]("../../../tests/note.json")
|
||||||
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, isn’t it just right to use them?",
|
|
||||||
CreatorName: "ponypussypounder",
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonResponser, err := httpmock.NewJsonResponder(200, noteResponse)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
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{
|
requestContext := model.RequestContext{
|
||||||
Client: http.Client{},
|
Client: http.Client{},
|
||||||
@ -49,10 +40,10 @@ func TestGetNote(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if pool.ID == noteResponse.ID && pool.Body == noteResponse.Body {
|
if pool.ID == response.ID && pool.Body == response.Body {
|
||||||
return
|
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package builder
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
||||||
"github.com/jarcoal/httpmock"
|
"github.com/jarcoal/httpmock"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@ -11,60 +12,18 @@ func TestGetNotes(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
noteResponse := []model.Note{
|
response, err := utils.LoadJsonTestData[[]model.Note]("../../../tests/notes.json")
|
||||||
{
|
|
||||||
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, isn’t 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, isn’t 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, isn’t it just right to use them?",
|
|
||||||
CreatorName: "ponypussypounder",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonResponser, err := httpmock.NewJsonResponder(200, noteResponse)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
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{
|
requestContext := model.RequestContext{
|
||||||
Client: http.Client{},
|
Client: http.Client{},
|
||||||
@ -81,10 +40,10 @@ func TestGetNotes(t *testing.T) {
|
|||||||
return
|
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
|
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package builder
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
||||||
"github.com/jarcoal/httpmock"
|
"github.com/jarcoal/httpmock"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@ -11,26 +12,18 @@ func TestGetPool(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
poolResponse := model.Pool{
|
response, err := utils.LoadJsonTestData[model.Pool]("../../../tests/pool.json")
|
||||||
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 didn’t have to~",
|
|
||||||
IsActive: true,
|
|
||||||
Category: "series",
|
|
||||||
PostIDS: nil,
|
|
||||||
CreatorName: "2DUK",
|
|
||||||
PostCount: 11,
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonResponser, err := httpmock.NewJsonResponder(200, poolResponse)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
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{
|
requestContext := model.RequestContext{
|
||||||
Client: http.Client{},
|
Client: http.Client{},
|
||||||
@ -47,10 +40,10 @@ func TestGetPool(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if pool.ID == poolResponse.ID && pool.Name == poolResponse.Name {
|
if pool.ID == response.ID && pool.Name == response.Name {
|
||||||
return
|
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package builder
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
||||||
"github.com/jarcoal/httpmock"
|
"github.com/jarcoal/httpmock"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@ -11,67 +12,17 @@ func TestGetPools(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
poolResponse := []model.Pool{
|
response, err := utils.LoadJsonTestData[[]model.Pool]("../../../tests/pools.json")
|
||||||
{
|
|
||||||
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 didn’t 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 didn’t 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 didn’t 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 didn’t have to~",
|
|
||||||
IsActive: true,
|
|
||||||
Category: "series",
|
|
||||||
PostIDS: nil,
|
|
||||||
CreatorName: "2DUK",
|
|
||||||
PostCount: 11,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonResponser, err := httpmock.NewJsonResponder(200, poolResponse)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
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{
|
requestContext := model.RequestContext{
|
||||||
Client: http.Client{},
|
Client: http.Client{},
|
||||||
@ -88,10 +39,10 @@ func TestGetPools(t *testing.T) {
|
|||||||
return
|
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
|
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package builder
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
||||||
"github.com/jarcoal/httpmock"
|
"github.com/jarcoal/httpmock"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@ -11,48 +12,23 @@ func TestGetPost(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
postResponse := model.PostResponse{
|
data, err := utils.LoadJsonTestData[model.Post]("../../../tests/post.json")
|
||||||
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 {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
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{
|
requestContext := model.RequestContext{
|
||||||
Client: http.Client{},
|
Client: http.Client{},
|
||||||
@ -69,10 +45,10 @@ func TestGetPost(t *testing.T) {
|
|||||||
return
|
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
|
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package builder
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
||||||
"github.com/jarcoal/httpmock"
|
"github.com/jarcoal/httpmock"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@ -11,114 +12,18 @@ func TestGetPosts(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
postResponse := model.PostResponse{
|
response, err := utils.LoadJsonTestData[model.PostResponse]("../../../tests/posts.json")
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
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{
|
requestContext := model.RequestContext{
|
||||||
Client: http.Client{},
|
Client: http.Client{},
|
||||||
@ -135,10 +40,10 @@ func TestGetPosts(t *testing.T) {
|
|||||||
return
|
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
|
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package builder
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
||||||
"github.com/jarcoal/httpmock"
|
"github.com/jarcoal/httpmock"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@ -11,24 +12,18 @@ func TestGetTag(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
tagResponse := model.Tag{
|
response, err := utils.LoadJsonTestData[model.Tag]("../../../tests/tag.json")
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
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{
|
requestContext := model.RequestContext{
|
||||||
Client: http.Client{},
|
Client: http.Client{},
|
||||||
@ -45,10 +40,10 @@ func TestGetTag(t *testing.T) {
|
|||||||
return
|
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
|
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package builder
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
||||||
"github.com/jarcoal/httpmock"
|
"github.com/jarcoal/httpmock"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@ -11,39 +12,18 @@ func TestGetUser(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
userResponse := model.User{
|
response, err := utils.LoadJsonTestData[model.User]("../../../tests/user.json")
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
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{
|
requestContext := model.RequestContext{
|
||||||
Client: http.Client{},
|
Client: http.Client{},
|
||||||
@ -60,10 +40,10 @@ func TestGetUser(t *testing.T) {
|
|||||||
return
|
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
|
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package builder
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
||||||
"github.com/jarcoal/httpmock"
|
"github.com/jarcoal/httpmock"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@ -11,68 +12,18 @@ func TestGetUsers(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
userResponse := []model.User{
|
response, err := utils.LoadJsonTestData[[]model.User]("../../../tests/users.json")
|
||||||
{
|
|
||||||
|
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
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{
|
requestContext := model.RequestContext{
|
||||||
Client: http.Client{},
|
Client: http.Client{},
|
||||||
@ -89,10 +40,10 @@ func TestGetUsers(t *testing.T) {
|
|||||||
return
|
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
|
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package endpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
||||||
"github.com/jarcoal/httpmock"
|
"github.com/jarcoal/httpmock"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@ -11,7 +12,7 @@ func TestGetFavorites(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
response, err := loadJsonTestData[model.PostResponse]("../../../tests/posts.json")
|
response, err := utils.LoadJsonTestData[model.PostResponse]("../../../tests/posts.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
|
@ -2,6 +2,7 @@ package endpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
||||||
"github.com/jarcoal/httpmock"
|
"github.com/jarcoal/httpmock"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@ -11,7 +12,7 @@ func TestGetNote(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
response, err := loadJsonTestData[model.Note]("../../../tests/note.json")
|
response, err := utils.LoadJsonTestData[model.Note]("../../../tests/note.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
@ -50,7 +51,7 @@ func TestGetNotes(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
response, err := loadJsonTestData[[]model.Note]("../../../tests/notes.json")
|
response, err := utils.LoadJsonTestData[[]model.Note]("../../../tests/notes.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
|
@ -2,6 +2,7 @@ package endpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
||||||
"github.com/jarcoal/httpmock"
|
"github.com/jarcoal/httpmock"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@ -11,7 +12,7 @@ func TestGetPool(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
response, err := loadJsonTestData[model.Pool]("../../../tests/pool.json")
|
response, err := utils.LoadJsonTestData[model.Pool]("../../../tests/pool.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
@ -50,7 +51,7 @@ func TestGetPools(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
response, err := loadJsonTestData[[]model.Pool]("../../../tests/pools.json")
|
response, err := utils.LoadJsonTestData[[]model.Pool]("../../../tests/pools.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
|
@ -2,6 +2,7 @@ package endpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
||||||
"github.com/jarcoal/httpmock"
|
"github.com/jarcoal/httpmock"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@ -11,7 +12,7 @@ func TestGetPost(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
data, err := loadJsonTestData[model.Post]("../../../tests/post.json")
|
data, err := utils.LoadJsonTestData[model.Post]("../../../tests/post.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
@ -55,7 +56,7 @@ func TestGetPosts(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
response, err := loadJsonTestData[model.PostResponse]("../../../tests/posts.json")
|
response, err := utils.LoadJsonTestData[model.PostResponse]("../../../tests/posts.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
|
@ -2,6 +2,7 @@ package endpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
||||||
"github.com/jarcoal/httpmock"
|
"github.com/jarcoal/httpmock"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@ -11,7 +12,7 @@ func TestGetTag(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
response, err := loadJsonTestData[model.Tag]("../../../tests/tag.json")
|
response, err := utils.LoadJsonTestData[model.Tag]("../../../tests/tag.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
|
@ -2,6 +2,7 @@ package endpoints
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
||||||
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
||||||
"github.com/jarcoal/httpmock"
|
"github.com/jarcoal/httpmock"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@ -11,7 +12,7 @@ func TestGetUser(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
response, err := loadJsonTestData[model.User]("../../../tests/user.json")
|
response, err := utils.LoadJsonTestData[model.User]("../../../tests/user.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
@ -50,7 +51,7 @@ func TestGetUsers(t *testing.T) {
|
|||||||
httpmock.Activate()
|
httpmock.Activate()
|
||||||
defer httpmock.DeactivateAndReset()
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
response, err := loadJsonTestData[[]model.User]("../../../tests/users.json")
|
response, err := utils.LoadJsonTestData[[]model.User]("../../../tests/users.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package endpoints
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"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
|
// Create a variable to store the decoded JSON data
|
||||||
var jsonData T
|
var jsonData T
|
||||||
|
|
Reference in New Issue
Block a user