{"id":22351051,"url":"https://github.com/ewohltman/discordgo-mock","last_synced_at":"2025-10-29T06:02:08.423Z","repository":{"id":42015764,"uuid":"369630877","full_name":"ewohltman/discordgo-mock","owner":"ewohltman","description":"Helper library to assist with writing unit tests for projects that use https://github.com/bwmarrin/discordgo","archived":false,"fork":false,"pushed_at":"2024-04-02T20:03:28.000Z","size":64,"stargazers_count":17,"open_issues_count":1,"forks_count":3,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-06-19T05:37:46.040Z","etag":null,"topics":["discord","discord-bot","discordgo","go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ewohltman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-21T19:07:57.000Z","updated_at":"2024-06-03T15:56:06.000Z","dependencies_parsed_at":"2023-01-25T23:01:43.339Z","dependency_job_id":"159884bd-2a9e-47f5-b9d9-8c1c61623a17","html_url":"https://github.com/ewohltman/discordgo-mock","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ewohltman%2Fdiscordgo-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ewohltman%2Fdiscordgo-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ewohltman%2Fdiscordgo-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ewohltman%2Fdiscordgo-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ewohltman","download_url":"https://codeload.github.com/ewohltman/discordgo-mock/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228106545,"owners_count":17870437,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discord","discord-bot","discordgo","go","golang"],"created_at":"2024-12-04T12:12:28.554Z","updated_at":"2025-10-29T06:02:08.367Z","avatar_url":"https://github.com/ewohltman.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# discordgo-mock\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/ewohltman/discordgo-mock.svg)](https://pkg.go.dev/github.com/ewohltman/discordgo-mock)\n\n`discordgo-mock` is a helper library to assist with writing unit tests for\nprojects that use [discordgo](https://github.com/bwmarrin/discordgo). The\nlibrary provides a custom `http.RoundTripper` to be injected into an\n`*http.Client.Transport` before being injected into `discordgo.Session`.\n\nThe custom `http.RoundTripper` maps the Discord REST API methods and paths to\nappropriate handler functions and returns expected data based upon what is in\nthe provided `discordgo.State` cache. Discord API calls that involve creating\nnew, updating, or deleting resources will also update the internal\n`discordgo.State` cache to maintain state changes.\n\n## Example Usage\n\n```go\npackage mocksession_test\n\nimport (\n\t\"net/http\"\n\t\"testing\"\n\n\t\"github.com/bwmarrin/discordgo\"\n\t\"github.com/ewohltman/discordgo-mock/mockchannel\"\n\t\"github.com/ewohltman/discordgo-mock/mockconstants\"\n\t\"github.com/ewohltman/discordgo-mock/mockguild\"\n\t\"github.com/ewohltman/discordgo-mock/mockmember\"\n\t\"github.com/ewohltman/discordgo-mock/mockrest\"\n\t\"github.com/ewohltman/discordgo-mock/mockrole\"\n\t\"github.com/ewohltman/discordgo-mock/mocksession\"\n\t\"github.com/ewohltman/discordgo-mock/mockstate\"\n\t\"github.com/ewohltman/discordgo-mock/mockuser\"\n)\n\nfunc TestNew(t *testing.T) {\n\tstate, err := newState()\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\n\tsession, err := mocksession.New(\n\t\tmocksession.WithState(state),\n\t\tmocksession.WithClient(\u0026http.Client{\n\t\t\tTransport: mockrest.NewTransport(state),\n\t\t}),\n\t)\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\n\tguildBefore, err := session.Guild(mockconstants.TestGuild)\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\n\tt.Logf(\"Name: %s\", guildBefore.Name)\n\tt.Logf(\"Channels: %d\", len(guildBefore.Channels))\n\tt.Logf(\"Members: %d\", guildBefore.MemberCount)\n\n\tt.Logf(\"Roles before change: %d\", len(guildBefore.Roles))\n\n\t_, err = session.GuildRoleCreate(guildBefore.ID)\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\n\tguildAfter, err := session.Guild(mockconstants.TestGuild)\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\n\tt.Logf(\"Roles after change: %d\", len(guildAfter.Roles))\n}\n\nfunc newState() (*discordgo.State, error) {\n\trole := mockrole.New(\n\t\tmockrole.WithID(mockconstants.TestRole),\n\t\tmockrole.WithName(mockconstants.TestRole),\n\t\tmockrole.WithPermissions(discordgo.PermissionViewChannel),\n\t)\n\n\tbotUser := mockuser.New(\n\t\tmockuser.WithID(mockconstants.TestUser+\"Bot\"),\n\t\tmockuser.WithUsername(mockconstants.TestUser+\"Bot\"),\n\t\tmockuser.WithBotFlag(true),\n\t)\n\n\tbotMember := mockmember.New(\n\t\tmockmember.WithUser(botUser),\n\t\tmockmember.WithGuildID(mockconstants.TestGuild),\n\t\tmockmember.WithRoles(role),\n\t)\n\n\tuserMember := mockmember.New(\n\t\tmockmember.WithUser(mockuser.New(\n\t\t\tmockuser.WithID(mockconstants.TestUser),\n\t\t\tmockuser.WithUsername(mockconstants.TestUser),\n\t\t)),\n\t\tmockmember.WithGuildID(mockconstants.TestGuild),\n\t\tmockmember.WithRoles(role),\n\t)\n\n\tchannel := mockchannel.New(\n\t\tmockchannel.WithID(mockconstants.TestChannel),\n\t\tmockchannel.WithGuildID(mockconstants.TestGuild),\n\t\tmockchannel.WithName(mockconstants.TestChannel),\n\t\tmockchannel.WithType(discordgo.ChannelTypeGuildVoice),\n\t)\n\n\tprivateChannel := mockchannel.New(\n\t\tmockchannel.WithID(mockconstants.TestPrivateChannel),\n\t\tmockchannel.WithGuildID(mockconstants.TestGuild),\n\t\tmockchannel.WithName(mockconstants.TestPrivateChannel),\n\t\tmockchannel.WithType(discordgo.ChannelTypeGuildVoice),\n\t\tmockchannel.WithPermissionOverwrites(\u0026discordgo.PermissionOverwrite{\n\t\t\tID:   botMember.User.ID,\n\t\t\tType: discordgo.PermissionOverwriteTypeMember,\n\t\t\tDeny: discordgo.PermissionViewChannel,\n\t\t}),\n\t)\n\n\treturn mockstate.New(\n\t\tmockstate.WithUser(botUser),\n\t\tmockstate.WithGuilds(\n\t\t\tmockguild.New(\n\t\t\t\tmockguild.WithID(mockconstants.TestGuild),\n\t\t\t\tmockguild.WithName(mockconstants.TestGuild),\n\t\t\t\tmockguild.WithRoles(role),\n\t\t\t\tmockguild.WithChannels(channel, privateChannel),\n\t\t\t\tmockguild.WithMembers(botMember, userMember),\n\t\t\t),\n\t\t),\n\t)\n}\n```\n\nOutput:\n```\n=== RUN   TestNew\n    mocksession_test.go:40: Name: testGuild\n    mocksession_test.go:41: Channels: 2\n    mocksession_test.go:42: Members: 2\n    mocksession_test.go:44: Roles before change: 1\n    mocksession_test.go:56: Roles after change: 2\n--- PASS: TestNew (0.00s)\nPASS\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fewohltman%2Fdiscordgo-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fewohltman%2Fdiscordgo-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fewohltman%2Fdiscordgo-mock/lists"}