Skip to content

Commit

Permalink
fix linting errors (#166)
Browse files Browse the repository at this point in the history
* go mod tidy

* fix lint errors
  • Loading branch information
bcmdarroch authored Feb 9, 2023
1 parent 7841fe6 commit c9c7d25
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion auth/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func TestTokenToJson_InvalidFormat(t *testing.T) {
}
}

//TODO: create testHelpers file to include testsetup and destroy
// TODO: create testHelpers file to include testsetup and destroy
func CacheSetup(t *testing.T) (credentialDir, credentialPath string, err error) {
os.Setenv(envVarCacheTestMode, "true")

Expand Down
33 changes: 20 additions & 13 deletions cmd/transform-swagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ import (

// XGoType contains the fields of the go-swagger extension x-go-type
// In its final form, the extension looks like this on the generated type definition:
// "hashicorp.cloud.common.PaginationRequest": {
// "properties": { ... }
// ...
// "x-go-type": {
// "import": {
// "package": "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models",
// "alias": "cloud"
// },
// "type": "HashicorpCloudCommonPaginationRequest"
// }
// }
//
// "hashicorp.cloud.common.PaginationRequest": {
// "properties": { ... }
// ...
// "x-go-type": {
// "import": {
// "package": "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models",
// "alias": "cloud"
// },
// "type": "HashicorpCloudCommonPaginationRequest"
// }
// }
//
// ref: https://goswagger.io/use/models/schemas.html#types-reusability
type XGoType struct {
Import Import `json:"import"`
Expand Down Expand Up @@ -94,7 +96,7 @@ func main() {

// Overwrite original spec with the transformed spec.
log.Printf("Overwriting spec %q", svcPath)
err = ioutil.WriteFile(svcPath, json, os.ModePerm)
err = os.WriteFile(svcPath, json, os.ModePerm)
if err != nil {
log.Fatalf("failed to overwrite spec at path %q: %v", svcPath, err)
}
Expand Down Expand Up @@ -136,11 +138,16 @@ func loadSharedDefinitions(sharedPath, svcPath string) (map[string]bool, error)
return nil, fmt.Errorf("failed to load spec at path %q: %w", svcPath, err)
}

re := regexp.MustCompile(`\w+\.\w+\.`)
if err != nil {
return nil, fmt.Errorf("failed to compile regex for shared definitions: %w", err)
}

for _, def := range doc.Analyzer.AllDefinitions() {
if def.TopLevel {
// depending on which plugin used for swagger, some package info may not be available
// any types missing package information are skipped
fqnSwaggerFormat, _ := regexp.MatchString("\\w+\\.\\w+\\.", def.Name)
fqnSwaggerFormat := re.MatchString(def.Name)
if fqnSwaggerFormat && !strings.HasPrefix(def.Name, "hashicorp.cloud") {
sharedDefs[def.Name] = true
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
github.com/stretchr/testify v1.8.1
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd
golang.org/x/net v0.5.0
golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58
)

Expand Down
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/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-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -392,7 +392,7 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 h1:h+EGohizhe9XlX18rfpa8k8RAc5XyaeamM+0VHRd4lc=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
4 changes: 2 additions & 2 deletions httpclient/httpclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -45,7 +45,7 @@ func TestNew(t *testing.T) {
// This handler mocks responses from the auth provider.
case tokenPath:
// Before returning the access token, verify request payload includes expected params.
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
defer r.Body.Close()
require.NoError(t, err)

Expand Down
8 changes: 6 additions & 2 deletions resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ type Resource struct {
}

// String encodes the resource identifier in the following canonical format:
// "organization/<Organization UUID>/project/<Project UUID>/<Type>/<ID>"
//
// "organization/<Organization UUID>/project/<Project UUID>/<Type>/<ID>"
//
// Example:
// "organization/ccbdd191-5dc3-4a73-9e05-6ac30ca67992/project/36019e0d-ed59-4df6-9990-05bb7fc793b6/hashicorp.consul.linked-cluster/prod-on-prem"
//
// "organization/ccbdd191-5dc3-4a73-9e05-6ac30ca67992/project/36019e0d-ed59-4df6-9990-05bb7fc793b6/hashicorp.consul.linked-cluster/prod-on-prem"
func (r Resource) String() string {
return strings.Join([]string{
tokenOrganization, r.Organization,
Expand Down Expand Up @@ -130,6 +133,7 @@ func (r *Resource) UnmarshalJSON(bytes []byte) error {
// Must is a helper function that wraps a call to a function returning (Resource, error) such as FromLink or FromString
// and panics if the error is non-nil. It is intended for use in variable
// initializations such as
//
// var packageResource = resource.Must(resource.FromString("..."))
func Must(r Resource, err error) Resource {
if err != nil {
Expand Down

0 comments on commit c9c7d25

Please sign in to comment.