Skip to content

Commit 87ed6ed

Browse files
committed
Replace go-github-mock with githubApiMock
Signed-off-by: Timo Sand <[email protected]>
1 parent 4a72832 commit 87ed6ed

202 files changed

Lines changed: 54 additions & 80212 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

github/resource_github_emu_group_mapping_migration_test.go

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package github
22

33
import (
4+
"fmt"
45
"net/http"
6+
"net/url"
57
"strconv"
68
"testing"
79

810
"github.com/google/go-cmp/cmp"
911
"github.com/google/go-github/v82/github"
1012
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
11-
12-
"github.com/migueleliasweb/go-github-mock/src/mock"
1313
)
1414

1515
type (
@@ -41,30 +41,38 @@ func testResourceGithubEMUGroupMappingInstanceStateDataV1(t *testing.T) map[stri
4141
return v0
4242
}
4343

44-
func buildMockClientForMigrationV0toV1() *http.Client {
45-
return mock.NewMockedHTTPClient(
46-
mock.WithRequestMatch(
47-
mock.GetOrgsTeamsExternalGroupsByOrgByTeamSlug,
48-
github.ExternalGroupList{
49-
Groups: []*github.ExternalGroup{
50-
{
51-
GroupID: github.Ptr(int64(testGroupID)),
52-
Teams: []*github.ExternalGroupTeam{
53-
{
54-
TeamID: github.Ptr(int64(testTeamID)),
55-
},
56-
},
57-
},
58-
},
44+
func buildMockResponsesForMigrationV0toV1() []*mockResponse {
45+
return []*mockResponse{
46+
{
47+
ExpectedUri: fmt.Sprintf("/orgs/%s/teams/%s/external-groups", "test-org", "test-team"),
48+
ExpectedHeaders: map[string]string{
49+
"Accept": "application/vnd.github.v3+json",
5950
},
60-
),
61-
mock.WithRequestMatch(
62-
mock.GetOrgsTeamsByOrgByTeamSlug,
63-
github.Team{
64-
ID: github.Ptr(int64(testTeamID)),
51+
ResponseBody: fmt.Sprintf(`
52+
{
53+
"groups": [
54+
{
55+
"group_id": %d,
56+
"group_name": "test-group",
57+
"updated_at": "2021-01-24T11:31:04-06:00"
58+
}
59+
]
60+
}`, int64(testGroupID)),
61+
StatusCode: 201,
62+
},
63+
{
64+
ExpectedUri: fmt.Sprintf("/orgs/%s/teams/%s", "test-org", "test-team"),
65+
ExpectedHeaders: map[string]string{
66+
"Accept": "application/vnd.github.v3+json",
6567
},
66-
),
67-
)
68+
ResponseBody: fmt.Sprintf(`
69+
{
70+
"id": %d
71+
}
72+
`, testTeamID),
73+
StatusCode: 200,
74+
},
75+
}
6876
}
6977

7078
func TestGithub_MigrateEMUGroupMappingsState(t *testing.T) {
@@ -75,27 +83,35 @@ func TestGithub_MigrateEMUGroupMappingsState(t *testing.T) {
7583
}
7684

7785
for _, d := range []struct {
78-
testName string
79-
migrationFunc schema.StateUpgradeFunc
80-
rawState currentStateFunc
81-
want expectedStateFunc
82-
buildClient func() *http.Client
83-
shouldError bool
86+
testName string
87+
migrationFunc schema.StateUpgradeFunc
88+
rawState currentStateFunc
89+
want expectedStateFunc
90+
buildMockResponses func() []*mockResponse
91+
shouldError bool
8492
}{
8593
{
86-
testName: "migrates v0 to v1",
87-
migrationFunc: resourceGithubEMUGroupMappingInstanceStateUpgradeV0,
88-
rawState: testResourceGithubEMUGroupMappingInstanceStateDataV0,
89-
want: testResourceGithubEMUGroupMappingInstanceStateDataV1,
90-
buildClient: buildMockClientForMigrationV0toV1,
91-
shouldError: false,
94+
testName: "migrates v0 to v1",
95+
migrationFunc: resourceGithubEMUGroupMappingInstanceStateUpgradeV0,
96+
rawState: testResourceGithubEMUGroupMappingInstanceStateDataV0,
97+
want: testResourceGithubEMUGroupMappingInstanceStateDataV1,
98+
buildMockResponses: buildMockResponsesForMigrationV0toV1,
99+
shouldError: false,
92100
},
93101
} {
94102
t.Run(d.testName, func(t *testing.T) {
95103
t.Parallel()
96104

97-
ghClient := github.NewClient(d.buildClient())
98-
meta.v3client = ghClient
105+
ts := githubApiMock(d.buildMockResponses())
106+
defer ts.Close()
107+
108+
httpCl := http.DefaultClient
109+
httpCl.Transport = http.DefaultTransport
110+
111+
client := github.NewClient(httpCl)
112+
u, _ := url.Parse(ts.URL + "/")
113+
client.BaseURL = u
114+
meta.v3client = client
99115

100116
currentState := d.rawState()
101117
got, err := d.migrationFunc(t.Context(), currentState, meta)

go.mod

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ require (
1010
github.com/hashicorp/go-cty v1.5.0
1111
github.com/hashicorp/terraform-plugin-log v0.10.0
1212
github.com/hashicorp/terraform-plugin-sdk/v2 v2.38.1
13-
github.com/migueleliasweb/go-github-mock v1.5.0
1413
github.com/shurcooL/githubv4 v0.0.0-20221126192849-0b5c4c7994eb
1514
github.com/stretchr/testify v1.11.1
1615
golang.org/x/crypto v0.47.0
@@ -25,9 +24,7 @@ require (
2524
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
2625
github.com/fatih/color v1.18.0 // indirect
2726
github.com/golang/protobuf v1.5.4 // indirect
28-
github.com/google/go-github/v73 v73.0.0 // indirect
2927
github.com/google/go-querystring v1.2.0 // indirect
30-
github.com/gorilla/mux v1.8.1 // indirect
3128
github.com/hashicorp/errwrap v1.0.0 // indirect
3229
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
3330
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
@@ -66,7 +63,6 @@ require (
6663
golang.org/x/sync v0.19.0 // indirect
6764
golang.org/x/sys v0.40.0 // indirect
6865
golang.org/x/text v0.33.0 // indirect
69-
golang.org/x/time v0.11.0 // indirect
7066
golang.org/x/tools v0.40.0 // indirect
7167
google.golang.org/appengine v1.6.8 // indirect
7268
google.golang.org/genproto/googleapis/rpc v0.0.0-20250818200422-3122310a409c // indirect

go.sum

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,12 @@ github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
5252
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
5353
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
5454
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
55-
github.com/google/go-github/v73 v73.0.0 h1:aR+Utnh+Y4mMkS+2qLQwcQ/cF9mOTpdwnzlaw//rG24=
56-
github.com/google/go-github/v73 v73.0.0/go.mod h1:fa6w8+/V+edSU0muqdhCVY7Beh1M8F1IlQPZIANKIYw=
5755
github.com/google/go-github/v82 v82.0.0 h1:OH09ESON2QwKCUVMYmMcVu1IFKFoaZHwqYaUtr/MVfk=
5856
github.com/google/go-github/v82 v82.0.0/go.mod h1:hQ6Xo0VKfL8RZ7z1hSfB4fvISg0QqHOqe9BP0qo+WvM=
5957
github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfhIxNtP0=
6058
github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU=
6159
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
6260
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
63-
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
64-
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
6561
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
6662
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
6763
github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU=
@@ -127,8 +123,6 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
127123
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
128124
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
129125
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
130-
github.com/migueleliasweb/go-github-mock v1.5.0 h1:dIr6vgVz8QY9sDiDopWxk6pDw4d7K/xIcCk/NQe4ajM=
131-
github.com/migueleliasweb/go-github-mock v1.5.0/go.mod h1:/DUmhXkxrgVlDOVBqGoUXkV4w0ms5n1jDQHotYm135o=
132126
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
133127
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
134128
github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU=
@@ -244,8 +238,6 @@ golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
244238
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
245239
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
246240
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
247-
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
248-
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
249241
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
250242
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
251243
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=

0 commit comments

Comments
 (0)