Skip to content

Commit

Permalink
Start adding tests for the Snyk module
Browse files Browse the repository at this point in the history
  • Loading branch information
garethr committed May 14, 2023
1 parent 2751fc9 commit b41270b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
4 changes: 0 additions & 4 deletions lib/snyk/self.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ const experimentalVersion = "2023-04-28~experimental"
type selfDocument struct {
Data struct {
Attributes users.User `json:"attributes,omitempty"`
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
}
Jsonapi users.JsonApi `json:"jsonapi,omitempty"`
Links users.Links `json:"links,omitempty"`
}

func getSnykOrg(auth *securityprovider.SecurityProviderApiKey) (*uuid.UUID, error) {
Expand Down
38 changes: 38 additions & 0 deletions lib/snyk/self_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package snyk

import (
"net/http"
"testing"

"github.com/deepmap/oapi-codegen/pkg/securityprovider"
"github.com/google/uuid"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
)

func TestGetSnykOrg(t *testing.T) {
expectedOrg := uuid.New()
auth, _ := securityprovider.NewSecurityProviderApiKey("header", "name", "value")

httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("GET", "https://api.snyk.io/rest/self",
func(req *http.Request) (*http.Response, error) {
jsonBody := `{
"data": {
"attributes": {
"default_org_context": "` + expectedOrg.String() + `"
}
}
}`
resp := httpmock.NewStringResponse(200, jsonBody)
resp.Header.Set("Content-Type", "application/json")
return resp, nil
},
)

actualOrg, err := getSnykOrg(auth)
assert.NoError(t, err)
assert.Equal(t, expectedOrg, *actualOrg)
}

0 comments on commit b41270b

Please sign in to comment.