From 1513ee6421fd92848b29e2c766fc6bbde59978f0 Mon Sep 17 00:00:00 2001 From: Nish Krishnan Date: Tue, 5 Jan 2021 18:21:31 -0500 Subject: [PATCH] Add support for fetching gh app user. (#30) (#1334) * Add support for fetching gh app user. (#30) * Upgrade pegomock. * go mod vendor. --- cmd/server.go | 4 + cmd/server_test.go | 1 + go.mod | 2 +- go.sum | 13 +- server/events/vcs/fixtures/fixtures.go | 55 ++- server/events/vcs/github_client.go | 11 +- server/events/vcs/github_credentials.go | 36 +- server/events/vcs/github_credentials_test.go | 35 ++ .../vcs/mocks/matchers/ptr_to_http_client.go | 15 +- .../vcs/mocks/mock_github_credentials.go | 18 +- server/server.go | 1 + server/user_config.go | 1 + .../petergtz/pegomock/.goreleaser.yml | 4 +- vendor/github.com/petergtz/pegomock/README.md | 13 +- vendor/github.com/petergtz/pegomock/dsl.go | 48 +- .../github.com/petergtz/pegomock/matcher.go | 18 +- .../petergtz/pegomock/matcher_factories.go | 467 +++++++++++++++++- vendor/modules.txt | 2 +- 18 files changed, 681 insertions(+), 63 deletions(-) diff --git a/cmd/server.go b/cmd/server.go index 9f8832d78..1ec9ab9ba 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -61,6 +61,7 @@ const ( GHUserFlag = "gh-user" GHAppIDFlag = "gh-app-id" GHAppKeyFileFlag = "gh-app-key-file" + GHAppSlugFlag = "gh-app-slug" GHOrganizationFlag = "gh-org" GHWebhookSecretFlag = "gh-webhook-secret" // nolint: gosec GitlabHostnameFlag = "gitlab-hostname" @@ -181,6 +182,9 @@ var stringFlags = map[string]stringFlag{ description: "A path to a file containing the GitHub App's private key", defaultValue: "", }, + GHAppSlugFlag: { + description: "The Github app slug (ie. the URL-friendly name of your GitHub App)", + }, GHOrganizationFlag: { description: "The name of the GitHub organization to use during the creation of a Github App for Atlantis", defaultValue: "", diff --git a/cmd/server_test.go b/cmd/server_test.go index d5b66614b..d41c748c8 100644 --- a/cmd/server_test.go +++ b/cmd/server_test.go @@ -72,6 +72,7 @@ var testFlags = map[string]interface{}{ GHUserFlag: "user", GHAppIDFlag: int64(0), GHAppKeyFileFlag: "", + GHAppSlugFlag: "atlantis", GHOrganizationFlag: "", GHWebhookSecretFlag: "secret", GitlabHostnameFlag: "gitlab-hostname", diff --git a/go.mod b/go.mod index e8e956381..2d15c2053 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ require ( github.com/nlopes/slack v0.1.0 github.com/onsi/ginkgo v1.9.0 // indirect github.com/onsi/gomega v1.4.3 // indirect - github.com/petergtz/pegomock v2.8.0+incompatible + github.com/petergtz/pegomock v2.9.0+incompatible github.com/pkg/errors v0.9.1 github.com/remeh/sizedwaitgroup v1.0.0 github.com/shurcooL/githubv4 v0.0.0-20191127044304-8f68eb5628d0 diff --git a/go.sum b/go.sum index 62fa09146..a1dfef6cf 100644 --- a/go.sum +++ b/go.sum @@ -269,8 +269,8 @@ github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFSt github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= -github.com/petergtz/pegomock v2.8.0+incompatible h1:xRKfBK+COYde7M4WzWPJM2nuIwO387NkFivWuxiBRxI= -github.com/petergtz/pegomock v2.8.0+incompatible/go.mod h1:nuBLWZpVyv/fLo56qTwt/AUau7jgouO1h7bEvZCq82o= +github.com/petergtz/pegomock v2.9.0+incompatible h1:BKfb5XfkJfehe5T+O1xD4Zm26Sb9dnRj7tHxLYwUPiI= +github.com/petergtz/pegomock v2.9.0+incompatible/go.mod h1:nuBLWZpVyv/fLo56qTwt/AUau7jgouO1h7bEvZCq82o= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -317,7 +317,6 @@ github.com/spf13/cobra v0.0.0-20170905172051-b78744579491/go.mod h1:1l0Ry5zgKvJa github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= @@ -327,7 +326,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= @@ -344,7 +342,6 @@ github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6Ac github.com/xanzy/go-gitlab v0.34.1 h1:Dtqla2gWIQIevfZVS6FY4qjgrKf+5LYLzW6XBNstGSw= github.com/xanzy/go-gitlab v0.34.1/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= -github.com/zclconf/go-cty v1.1.0 h1:uJwc9HiBOCpoKIObTQaLR+tsEXx1HBHnOsOOpcdhZgw= github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s= github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= github.com/zclconf/go-cty v1.5.1 h1:oALUZX+aJeEBUe2a1+uD2+UTaYfEjnKFDEMRydkGvWE= @@ -364,7 +361,6 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200403201458-baeed622b8d8 h1:fpnn/HnJONpIu6hkXi1u/7rR0NzilgWr4T0JmWkEitk= golang.org/x/crypto v0.0.0-20200403201458-baeed622b8d8/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200414173820-0848c9571904 h1:bXoxMPcSLOq08zI3/c5dEBT6lE4eh+jOh886GHrn6V8= golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -411,7 +407,6 @@ golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAG golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20191122200657-5d9234df094c h1:HjRaKPaiWks0f5tA6ELVF7ZfqSppfPwOEEAvsrKUTO4= golang.org/x/oauth2 v0.0.0-20191122200657-5d9234df094c/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -440,7 +435,6 @@ golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfru golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -472,7 +466,6 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.9.0 h1:jbyannxz0XFD3zdjgrSUsaJbgpH4eTrkdhRChkHPfO8= google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= google.golang.org/api v0.13.0 h1:Q3Ui3V3/CVinFWFiW39Iw0kMuVrRzYX0wN6OPFp0lTA= google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= @@ -489,7 +482,6 @@ google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a h1:Ob5/580gVHBJZgXnff1cZDbG+xLtMVE5mDRTe+nIsX4= @@ -517,7 +509,6 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= diff --git a/server/events/vcs/fixtures/fixtures.go b/server/events/vcs/fixtures/fixtures.go index 0f9f2c331..5bd935ba4 100644 --- a/server/events/vcs/fixtures/fixtures.go +++ b/server/events/vcs/fixtures/fixtures.go @@ -332,7 +332,7 @@ var githubAppInstallationJSON = `[ // nolint: gosec var githubAppTokenJSON = `{ - "token": "v1.1f699f1069f60xx%d", + "token": "some-token", "expires_at": "2050-01-01T00:00:00Z", "permissions": { "issues": "write", @@ -452,6 +452,48 @@ var githubAppTokenJSON = `{ ] }` +var githubAppJSON = `{ + "id": 1, + "slug": "octoapp", + "node_id": "MDExOkludGVncmF0aW9uMQ==", + "owner": { + "login": "github", + "id": 1, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=", + "url": "https://api.github.com/orgs/github", + "repos_url": "https://api.github.com/orgs/github/repos", + "events_url": "https://api.github.com/orgs/github/events", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": true + }, + "name": "Octocat App", + "description": "", + "external_url": "https://example.com", + "html_url": "https://github.com/apps/octoapp", + "created_at": "2017-07-08T16:18:44-04:00", + "updated_at": "2017-07-08T16:18:44-04:00", + "permissions": { + "metadata": "read", + "contents": "read", + "issues": "write", + "single_file": "write" + }, + "events": [ + "push", + "pull_request" + ] + }` + func validateGithubToken(tokenString string) error { key, err := jwt.ParseRSAPrivateKeyFromPEM([]byte(GithubPrivateKey)) if err != nil { @@ -499,6 +541,17 @@ func GithubAppTestServer(t *testing.T) (string, error) { w.Write([]byte(githubAppInstallationJSON)) // nolint: errcheck return + case "/api/v3/apps/some-app": + token := strings.Replace(r.Header.Get("Authorization"), "token ", "", 1) + + // token is taken from githubAppTokenJSON + if token != "some-token" { + w.WriteHeader(403) + w.Write([]byte("Invalid installation token")) // nolint: errcheck + return + } + w.Write([]byte(githubAppJSON)) // nolint: errcheck + return case "/api/v3/app/installations/1/access_tokens": token := strings.Replace(r.Header.Get("Authorization"), "Bearer ", "", 1) if err := validateGithubToken(token); err != nil { diff --git a/server/events/vcs/github_client.go b/server/events/vcs/github_client.go index 3181d0695..1c7824884 100644 --- a/server/events/vcs/github_client.go +++ b/server/events/vcs/github_client.go @@ -91,8 +91,15 @@ func NewGithubClient(hostname string, credentials GithubCredentials, logger *log transport, graphql.WithHeader("Accept", "application/vnd.github.queen-beryl-preview+json"), ) + + user, err := credentials.GetUser() + logger.Debug("GH User: %s", user) + + if err != nil { + return nil, errors.Wrap(err, "getting user") + } return &GithubClient{ - user: credentials.GetUser(), + user: user, client: client, v4MutateClient: v4MutateClient, ctx: context.Background(), @@ -173,7 +180,7 @@ func (g *GithubClient) HidePrevPlanComments(repo models.Repo, pullNum int) error ListOptions: github.ListOptions{Page: nextPage}, }) if err != nil { - return err + return errors.Wrap(err, "listing comments") } allComments = append(allComments, comments...) if resp.NextPage == 0 { diff --git a/server/events/vcs/github_credentials.go b/server/events/vcs/github_credentials.go index 29db764e0..dc18457e0 100644 --- a/server/events/vcs/github_credentials.go +++ b/server/events/vcs/github_credentials.go @@ -18,7 +18,7 @@ import ( type GithubCredentials interface { Client() (*http.Client, error) GetToken() (string, error) - GetUser() string + GetUser() (string, error) } // GithubAnonymousCredentials expose no credentials. @@ -31,8 +31,8 @@ func (c *GithubAnonymousCredentials) Client() (*http.Client, error) { } // GetUser returns the username for these credentials. -func (c *GithubAnonymousCredentials) GetUser() string { - return "anonymous" +func (c *GithubAnonymousCredentials) GetUser() (string, error) { + return "anonymous", nil } // GetToken returns an empty token. @@ -56,8 +56,8 @@ func (c *GithubUserCredentials) Client() (*http.Client, error) { } // GetUser returns the username for these credentials. -func (c *GithubUserCredentials) GetUser() string { - return c.User +func (c *GithubUserCredentials) GetUser() (string, error) { + return c.User, nil } // GetToken returns the user token. @@ -73,6 +73,7 @@ type GithubAppCredentials struct { apiURL *url.URL installationID int64 tr *ghinstallation.Transport + AppSlug string } // Client returns a github app installation client. @@ -85,8 +86,29 @@ func (c *GithubAppCredentials) Client() (*http.Client, error) { } // GetUser returns the username for these credentials. -func (c *GithubAppCredentials) GetUser() string { - return "" +func (c *GithubAppCredentials) GetUser() (string, error) { + // Keeping backwards compatibility since this flag is optional + if c.AppSlug == "" { + return "", nil + } + client, err := c.Client() + + if err != nil { + return "", errors.Wrap(err, "initializing client") + } + + ghClient := github.NewClient(client) + ghClient.BaseURL = c.getAPIURL() + ctx := context.Background() + + app, _, err := ghClient.Apps.Get(ctx, c.AppSlug) + + if err != nil { + return "", errors.Wrap(err, "getting app details") + } + // Currently there is no way to get the bot's login info, so this is a + // hack until Github exposes that. + return fmt.Sprintf("%s[bot]", app.GetName()), nil } // GetToken returns a fresh installation token. diff --git a/server/events/vcs/github_credentials_test.go b/server/events/vcs/github_credentials_test.go index 3be20f3b2..c643c9706 100644 --- a/server/events/vcs/github_credentials_test.go +++ b/server/events/vcs/github_credentials_test.go @@ -9,6 +9,36 @@ import ( . "github.com/runatlantis/atlantis/testing" ) +func TestGithubClient_GetUser_AppSlug(t *testing.T) { + defer disableSSLVerification()() + testServer, err := fixtures.GithubAppTestServer(t) + Ok(t, err) + + anonCreds := &vcs.GithubAnonymousCredentials{} + anonClient, err := vcs.NewGithubClient(testServer, anonCreds, nil) + Ok(t, err) + tempSecrets, err := anonClient.ExchangeCode("good-code") + Ok(t, err) + + tmpDir, cleanup := DirStructure(t, map[string]interface{}{ + "key.pem": tempSecrets.Key, + }) + defer cleanup() + keyPath := fmt.Sprintf("%v/key.pem", tmpDir) + + appCreds := &vcs.GithubAppCredentials{ + AppID: tempSecrets.ID, + KeyPath: keyPath, + Hostname: testServer, + AppSlug: "some-app", + } + + user, err := appCreds.GetUser() + Ok(t, err) + + Assert(t, user == "Octocat App[bot]", "user should not empty") +} + func TestGithubClient_AppAuthentication(t *testing.T) { defer disableSSLVerification()() testServer, err := fixtures.GithubAppTestServer(t) @@ -40,6 +70,11 @@ func TestGithubClient_AppAuthentication(t *testing.T) { newToken, err := appCreds.GetToken() Ok(t, err) + user, err := appCreds.GetUser() + Ok(t, err) + + Assert(t, user == "", "user should be empty") + if token != newToken { t.Errorf("app token was not cached: %q != %q", token, newToken) } diff --git a/server/events/vcs/mocks/matchers/ptr_to_http_client.go b/server/events/vcs/mocks/matchers/ptr_to_http_client.go index 4ec255001..74766e888 100644 --- a/server/events/vcs/mocks/matchers/ptr_to_http_client.go +++ b/server/events/vcs/mocks/matchers/ptr_to_http_client.go @@ -2,8 +2,9 @@ package matchers import ( - "reflect" "github.com/petergtz/pegomock" + "reflect" + http "net/http" ) @@ -18,3 +19,15 @@ func EqPtrToHttpClient(value *http.Client) *http.Client { var nullValue *http.Client return nullValue } + +func NotEqPtrToHttpClient(value *http.Client) *http.Client { + pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) + var nullValue *http.Client + return nullValue +} + +func PtrToHttpClientThat(matcher pegomock.ArgumentMatcher) *http.Client { + pegomock.RegisterMatcher(matcher) + var nullValue *http.Client + return nullValue +} diff --git a/server/events/vcs/mocks/mock_github_credentials.go b/server/events/vcs/mocks/mock_github_credentials.go index 2837977c4..d491009dc 100644 --- a/server/events/vcs/mocks/mock_github_credentials.go +++ b/server/events/vcs/mocks/mock_github_credentials.go @@ -63,19 +63,23 @@ func (mock *MockGithubCredentials) GetToken() (string, error) { return ret0, ret1 } -func (mock *MockGithubCredentials) GetUser() string { +func (mock *MockGithubCredentials) GetUser() (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockGithubCredentials().") } params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("GetUser", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem()}) + result := pegomock.GetGenericMockFrom(mock).Invoke("GetUser", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) var ret0 string + var ret1 error if len(result) != 0 { if result[0] != nil { ret0 = result[0].(string) } + if result[1] != nil { + ret1 = result[1].(error) + } } - return ret0 + return ret0, ret1 } func (mock *MockGithubCredentials) VerifyWasCalledOnce() *VerifierMockGithubCredentials { @@ -85,14 +89,14 @@ func (mock *MockGithubCredentials) VerifyWasCalledOnce() *VerifierMockGithubCred } } -func (mock *MockGithubCredentials) VerifyWasCalled(invocationCountMatcher pegomock.Matcher) *VerifierMockGithubCredentials { +func (mock *MockGithubCredentials) VerifyWasCalled(invocationCountMatcher pegomock.InvocationCountMatcher) *VerifierMockGithubCredentials { return &VerifierMockGithubCredentials{ mock: mock, invocationCountMatcher: invocationCountMatcher, } } -func (mock *MockGithubCredentials) VerifyWasCalledInOrder(invocationCountMatcher pegomock.Matcher, inOrderContext *pegomock.InOrderContext) *VerifierMockGithubCredentials { +func (mock *MockGithubCredentials) VerifyWasCalledInOrder(invocationCountMatcher pegomock.InvocationCountMatcher, inOrderContext *pegomock.InOrderContext) *VerifierMockGithubCredentials { return &VerifierMockGithubCredentials{ mock: mock, invocationCountMatcher: invocationCountMatcher, @@ -100,7 +104,7 @@ func (mock *MockGithubCredentials) VerifyWasCalledInOrder(invocationCountMatcher } } -func (mock *MockGithubCredentials) VerifyWasCalledEventually(invocationCountMatcher pegomock.Matcher, timeout time.Duration) *VerifierMockGithubCredentials { +func (mock *MockGithubCredentials) VerifyWasCalledEventually(invocationCountMatcher pegomock.InvocationCountMatcher, timeout time.Duration) *VerifierMockGithubCredentials { return &VerifierMockGithubCredentials{ mock: mock, invocationCountMatcher: invocationCountMatcher, @@ -110,7 +114,7 @@ func (mock *MockGithubCredentials) VerifyWasCalledEventually(invocationCountMatc type VerifierMockGithubCredentials struct { mock *MockGithubCredentials - invocationCountMatcher pegomock.Matcher + invocationCountMatcher pegomock.InvocationCountMatcher inOrderContext *pegomock.InOrderContext timeout time.Duration } diff --git a/server/server.go b/server/server.go index a53fb8a8a..17e8a7501 100644 --- a/server/server.go +++ b/server/server.go @@ -135,6 +135,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { AppID: userConfig.GithubAppID, KeyPath: userConfig.GithubAppKey, Hostname: userConfig.GithubHostname, + AppSlug: userConfig.GithubAppSlug, } githubAppEnabled = true } diff --git a/server/user_config.go b/server/user_config.go index 909dfdc2f..fd70ad38d 100644 --- a/server/user_config.go +++ b/server/user_config.go @@ -33,6 +33,7 @@ type UserConfig struct { GithubOrg string `mapstructure:"gh-org"` GithubAppID int64 `mapstructure:"gh-app-id"` GithubAppKey string `mapstructure:"gh-app-key-file"` + GithubAppSlug string `mapstructure:"gh-app-slug"` GitlabHostname string `mapstructure:"gitlab-hostname"` GitlabToken string `mapstructure:"gitlab-token"` GitlabUser string `mapstructure:"gitlab-user"` diff --git a/vendor/github.com/petergtz/pegomock/.goreleaser.yml b/vendor/github.com/petergtz/pegomock/.goreleaser.yml index 122cdf10f..de80d4770 100644 --- a/vendor/github.com/petergtz/pegomock/.goreleaser.yml +++ b/vendor/github.com/petergtz/pegomock/.goreleaser.yml @@ -11,8 +11,8 @@ builds: goarch: - amd64 -archive: - replacements: +archives: +- replacements: # darwin: Darwin # linux: Linux # windows: Windows diff --git a/vendor/github.com/petergtz/pegomock/README.md b/vendor/github.com/petergtz/pegomock/README.md index 56e30dcb0..3f55e2aad 100644 --- a/vendor/github.com/petergtz/pegomock/README.md +++ b/vendor/github.com/petergtz/pegomock/README.md @@ -13,7 +13,7 @@ go get github.com/petergtz/pegomock/... This will download the package and install an executable `pegomock` in your `$GOPATH/bin`. -See also section[Tracking the pegomock tool in your project](#tracking-the-pegomock-tool-in-your-project) for a per-project control of the tool version. +See also section [Tracking the pegomock tool in your project](#tracking-the-pegomock-tool-in-your-project) for a per-project control of the tool version. Getting Started =============== @@ -271,9 +271,16 @@ When(contactList.getContactByFullName(EqString("Dan"), AnyString())).thenReturn( ### Writing Your Own Argument Matchers -**Important:** `Eq...` and `Any...` matchers for types used in mock methods, can now be _auto-generated_ while generating the mock. So writing your own argument matchers is not necessary for most use cases. See section [The Pegomock CLI](#generating-mocks) for more information. +**Important:** `Eq...`, `NotEq...`, `Any...` and `...That` matchers for types used in mock methods, +can now be _auto-generated_ while generating the mock. The `...That` argument matcher accepts an +argument implementing the `pegomock.ArgumentMatcher` interface and allows you to write and use custom +matcher logic without having to create a new argument matcher method for each type you want to match. -You can also write your own matchers for non-basic types. E.g. if you have a `struct MyType`, you can write an _Equals_ and _Any_ matcher like this: +So writing your own argument matchers is not necessary for most use cases. See section +[The Pegomock CLI](#generating-mocks) for more information. + +If you are not using the option to generate matchers you can write your own for non-basic types. +E.g. if you have a `struct MyType`, you can write an _Equals_ and _Any_ matcher like this: ```go func EqMyType(value MyType) MyType { RegisterMatcher(&EqMatcher{Value: value}) diff --git a/vendor/github.com/petergtz/pegomock/dsl.go b/vendor/github.com/petergtz/pegomock/dsl.go index 09a8ab320..00a477a64 100644 --- a/vendor/github.com/petergtz/pegomock/dsl.go +++ b/vendor/github.com/petergtz/pegomock/dsl.go @@ -43,7 +43,7 @@ var ( var globalArgMatchers Matchers -func RegisterMatcher(matcher Matcher) { +func RegisterMatcher(matcher ArgumentMatcher) { globalArgMatchers.append(matcher) } @@ -72,11 +72,11 @@ func (genericMock *GenericMock) Invoke(methodName string, params []Param, return return genericMock.getOrCreateMockedMethod(methodName).Invoke(params) } -func (genericMock *GenericMock) stub(methodName string, paramMatchers []Matcher, returnValues ReturnValues) { +func (genericMock *GenericMock) stub(methodName string, paramMatchers []ArgumentMatcher, returnValues ReturnValues) { genericMock.stubWithCallback(methodName, paramMatchers, func([]Param) ReturnValues { return returnValues }) } -func (genericMock *GenericMock) stubWithCallback(methodName string, paramMatchers []Matcher, callback func([]Param) ReturnValues) { +func (genericMock *GenericMock) stubWithCallback(methodName string, paramMatchers []ArgumentMatcher, callback func([]Param) ReturnValues) { genericMock.getOrCreateMockedMethod(methodName).stub(paramMatchers, callback) } @@ -89,13 +89,13 @@ func (genericMock *GenericMock) getOrCreateMockedMethod(methodName string) *mock return genericMock.mockedMethods[methodName] } -func (genericMock *GenericMock) reset(methodName string, paramMatchers []Matcher) { +func (genericMock *GenericMock) reset(methodName string, paramMatchers []ArgumentMatcher) { genericMock.getOrCreateMockedMethod(methodName).reset(paramMatchers) } func (genericMock *GenericMock) Verify( inOrderContext *InOrderContext, - invocationCountMatcher Matcher, + invocationCountMatcher InvocationCountMatcher, methodName string, params []Param, options ...interface{}, @@ -175,7 +175,7 @@ func (genericMock *GenericMock) GetInvocationParams(methodInvocations []MethodIn return result } -func (genericMock *GenericMock) methodInvocations(methodName string, params []Param, matchers []Matcher) []MethodInvocation { +func (genericMock *GenericMock) methodInvocations(methodName string, params []Param, matchers []ArgumentMatcher) []MethodInvocation { var invocations []MethodInvocation if method, exists := genericMock.mockedMethods[methodName]; exists { method.Lock() @@ -200,7 +200,7 @@ func formatInteractions(interactions map[string][]MethodInvocation) string { if len(interactions) == 0 { return "There were no other interactions with this mock" } - result := "But other interactions with this mock were:\n" + result := "Actual interactions with this mock were:\n" for _, methodName := range sortedMethodNames(interactions) { result += formatInvocations(methodName, interactions[methodName]) } @@ -224,7 +224,7 @@ func formatParams(params []Param) (result string) { return } -func formatMatchers(matchers []Matcher) (result string) { +func formatMatchers(matchers []ArgumentMatcher) (result string) { for i, matcher := range matchers { if i > 0 { result += ", " @@ -366,7 +366,7 @@ func (stubbing *Stubbing) Invoke(params []Param) ReturnValues { return stubbing.callbackSequence[stubbing.sequencePointer](params) } -type Matchers []Matcher +type Matchers []ArgumentMatcher func (matchers Matchers) Matches(params []Param) bool { if len(matchers) != len(params) { // Technically, this is not an error. Variadic arguments can cause this @@ -381,14 +381,14 @@ func (matchers Matchers) Matches(params []Param) bool { return true } -func (matchers *Matchers) append(matcher Matcher) { +func (matchers *Matchers) append(matcher ArgumentMatcher) { *matchers = append(*matchers, matcher) } type ongoingStubbing struct { genericMock *GenericMock MethodName string - ParamMatchers []Matcher + ParamMatchers []ArgumentMatcher returnTypes []reflect.Type } @@ -434,7 +434,7 @@ func actualTypeOf(iface interface{}) reflect.Type { return reflect.TypeOf(iface) } -func paramMatchersFromArgMatchersOrParams(argMatchers []Matcher, params []Param) []Matcher { +func paramMatchersFromArgMatchersOrParams(argMatchers []ArgumentMatcher, params []Param) []ArgumentMatcher { if len(argMatchers) != 0 { verifyArgMatcherUse(argMatchers, params) return argMatchers @@ -442,7 +442,7 @@ func paramMatchersFromArgMatchersOrParams(argMatchers []Matcher, params []Param) return transformParamsIntoEqMatchers(params) } -func verifyArgMatcherUse(argMatchers []Matcher, params []Param) { +func verifyArgMatcherUse(argMatchers []ArgumentMatcher, params []Param) { verify.Argument(len(argMatchers) == len(params), "Invalid use of matchers!\n\n %v matchers expected, %v recorded.\n\n"+ "This error may occur if matchers are combined with raw values:\n"+ @@ -456,8 +456,8 @@ func verifyArgMatcherUse(argMatchers []Matcher, params []Param) { ) } -func transformParamsIntoEqMatchers(params []Param) []Matcher { - paramMatchers := make([]Matcher, len(params)) +func transformParamsIntoEqMatchers(params []Param) []ArgumentMatcher { + paramMatchers := make([]ArgumentMatcher, len(params)) for i, param := range params { paramMatchers[i] = &EqMatcher{Value: param} } @@ -528,8 +528,22 @@ type InOrderContext struct { lastInvokedMethodParams []Param } -// Matcher ... it is guaranteed that FailureMessage will always be called after Matches -// so an implementation can save state +// ArgumentMatcher can be used to match arguments. +type ArgumentMatcher interface { + Matches(param Param) bool + fmt.Stringer +} + +// InvocationCountMatcher can be used to match invocation counts. It is guaranteed that +// FailureMessage will always be called after Matches so an implementation can save state. +type InvocationCountMatcher interface { + Matches(param Param) bool + FailureMessage() string +} + +// Matcher can be used to match arguments as well as invocation counts. +// Note that support for overlapping embedded interfaces was added in Go 1.14, which is why +// ArgumentMatcher and InvocationCountMatcher are not embedded here. type Matcher interface { Matches(param Param) bool FailureMessage() string diff --git a/vendor/github.com/petergtz/pegomock/matcher.go b/vendor/github.com/petergtz/pegomock/matcher.go index eb518d731..d3e9700a9 100644 --- a/vendor/github.com/petergtz/pegomock/matcher.go +++ b/vendor/github.com/petergtz/pegomock/matcher.go @@ -27,7 +27,23 @@ func (matcher *EqMatcher) FailureMessage() string { } func (matcher *EqMatcher) String() string { - return fmt.Sprintf("Eq(%v)", matcher.Value) + return fmt.Sprintf("Eq(%#v)", matcher.Value) +} + +type NotEqMatcher struct { + Value Param +} + +func (matcher *NotEqMatcher) Matches(param Param) bool { + return !reflect.DeepEqual(matcher.Value, param) +} + +func (matcher *NotEqMatcher) FailureMessage() string { + return fmt.Sprintf("Expected: not %v; but got: %v", matcher.Value, matcher.Value) +} + +func (matcher *NotEqMatcher) String() string { + return fmt.Sprintf("NotEq(%#v)", matcher.Value) } type AnyMatcher struct { diff --git a/vendor/github.com/petergtz/pegomock/matcher_factories.go b/vendor/github.com/petergtz/pegomock/matcher_factories.go index 1691515f4..6a1bff0f3 100644 --- a/vendor/github.com/petergtz/pegomock/matcher_factories.go +++ b/vendor/github.com/petergtz/pegomock/matcher_factories.go @@ -9,13 +9,38 @@ func EqBool(value bool) bool { return false } +func NotEqBool(value bool) bool { + RegisterMatcher(&NotEqMatcher{Value: value}) + return false +} + func AnyBool() bool { - RegisterMatcher(NewAnyMatcher(reflect.TypeOf((bool)(false)))) + RegisterMatcher(NewAnyMatcher(reflect.TypeOf(false))) return false } +func BoolThat(matcher ArgumentMatcher) bool { + RegisterMatcher(matcher) + return false +} + +func EqBoolSlice(value []bool) []bool { + RegisterMatcher(&EqMatcher{Value: value}) + return nil +} + +func NotEqBoolSlice(value []bool) []bool { + RegisterMatcher(&NotEqMatcher{Value: value}) + return nil +} + func AnyBoolSlice() []bool { - RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((bool)(false))))) + RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf(false)))) + return nil +} + +func BoolSliceThat(matcher ArgumentMatcher) []bool { + RegisterMatcher(matcher) return nil } @@ -24,13 +49,38 @@ func EqInt(value int) int { return 0 } +func NotEqInt(value int) int { + RegisterMatcher(&NotEqMatcher{Value: value}) + return 0 +} + func AnyInt() int { - RegisterMatcher(NewAnyMatcher(reflect.TypeOf((int)(0)))) + RegisterMatcher(NewAnyMatcher(reflect.TypeOf(0))) return 0 } +func IntThat(matcher ArgumentMatcher) int { + RegisterMatcher(matcher) + return 0 +} + +func EqIntSlice(value []int) []int { + RegisterMatcher(&EqMatcher{Value: value}) + return nil +} + +func NotEqIntSlice(value []int) []int { + RegisterMatcher(&NotEqMatcher{Value: value}) + return nil +} + func AnyIntSlice() []int { - RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((int)(0))))) + RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf(0)))) + return nil +} + +func IntSliceThat(matcher ArgumentMatcher) []int { + RegisterMatcher(matcher) return nil } @@ -39,223 +89,598 @@ func EqInt8(value int8) int8 { return 0 } +func NotEqInt8(value int8) int8 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return 0 +} + func AnyInt8() int8 { RegisterMatcher(NewAnyMatcher(reflect.TypeOf((int8)(0)))) return 0 } +func Int8That(matcher ArgumentMatcher) int8 { + RegisterMatcher(matcher) + return 0 +} + +func EqInt8Slice(value []int8) []int8 { + RegisterMatcher(&EqMatcher{Value: value}) + return nil +} + +func NotEqInt8Slice(value []int8) []int8 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return nil +} + func AnyInt8Slice() []int8 { RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((int8)(0))))) return nil } +func Int8SliceThat(matcher ArgumentMatcher) []int8 { + RegisterMatcher(matcher) + return nil +} + func EqInt16(value int16) int16 { RegisterMatcher(&EqMatcher{Value: value}) return 0 } +func NotEqInt16(value int16) int16 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return 0 +} + func AnyInt16() int16 { RegisterMatcher(NewAnyMatcher(reflect.TypeOf((int16)(0)))) return 0 } +func Int16That(matcher ArgumentMatcher) int16 { + RegisterMatcher(matcher) + return 0 +} + +func EqInt16Slice(value []int16) []int16 { + RegisterMatcher(&EqMatcher{Value: value}) + return nil +} + +func NotEqInt16Slice(value []int16) []int16 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return nil +} + func AnyInt16Slice() []int16 { RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((int16)(0))))) return nil } +func Int16SliceThat(matcher ArgumentMatcher) []int16 { + RegisterMatcher(matcher) + return nil +} + func EqInt32(value int32) int32 { RegisterMatcher(&EqMatcher{Value: value}) return 0 } +func NotEqInt32(value int32) int32 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return 0 +} + func AnyInt32() int32 { RegisterMatcher(NewAnyMatcher(reflect.TypeOf((int32)(0)))) return 0 } +func Int32That(matcher ArgumentMatcher) int32 { + RegisterMatcher(matcher) + return 0 +} + +func EqInt32Slice(value []int32) []int32 { + RegisterMatcher(&EqMatcher{Value: value}) + return nil +} + +func NotEqInt32Slice(value []int32) []int32 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return nil +} + func AnyInt32Slice() []int32 { RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((int32)(0))))) return nil } +func Int32SliceThat(matcher ArgumentMatcher) []int32 { + RegisterMatcher(matcher) + return nil +} + func EqInt64(value int64) int64 { RegisterMatcher(&EqMatcher{Value: value}) return 0 } +func NotEqInt64(value int64) int64 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return 0 +} + func AnyInt64() int64 { RegisterMatcher(NewAnyMatcher(reflect.TypeOf((int64)(0)))) return 0 } +func Int64That(matcher ArgumentMatcher) int64 { + RegisterMatcher(matcher) + return 0 +} + +func EqInt64Slice(value []int64) []int64 { + RegisterMatcher(&EqMatcher{Value: value}) + return nil +} + +func NotEqInt64Slice(value []int64) []int64 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return nil +} + func AnyInt64Slice() []int64 { RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((int64)(0))))) return nil } +func Int64SliceThat(matcher ArgumentMatcher) []int64 { + RegisterMatcher(matcher) + return nil +} + func EqUint(value uint) uint { RegisterMatcher(&EqMatcher{Value: value}) return 0 } +func NotEqUint(value uint) uint { + RegisterMatcher(&NotEqMatcher{Value: value}) + return 0 +} + func AnyUint() uint { RegisterMatcher(NewAnyMatcher(reflect.TypeOf((uint)(0)))) return 0 } +func UintThat(matcher ArgumentMatcher) uint { + RegisterMatcher(matcher) + return 0 +} + +func EqUintSlice(value []uint) []uint { + RegisterMatcher(&EqMatcher{Value: value}) + return nil +} + +func NotEqUintSlice(value []uint) []uint { + RegisterMatcher(&NotEqMatcher{Value: value}) + return nil +} + func AnyUintSlice() []uint { RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((uint)(0))))) return nil } +func UintSliceThat(matcher ArgumentMatcher) []uint { + RegisterMatcher(matcher) + return nil +} + func EqUint8(value uint8) uint8 { RegisterMatcher(&EqMatcher{Value: value}) return 0 } +func NotEqUint8(value uint8) uint8 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return 0 +} + func AnyUint8() uint8 { RegisterMatcher(NewAnyMatcher(reflect.TypeOf((uint8)(0)))) return 0 } +func Uint8That(matcher ArgumentMatcher) uint8 { + RegisterMatcher(matcher) + return 0 +} + +func EqUint8Slice(value []uint8) []uint8 { + RegisterMatcher(&EqMatcher{Value: value}) + return nil +} + +func NotEqUint8Slice(value []uint8) []uint8 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return nil +} + func AnyUint8Slice() []uint8 { RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((uint8)(0))))) return nil } +func Uint8SliceThat(matcher ArgumentMatcher) []uint8 { + RegisterMatcher(matcher) + return nil +} + func EqUint16(value uint16) uint16 { RegisterMatcher(&EqMatcher{Value: value}) return 0 } +func NotEqUint16(value uint16) uint16 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return 0 +} + func AnyUint16() uint16 { RegisterMatcher(NewAnyMatcher(reflect.TypeOf((uint16)(0)))) return 0 } +func Uint16That(matcher ArgumentMatcher) uint16 { + RegisterMatcher(matcher) + return 0 +} + +func EqUint16Slice(value []uint16) []uint16 { + RegisterMatcher(&EqMatcher{Value: value}) + return nil +} + +func NotEqUint16Slice(value []uint16) []uint16 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return nil +} + func AnyUint16Slice() []uint16 { RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((uint16)(0))))) return nil } +func Uint16SliceThat(matcher ArgumentMatcher) []uint16 { + RegisterMatcher(matcher) + return nil +} + func EqUint32(value uint32) uint32 { RegisterMatcher(&EqMatcher{Value: value}) return 0 } +func NotEqUint32(value uint32) uint32 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return 0 +} + func AnyUint32() uint32 { RegisterMatcher(NewAnyMatcher(reflect.TypeOf((uint32)(0)))) return 0 } +func Uint32That(matcher ArgumentMatcher) uint32 { + RegisterMatcher(matcher) + return 0 +} + +func EqUint32Slice(value []uint32) []uint32 { + RegisterMatcher(&EqMatcher{Value: value}) + return nil +} + +func NotEqUint32Slice(value []uint32) []uint32 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return nil +} + func AnyUint32Slice() []uint32 { RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((uint32)(0))))) return nil } +func Uint32SliceThat(matcher ArgumentMatcher) []uint32 { + RegisterMatcher(matcher) + return nil +} + func EqUint64(value uint64) uint64 { RegisterMatcher(&EqMatcher{Value: value}) return 0 } +func NotEqUint64(value uint64) uint64 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return 0 +} + func AnyUint64() uint64 { RegisterMatcher(NewAnyMatcher(reflect.TypeOf((uint64)(0)))) return 0 } +func Uint64That(matcher ArgumentMatcher) uint64 { + RegisterMatcher(matcher) + return 0 +} + +func EqUint64Slice(value []uint64) []uint64 { + RegisterMatcher(&EqMatcher{Value: value}) + return nil +} + +func NotEqUint64Slice(value []uint64) []uint64 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return nil +} + func AnyUint64Slice() []uint64 { RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((uint64)(0))))) return nil } +func Uint64SliceThat(matcher ArgumentMatcher) []uint64 { + RegisterMatcher(matcher) + return nil +} + func EqUintptr(value uintptr) uintptr { RegisterMatcher(&EqMatcher{Value: value}) return 0 } +func NotEqUintptr(value uintptr) uintptr { + RegisterMatcher(&NotEqMatcher{Value: value}) + return 0 +} + func AnyUintptr() uintptr { RegisterMatcher(NewAnyMatcher(reflect.TypeOf((uintptr)(0)))) return 0 } +func UintptrThat(matcher ArgumentMatcher) uintptr { + RegisterMatcher(matcher) + return 0 +} + +func EqUintptrSlice(value []uintptr) []uintptr { + RegisterMatcher(&EqMatcher{Value: value}) + return nil +} + +func NotEqUintptrSlice(value []uintptr) []uintptr { + RegisterMatcher(&NotEqMatcher{Value: value}) + return nil +} + func AnyUintptrSlice() []uintptr { RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((uintptr)(0))))) return nil } +func UintptrSliceThat(matcher ArgumentMatcher) []uintptr { + RegisterMatcher(matcher) + return nil +} + func EqFloat32(value float32) float32 { RegisterMatcher(&EqMatcher{Value: value}) return 0 } +func NotEqFloat32(value float32) float32 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return 0 +} + func AnyFloat32() float32 { RegisterMatcher(NewAnyMatcher(reflect.TypeOf((float32)(0)))) return 0 } +func Float32That(matcher ArgumentMatcher) float32 { + RegisterMatcher(matcher) + return 0 +} + +func EqFloat32Slice(value []float32) []float32 { + RegisterMatcher(&EqMatcher{Value: value}) + return nil +} + +func NotEqFloat32Slice(value []float32) []float32 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return nil +} + func AnyFloat32Slice() []float32 { RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((float32)(0))))) return nil } +func Float32SliceThat(matcher ArgumentMatcher) []float32 { + RegisterMatcher(matcher) + return nil +} + func EqFloat64(value float64) float64 { RegisterMatcher(&EqMatcher{Value: value}) return 0 } +func NotEqFloat64(value float64) float64 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return 0 +} + func AnyFloat64() float64 { RegisterMatcher(NewAnyMatcher(reflect.TypeOf((float64)(0)))) return 0 } +func Float64That(matcher ArgumentMatcher) float64 { + RegisterMatcher(matcher) + return 0 +} + +func EqFloat64Slice(value []float64) []float64 { + RegisterMatcher(&EqMatcher{Value: value}) + return nil +} + +func NotEqFloat64Slice(value []float64) []float64 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return nil +} + func AnyFloat64Slice() []float64 { RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((float64)(0))))) return nil } +func Float64SliceThat(matcher ArgumentMatcher) []float64 { + RegisterMatcher(matcher) + return nil +} + func EqComplex64(value complex64) complex64 { RegisterMatcher(&EqMatcher{Value: value}) return 0 } +func NotEqComplex64(value complex64) complex64 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return 0 +} + func AnyComplex64() complex64 { RegisterMatcher(NewAnyMatcher(reflect.TypeOf((complex64)(0)))) return 0 } +func Complex64That(matcher ArgumentMatcher) complex64 { + RegisterMatcher(matcher) + return 0 +} + +func EqComplex64Slice(value []complex64) []complex64 { + RegisterMatcher(&EqMatcher{Value: value}) + return nil +} + +func NotEqComplex64Slice(value []complex64) []complex64 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return nil +} + func AnyComplex64Slice() []complex64 { RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((complex64)(0))))) return nil } +func Complex64SliceThat(matcher ArgumentMatcher) []complex64 { + RegisterMatcher(matcher) + return nil +} + func EqComplex128(value complex128) complex128 { RegisterMatcher(&EqMatcher{Value: value}) return 0 } +func NotEqComplex128(value complex128) complex128 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return 0 +} + func AnyComplex128() complex128 { RegisterMatcher(NewAnyMatcher(reflect.TypeOf((complex128)(0)))) return 0 } +func Complex128That(matcher ArgumentMatcher) complex128 { + RegisterMatcher(matcher) + return 0 +} + +func EqComplex128Slice(value []complex128) []complex128 { + RegisterMatcher(&EqMatcher{Value: value}) + return nil +} + +func NotEqComplex128Slice(value []complex128) []complex128 { + RegisterMatcher(&NotEqMatcher{Value: value}) + return nil +} + func AnyComplex128Slice() []complex128 { RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((complex128)(0))))) return nil } +func Complex128SliceThat(matcher ArgumentMatcher) []complex128 { + RegisterMatcher(matcher) + return nil +} + func EqString(value string) string { RegisterMatcher(&EqMatcher{Value: value}) return "" } +func NotEqString(value string) string { + RegisterMatcher(&NotEqMatcher{Value: value}) + return "" +} + func AnyString() string { - RegisterMatcher(NewAnyMatcher(reflect.TypeOf((string)("")))) + RegisterMatcher(NewAnyMatcher(reflect.TypeOf(""))) + return "" +} + +func StringThat(matcher ArgumentMatcher) string { + RegisterMatcher(matcher) return "" } +func EqStringSlice(value []string) []string { + RegisterMatcher(&EqMatcher{Value: value}) + return nil +} + +func NotEqStringSlice(value []string) []string { + RegisterMatcher(&NotEqMatcher{Value: value}) + return nil +} + func AnyStringSlice() []string { - RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((string)(""))))) + RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf("")))) + return nil +} + +func StringSliceThat(matcher ArgumentMatcher) []string { + RegisterMatcher(matcher) return nil } @@ -264,13 +689,37 @@ func EqInterface(value interface{}) interface{} { return nil } +func NotEqInterface(value interface{}) interface{} { + RegisterMatcher(&NotEqMatcher{Value: value}) + return nil +} + func AnyInterface() interface{} { - RegisterMatcher(NewAnyMatcher(reflect.TypeOf((*(interface{}))(nil)).Elem())) + RegisterMatcher(NewAnyMatcher(reflect.TypeOf((*interface{})(nil)).Elem())) + return nil +} + +func InterfaceThat(matcher ArgumentMatcher) interface{} { + RegisterMatcher(matcher) + return nil +} + +func EqInterfaceSlice(value []interface{}) []interface{} { + RegisterMatcher(&EqMatcher{Value: value}) + return nil +} + +func NotEqInterfaceSlice(value []interface{}) []interface{} { + RegisterMatcher(&NotEqMatcher{Value: value}) return nil } func AnyInterfaceSlice() []interface{} { - RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((*(interface{}))(nil)).Elem()))) + RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((*interface{})(nil)).Elem()))) + return nil +} + +func InterfaceSliceThat(matcher ArgumentMatcher) []interface{} { + RegisterMatcher(matcher) return nil } - \ No newline at end of file diff --git a/vendor/modules.txt b/vendor/modules.txt index 1ae8115dc..b061faf3f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -235,7 +235,7 @@ github.com/nlopes/slack github.com/onsi/gomega/format # github.com/pelletier/go-toml v1.2.0 github.com/pelletier/go-toml -# github.com/petergtz/pegomock v2.8.0+incompatible +# github.com/petergtz/pegomock v2.9.0+incompatible ## explicit github.com/petergtz/pegomock github.com/petergtz/pegomock/internal/verify