Skip to content

Commit

Permalink
chore: update to latest arikawa
Browse files Browse the repository at this point in the history
  • Loading branch information
mavolin committed Feb 11, 2023
1 parent 68653d4 commit af559f1
Show file tree
Hide file tree
Showing 11 changed files with 331 additions and 85 deletions.
45 changes: 40 additions & 5 deletions dismockgen_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ StartThreadWithoutMessage:
infer_params:
- infer: channelID
from: ParentID
PublicArchivedThreadsBefore:
PublicArchivedThreads:
url_params:
- param: before
type: string
Expand All @@ -226,7 +226,8 @@ PublicArchivedThreadsBefore:
{{.Var}} = {{.Param}}.Format(discord.TimestampFormat)
}
- param: limit
PrivateArchivedThreadsBefore:
omitempty: true
PrivateArchivedThreads:
url_params:
- param: before
type: string
Expand All @@ -236,7 +237,8 @@ PrivateArchivedThreadsBefore:
{{.Var}} = {{.Param}}.Format(discord.TimestampFormat)
}
- param: limit
JoinedPrivateArchivedThreadsBefore:
omitempty: true
JoinedPrivateArchivedThreads:
url_params:
- param: before
type: string
Expand All @@ -246,6 +248,13 @@ JoinedPrivateArchivedThreadsBefore:
{{.Var}} = {{.Param}}.Format(discord.TimestampFormat)
}
- param: limit
omitempty: true
PublicArchivedThreadsBefore:
exclude: true
PrivateArchivedThreadsBefore:
exclude: true
JoinedPrivateArchivedThreadsBefore:
exclude: true


##########################################################################################
Expand Down Expand Up @@ -306,6 +315,10 @@ GuildWidgetImage:

RespondInteraction:
exclude: true
CreateInteractionFollowup:
exclude: true
FollowUpInteraction:
exclude: true


###########################################################################################
Expand Down Expand Up @@ -412,8 +425,8 @@ EditMessageComplex:
exclude: true
DeleteMessages:
exclude: true


#####################################################################################################
######################################## message_reaction.go ########################################
#####################################################################################################
Expand All @@ -440,6 +453,28 @@ ModifyRole:
from: ID


#########################################################################################
################################## scheduled_events.go ##################################
#########################################################################################

ListScheduledEventUsers:
url_params:
- param: limit
omitempty: true
- param: withMember
omitempty: true
- param: before
omitempty: true
- param: after
omitempty: true
ListScheduledEvents:
url_params:
- param: withUserCount
ScheduledEvent:
url_params:
- param: withUserCount


#########################################################################################
######################################## send.go ########################################
#########################################################################################
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/mavolin/dismock/v3
go 1.16

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/diamondburned/arikawa/v3 v3.0.0-rc.5
github.com/diamondburned/arikawa/v3 v3.2.0
github.com/gorilla/schema v1.2.0
github.com/stretchr/testify v1.7.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/stretchr/testify v1.8.1
golang.org/x/time v0.3.0 // indirect
)
26 changes: 14 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/diamondburned/arikawa/v3 v3.0.0-rc.3 h1:Ku3azqmuUJzl1JHCwCdieXFgQ28iDTVkr6BA+H4VfJ0=
github.com/diamondburned/arikawa/v3 v3.0.0-rc.3/go.mod h1:5jBSNnp82Z/EhsKa6Wk9FsOqSxfVkNZDTDBPOj47LpY=
github.com/diamondburned/arikawa/v3 v3.0.0-rc.5 h1:QexNI0czPwovlqBFiDYz4h4l60GOYHPEyWQxe6kQQd8=
github.com/diamondburned/arikawa/v3 v3.0.0-rc.5/go.mod h1:5jBSNnp82Z/EhsKa6Wk9FsOqSxfVkNZDTDBPOj47LpY=
github.com/diamondburned/arikawa/v3 v3.2.0 h1:aBUhg94pxblT6ks4EV7qxEk44tnl0ico67ydqjVnv9g=
github.com/diamondburned/arikawa/v3 v3.2.0/go.mod h1:5jBSNnp82Z/EhsKa6Wk9FsOqSxfVkNZDTDBPOj47LpY=
github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc=
github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211001092434-39dca1131b70 h1:pGleJoyD1yA5HfvuaksHxD0404gsEkNDerKsQ0N0y1s=
golang.org/x/sys v0.0.0-20211001092434-39dca1131b70/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
122 changes: 122 additions & 0 deletions pkg/dismock/custom_mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/diamondburned/arikawa/v3/utils/httputil"
"github.com/diamondburned/arikawa/v3/utils/json/option"
"github.com/diamondburned/arikawa/v3/utils/sendpart"
"github.com/gorilla/schema"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/mavolin/dismock/v3/internal/check"
Expand Down Expand Up @@ -42,6 +44,88 @@ func (m *Mocker) Ack(channelID discord.ChannelID, messageID discord.MessageID, s
})
}

func (m *Mocker) PublicArchivedThreadsBefore(
channelID discord.ChannelID, before discord.Timestamp, limit uint, ret *api.ArchivedThreads,
) {
m.MockAPI("PublicArchivedThreadsBefore", http.MethodGet, "channels/"+channelID.String()+"/threads/archived/public",
func(w http.ResponseWriter, r *http.Request, t testing.TInterface) {
_params := struct {
Before string `schema:"before,omitempty"`
Limit uint `schema:"limit,omitempty"`
}{
Limit: limit,
}

if before.IsValid() {
_params.Before = before.Format(discord.TimestampFormat)
}

var _values url.Values
err := schema.NewEncoder().Encode(_params, _values)
assert.NoError(t, err)

check.Query(t, _values, r.URL.Query())

check.WriteJSON(t, w, ret)
})
}

// PrivateArchivedThreadsBefore mocks api.Client.PrivateArchivedThreadsBefore.
func (m *Mocker) PrivateArchivedThreadsBefore(
channelID discord.ChannelID, before discord.Timestamp, limit uint, ret *api.ArchivedThreads,
) {
m.MockAPI("PrivateArchivedThreadsBefore", http.MethodGet,
"channels/"+channelID.String()+"/threads/archived/private",
func(w http.ResponseWriter, r *http.Request, t testing.TInterface) {
_params := struct {
Before string `schema:"before,omitempty"`
Limit uint `schema:"limit,omitempty"`
}{
Limit: limit,
}

if before.IsValid() {
_params.Before = before.Format(discord.TimestampFormat)
}

var _values url.Values
err := schema.NewEncoder().Encode(_params, _values)
assert.NoError(t, err)

check.Query(t, _values, r.URL.Query())

check.WriteJSON(t, w, ret)
})
}

// JoinedPrivateArchivedThreadsBefore mocks api.Client.JoinedPrivateArchivedThreadsBefore.
func (m *Mocker) JoinedPrivateArchivedThreadsBefore(
channelID discord.ChannelID, before discord.Timestamp, limit uint, ret api.ArchivedThreads,
) {
m.MockAPI("JoinedPrivateArchivedThreadsBefore", http.MethodGet,
"channels/"+channelID.String()+"/users/@me/threads/archived/private",
func(_w http.ResponseWriter, _r *http.Request, _t testing.TInterface) {
_params := struct {
Before string `schema:"before,omitempty"`
Limit uint `schema:"limit,omitempty"`
}{
Limit: limit,
}

if before.IsValid() {
_params.Before = before.Format(discord.TimestampFormat)
}

var _values url.Values
err := schema.NewEncoder().Encode(_params, _values)
assert.NoError(_t, err)

check.Query(_t, _values, _r.URL.Query())

check.WriteJSON(_t, _w, ret)
})
}

// =============================================================================
// guild.go
// =====================================================================================
Expand Down Expand Up @@ -223,6 +307,44 @@ func (m *Mocker) RespondInteraction(id discord.InteractionID, token string, resp
})
}

// CreateInteractionFollowup mocks api.Client.CreateInteractionFollowup.
func (m *Mocker) CreateInteractionFollowup(
appID discord.AppID, token string, resp api.InteractionResponseData, ret discord.Message,
) {
m.MockAPI("CreateInteractionFollowup", http.MethodPost, "webhooks/"+appID.String()+"/"+token+"?",
func(w http.ResponseWriter, r *http.Request, t testing.TInterface) {
if resp.NeedsMultipart() {
files := resp.Files
resp.Files = nil

check.Multipart(t, r.Body, r.Header, resp, files)
} else {
check.JSON(t, resp, r.Body)
}

check.WriteJSON(t, w, ret)
})
}

// FollowUpInteraction mocks api.Client.FollowUpInteraction.
func (m *Mocker) FollowUpInteraction(
appID discord.AppID, token string, resp api.InteractionResponseData, ret discord.Message,
) {
m.MockAPI("FollowUpInteraction", http.MethodPost, "webhooks/"+appID.String()+"/"+token+"?",
func(w http.ResponseWriter, r *http.Request, t testing.TInterface) {
if resp.NeedsMultipart() {
files := resp.Files
resp.Files = nil

check.Multipart(t, r.Body, r.Header, resp, files)
} else {
check.JSON(t, resp, r.Body)
}

check.WriteJSON(t, w, ret)
})
}

// =============================================================================
// members.go
// =====================================================================================
Expand Down
24 changes: 14 additions & 10 deletions pkg/dismock/custom_mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dismock
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"testing"

Expand Down Expand Up @@ -43,16 +43,20 @@ func TestMocker_Error(t *testing.T) {
// =====================================================================================

func TestMocker_Ack(t *testing.T) {
abc := "abc"
def := "def"
ghi := "ghi"

t.Run("success", func(t *testing.T) {
m, s := NewSession(t)

var (
channelID discord.ChannelID = 123
messageID discord.MessageID = 456
ack = api.Ack{Token: "abc"}
ack = api.Ack{Token: &abc}
)

expect := api.Ack{Token: "def"}
expect := api.Ack{Token: &def}
actual := &ack

m.Ack(channelID, messageID, ack, expect)
Expand All @@ -72,11 +76,11 @@ func TestMocker_Ack(t *testing.T) {
messageID discord.MessageID = 456
)

expect := api.Ack{Token: "def"}
expect := api.Ack{Token: &def}

m.Ack(channelID, messageID, api.Ack{Token: "abc"}, expect)
m.Ack(channelID, messageID, api.Ack{Token: &abc}, expect)

actual := &api.Ack{Token: "ghi"}
actual := &api.Ack{Token: &ghi}

err := s.Ack(channelID, messageID, actual)
require.NoError(t, err)
Expand Down Expand Up @@ -399,7 +403,7 @@ func TestMocker_RespondInteraction(t *testing.T) {
// deep copied. Therefore, we create two readers using the data from the original
// reader.
for i, f := range c.resp.Data.Files {
b, err := ioutil.ReadAll(f.Reader)
b, err := io.ReadAll(f.Reader)
require.NoError(t, err)

cp.Data.Files[i].Reader = bytes.NewBuffer(b)
Expand Down Expand Up @@ -1822,7 +1826,7 @@ func TestMocker_SendMessageComplex(t *testing.T) {
// deep copied. therefore we create two readers using the data from the original
// reader
for i, f := range c.data.Files {
b, err := ioutil.ReadAll(f.Reader)
b, err := io.ReadAll(f.Reader)
require.NoError(t, err)

cp.Files[i].Reader = bytes.NewBuffer(b)
Expand Down Expand Up @@ -1924,7 +1928,7 @@ func TestMocker_ExecuteWebhook(t *testing.T) {
// deep copied. therefore we create two readers using the data from the original
// reader
for i, f := range c.data.Files {
b, err := ioutil.ReadAll(f.Reader)
b, err := io.ReadAll(f.Reader)
require.NoError(t, err)

cp.Files[i].Reader = bytes.NewBuffer(b)
Expand Down Expand Up @@ -2030,7 +2034,7 @@ func TestMocker_ExecuteWebhookAndWait(t *testing.T) {
// deep copied. therefore we create two readers using the data from the original
// reader
for i, f := range c.data.Files {
b, err := ioutil.ReadAll(f.Reader)
b, err := io.ReadAll(f.Reader)
require.NoError(t, err)

cp.Files[i].Reader = bytes.NewBuffer(b)
Expand Down
Loading

0 comments on commit af559f1

Please sign in to comment.