Alphyron
214aaceee0
All checks were successful
Gitea Build Check / Build (pull_request) Successful in 35s
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package builder
|
|
|
|
import (
|
|
"git.anthrove.art/Anthrove/e621-sdk-go/pkg/e621/model"
|
|
"git.anthrove.art/Anthrove/e621-sdk-go/pkg/e621/utils"
|
|
"github.com/jarcoal/httpmock"
|
|
"net/http"
|
|
"testing"
|
|
)
|
|
|
|
func TestGetUser(t *testing.T) {
|
|
httpmock.Activate()
|
|
defer httpmock.DeactivateAndReset()
|
|
|
|
response, err := utils.LoadJsonTestData[model.User]("../../../tests/user.json")
|
|
if err != nil {
|
|
t.Error(err)
|
|
return
|
|
}
|
|
|
|
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{},
|
|
Host: "https://e621.net",
|
|
UserAgent: "Go-e621-SDK (@username)",
|
|
Username: "memo",
|
|
APIKey: "123456",
|
|
}
|
|
|
|
GetUser := NewGetUserBuilder(requestContext)
|
|
user, err := GetUser.SetUsername("MaxMustermannDer69ste").Execute()
|
|
if err != nil {
|
|
t.Error(err)
|
|
return
|
|
}
|
|
|
|
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, response)
|
|
|
|
}
|