diff --git a/gitlab_client_test.go b/gitlab_client_test.go index d763e97..3fbdd96 100644 --- a/gitlab_client_test.go +++ b/gitlab_client_test.go @@ -241,3 +241,33 @@ func TestGitlabClient_CurrentTokenInfo(t *testing.T) { require.NotNil(t, token) assert.EqualValues(t, gitlab.TokenTypePersonal, token.TokenType) } + +func TestGitlabClient_CreateAccessToken(t *testing.T) { + var err error + + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.RequestURI == "/api/v4/personal_access_tokens/self" { + w.WriteHeader(http.StatusOK) + data, _ := os.ReadFile("testdata/personal_access_tokens_self.json") + _, _ = w.Write(data) + + } else { + w.WriteHeader(http.StatusNotFound) + } + })) + defer server.Close() + + var client gitlab.Client + client, err = gitlab.NewGitlabClient(&gitlab.EntryConfig{ + Token: "super-secret-token", + BaseURL: server.URL, + }, nil) + require.NoError(t, err) + require.NotNil(t, client) + require.True(t, client.Valid()) + + token, err := client.CurrentTokenInfo() + require.NoError(t, err) + require.NotNil(t, token) + assert.EqualValues(t, gitlab.TokenTypePersonal, token.TokenType) +} diff --git a/go.mod b/go.mod index 518e950..b332525 100644 --- a/go.mod +++ b/go.mod @@ -64,6 +64,5 @@ require ( google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230731193218-e0aa005b6bdf // indirect google.golang.org/grpc v1.57.0 // indirect - gopkg.in/dnaeon/go-vcr.v3 v3.1.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index a705b41..36cad38 100644 --- a/go.sum +++ b/go.sum @@ -259,8 +259,6 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= -gopkg.in/dnaeon/go-vcr.v3 v3.1.2 h1:F1smfXBqQqwpVifDfUBQG6zzaGjzT+EnVZakrOdr5wA= -gopkg.in/dnaeon/go-vcr.v3 v3.1.2/go.mod h1:2IMOnnlx9I6u9x+YBsM3tAMx6AlOxnJ0pWxQAzZ79Ag= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 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= diff --git a/helpers_test.go b/helpers_test.go index e6e4d69..d128357 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -11,7 +11,7 @@ import ( gitlab "github.com/ilijamt/vault-plugin-secrets-gitlab" "github.com/stretchr/testify/require" g "github.com/xanzy/go-gitlab" - "slices" + "golang.org/x/exp/slices" "sync" "testing" "time"