From 003c38e9be526e0f367bf7e99ebe0c418c0de902 Mon Sep 17 00:00:00 2001 From: Brandon Croft Date: Wed, 30 Nov 2022 11:37:45 -0700 Subject: [PATCH 1/3] Fix or ignore all outsanding golangci-lint errors As reported by "make lint" Also fixed incorrect build tag in two tests that were causing the tests to be skipped Thanks to @estenssoros for the efforts to improve the code! Co-Authored-By: Sebastian Estenssoro --- .golangci.yml | 14 ++- ...etting_cost_estimation_integration_test.go | 4 +- admin_setting_saml_integration_test.go | 4 +- admin_terraform_version_integration_test.go | 6 +- admin_user_integration_test.go | 1 - admin_workspace_integration_test.go | 4 +- agent_pool_integration_test.go | 1 - configuration_version.go | 4 +- docs/CONTRIBUTING.md | 4 +- errors.go | 2 +- helper_test.go | 86 +++++++++++-------- ip_ranges.go | 2 +- notification_configuration.go | 1 - organization_membership_integration_test.go | 2 +- policy_evaluation_beta_test.go | 2 - project.go | 2 +- projects_integration_test.go | 6 +- registry_module.go | 8 +- registry_module_integration_test.go | 3 - registry_provider_integration_test.go | 1 - ...stry_provider_platform_integration_test.go | 22 ++--- registry_provider_version_integration_test.go | 39 ++++----- request.go | 4 +- run_task_integration_test.go | 3 +- state_version_integration_test.go | 7 +- task_stages_integration_beta_test.go | 6 +- tfe.go | 11 +-- tfe_integration_test.go | 65 +++++++------- workspace_integration_test.go | 20 ++--- workspace_run_task_integration_test.go | 6 +- 30 files changed, 174 insertions(+), 166 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 0fa0a95c6..400abe6ea 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -20,19 +20,27 @@ linters: - misspell #https://github.com/client9/misspell issues: exclude-rules: + - path: tfe_integration_test.go + linters: + - errcheck # Many calls in this test are known to return an error and not checked + - linters: + - stylecheck + text: "Ascii" # Permanently part of the public interface unless we break the API - path: _test\.go linters: - unused - deadcode + - unparam linters-settings: errcheck: # https://github.com/kisielk/errcheck#excluding-functions check-type-assertions: true - check-blank: true + check-blank: true goconst: - min-len: 20 - min-occurrences: 5 + min-len: 20 + min-occurrences: 5 ignore-calls: false + ignore-tests: true gocritic: enabled-tags: - diagnostic diff --git a/admin_setting_cost_estimation_integration_test.go b/admin_setting_cost_estimation_integration_test.go index 9d6903ae2..6847985db 100644 --- a/admin_setting_cost_estimation_integration_test.go +++ b/admin_setting_cost_estimation_integration_test.go @@ -26,11 +26,11 @@ func TestAdminSettings_CostEstimation_Update(t *testing.T) { client := testClient(t) ctx := context.Background() - costEstimationSettings, err := client.Admin.Settings.CostEstimation.Read(ctx) + _, err := client.Admin.Settings.CostEstimation.Read(ctx) require.NoError(t, err) costEnabled := false - costEstimationSettings, err = client.Admin.Settings.CostEstimation.Update(ctx, AdminCostEstimationSettingOptions{ + costEstimationSettings, err := client.Admin.Settings.CostEstimation.Update(ctx, AdminCostEstimationSettingOptions{ Enabled: Bool(costEnabled), }) require.NoError(t, err) diff --git a/admin_setting_saml_integration_test.go b/admin_setting_saml_integration_test.go index ce9f606c2..48f95bf91 100644 --- a/admin_setting_saml_integration_test.go +++ b/admin_setting_saml_integration_test.go @@ -42,13 +42,13 @@ func TestAdminSettings_SAML_Update(t *testing.T) { client := testClient(t) ctx := context.Background() - samlSettings, err := client.Admin.Settings.SAML.Read(ctx) + _, err := client.Admin.Settings.SAML.Read(ctx) require.NoError(t, err) enabled := false debug := false - samlSettings, err = client.Admin.Settings.SAML.Update(ctx, AdminSAMLSettingsUpdateOptions{ + samlSettings, err := client.Admin.Settings.SAML.Update(ctx, AdminSAMLSettingsUpdateOptions{ Enabled: Bool(enabled), Debug: Bool(debug), }) diff --git a/admin_terraform_version_integration_test.go b/admin_terraform_version_integration_test.go index 1e486f4bf..0fa84b293 100644 --- a/admin_terraform_version_integration_test.go +++ b/admin_terraform_version_integration_test.go @@ -103,7 +103,7 @@ func TestAdminTerraformVersions_CreateDelete(t *testing.T) { opts := AdminTerraformVersionCreateOptions{ Version: String(version), URL: String("https://www.hashicorp.com"), - Sha: String(genSha(t, "secret", "data")), + Sha: String(genSha(t)), Deprecated: Bool(true), DeprecatedReason: String("Test Reason"), Official: Bool(false), @@ -133,7 +133,7 @@ func TestAdminTerraformVersions_CreateDelete(t *testing.T) { opts := AdminTerraformVersionCreateOptions{ Version: String(version), URL: String("https://www.hashicorp.com"), - Sha: String(genSha(t, "secret", "data")), + Sha: String(genSha(t)), } tfv, err := client.Admin.TerraformVersions.Create(ctx, opts) require.NoError(t, err) @@ -170,7 +170,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) { opts := AdminTerraformVersionCreateOptions{ Version: String(version), URL: String("https://www.hashicorp.com"), - Sha: String(genSha(t, "secret", "data")), + Sha: String(genSha(t)), Official: Bool(false), Deprecated: Bool(true), DeprecatedReason: String("Test Reason"), diff --git a/admin_user_integration_test.go b/admin_user_integration_test.go index f71152fbf..a76d142ac 100644 --- a/admin_user_integration_test.go +++ b/admin_user_integration_test.go @@ -130,7 +130,6 @@ func TestAdminUsers_Delete(t *testing.T) { assert.Empty(t, ul.Items) assert.Equal(t, 1, ul.CurrentPage) assert.Equal(t, 0, ul.TotalCount) - }) t.Run("an non-existing user", func(t *testing.T) { diff --git a/admin_workspace_integration_test.go b/admin_workspace_integration_test.go index 60369e9cd..40baf59ec 100644 --- a/admin_workspace_integration_test.go +++ b/admin_workspace_integration_test.go @@ -130,7 +130,7 @@ func TestAdminWorkspaces_Read(t *testing.T) { assert.Nil(t, workspace) }) - t.Run("it fails to read a workspace that is non existant", func(t *testing.T) { + t.Run("it fails to read a workspace that is non existent", func(t *testing.T) { workspaceID := fmt.Sprintf("non-existent-%s", randomString(t)) adminWorkspace, err := client.Admin.Workspaces.Read(ctx, workspaceID) require.Error(t, err) @@ -138,7 +138,7 @@ func TestAdminWorkspaces_Read(t *testing.T) { assert.Nil(t, adminWorkspace) }) - t.Run("it reads a worksapce successfully", func(t *testing.T) { + t.Run("it reads a workspace successfully", func(t *testing.T) { org, orgCleanup := createOrganization(t, client) defer orgCleanup() diff --git a/agent_pool_integration_test.go b/agent_pool_integration_test.go index fbbfd4f5f..5c6014233 100644 --- a/agent_pool_integration_test.go +++ b/agent_pool_integration_test.go @@ -69,7 +69,6 @@ func TestAgentPoolsList(t *testing.T) { }) t.Run("with query options", func(t *testing.T) { - pools, err := client.AgentPools.List(ctx, orgTest.Name, &AgentPoolListOptions{ Query: agentPool.Name, }) diff --git a/configuration_version.go b/configuration_version.go index 07d378644..24ed280fd 100644 --- a/configuration_version.go +++ b/configuration_version.go @@ -252,13 +252,13 @@ func (s *configurationVersions) ReadWithOptions(ctx context.Context, cvID string // Upload packages and uploads Terraform configuration files. It requires the // upload URL from a configuration version and the path to the configuration // files on disk. -func (s *configurationVersions) Upload(ctx context.Context, url string, path string) error { +func (s *configurationVersions) Upload(ctx context.Context, uploadURL, path string) error { body, err := packContents(path) if err != nil { return err } - req, err := s.client.NewRequest("PUT", url, body) + req, err := s.client.NewRequest("PUT", uploadURL, body) if err != nil { return err } diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index c6e2b22a6..8cb7323c1 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -16,7 +16,9 @@ There are instances where several new resources being added (i.e Workspace Run T **Note HashiCorp Employees Only:** When submitting a new set of endpoints please ensure that one of your respective team members approves the changes as well before merging. -## Running the Linters Locally +## Linting + +Linting is not necessarily required for a change to be merged, but it helps smooth the review process and catch common mistakes early. If you'd like to run the linters manually, follow these steps: 1. Ensure you have [installed golangci-lint](https://golangci-lint.run/usage/install/#local-installation) 2. From the CLI, run `make lint` diff --git a/errors.go b/errors.go index ff17994b0..ca5301c8a 100644 --- a/errors.go +++ b/errors.go @@ -313,7 +313,7 @@ var ( ErrRequiredFilename = errors.New("filename is required") - ErrInvalidAsciiArmor = errors.New("ascii armor is invalid") + ErrInvalidAsciiArmor = errors.New("ASCII Armor is invalid") ErrRequiredNamespace = errors.New("namespace is required for public registry") diff --git a/helper_test.go b/helper_test.go index 5548f79e1..be1cbef28 100644 --- a/helper_test.go +++ b/helper_test.go @@ -114,16 +114,16 @@ func fetchTestAccountDetails(t *testing.T, client *Client) *TestAccountDetails { return _testAccountDetails } -func downloadFile(filepath string, url string) error { +func downloadFile(filePath, fileURL string) error { // Get the data - resp, err := http.Get(url) + resp, err := http.Get(fileURL) if err != nil { return err } defer resp.Body.Close() // Create the file - out, err := os.Create(filepath) + out, err := os.Create(filePath) if err != nil { return err } @@ -145,11 +145,13 @@ func unzip(src, dest string) error { } }() - os.MkdirAll(dest, 0755) + if err := os.MkdirAll(dest, 0o755); err != nil { + return err + } // Closure to address file descriptors issue with all the deferred .Close() methods - extractAndWriteFile := func(f *zip.File) error { - rc, err := f.Open() + extractAndWriteFile := func(zf *zip.File) error { + rc, err := zf.Open() if err != nil { return err } @@ -159,32 +161,34 @@ func unzip(src, dest string) error { } }() - path := filepath.Join(dest, f.Name) + path := filepath.Join(dest, zf.Name) // Check for ZipSlip (Directory traversal) if !strings.HasPrefix(path, filepath.Clean(dest)+string(os.PathSeparator)) { return fmt.Errorf("illegal file path: %s", path) } - if f.FileInfo().IsDir() { - os.MkdirAll(path, f.Mode()) - } else { - os.MkdirAll(filepath.Dir(path), f.Mode()) - f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()) - if err != nil { - return err + if zf.FileInfo().IsDir() { + return os.MkdirAll(path, zf.Mode()) + } + if err := os.MkdirAll(filepath.Dir(path), zf.Mode()); err != nil { + return err + } + f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, zf.Mode()) + if err != nil { + return err + } + defer func() { + if err := f.Close(); err != nil { + panic(err) } - defer func() { - if err := f.Close(); err != nil { - panic(err) - } - }() + }() - _, err = io.Copy(f, rc) - if err != nil { - return err - } + _, err = io.Copy(f, rc) + if err != nil { + return err } + return nil } @@ -226,6 +230,7 @@ func createAgent(t *testing.T, client *Client, org *Organization) (*Agent, *Agen var orgCleanup func() var agentPoolTokenCleanup func() var agent *Agent + var ok bool if org == nil { org, orgCleanup = createOrganization(t, client) @@ -258,9 +263,11 @@ func createAgent(t *testing.T, client *Client, org *Organization) (*Agent, *Agen cmd := exec.Command(agentPath) cmd.Env = os.Environ() - cmd.Env = append(cmd.Env, "TFC_AGENT_TOKEN="+agentPoolToken.Token) - cmd.Env = append(cmd.Env, "TFC_AGENT_NAME="+"test-agent") - cmd.Env = append(cmd.Env, "TFC_ADDRESS="+DefaultConfig().Address) + cmd.Env = append(cmd.Env, + "TFC_AGENT_TOKEN="+agentPoolToken.Token, + "TFC_AGENT_NAME="+"test-agent", + "TFC_ADDRESS="+DefaultConfig().Address, + ) go func() { _, err := cmd.CombinedOutput() @@ -270,11 +277,12 @@ func createAgent(t *testing.T, client *Client, org *Organization) (*Agent, *Agen }() t.Cleanup(func() { - cmd.Process.Kill() + if err := cmd.Process.Kill(); err != nil { + t.Error(err) + } }) i, err := retry(func() (interface{}, error) { - agentList, err := client.Agents.List(ctx, agentPool.ID, nil) if err != nil { return nil, err @@ -290,7 +298,10 @@ func createAgent(t *testing.T, client *Client, org *Organization) (*Agent, *Agen t.Fatalf("Could not return an agent %s", err) } - agent = i.(*Agent) + agent, ok = i.(*Agent) + if !ok { + t.Fatalf("Expected type to be *Agent but got %T", agent) + } return agent, agentPool, cleanup } @@ -926,9 +937,8 @@ func createPolicyCheckedRun(t *testing.T, client *Client, w *Workspace) (*Run, f func createPlannedRun(t *testing.T, client *Client, w *Workspace) (*Run, func()) { if paidFeaturesDisabled() { return createRunWaitForStatus(t, client, w, RunPlanned) - } else { - return createRunWaitForStatus(t, client, w, RunCostEstimated) } + return createRunWaitForStatus(t, client, w, RunCostEstimated) } func createCostEstimatedRun(t *testing.T, client *Client, w *Workspace) (*Run, func()) { @@ -1403,7 +1413,7 @@ func createRegistryProviderPlatform(t *testing.T, client *Client, provider *Regi options := RegistryProviderPlatformCreateOptions{ OS: randomString(t), Arch: randomString(t), - Shasum: genSha(t, "secret", "data"), + Shasum: genSha(t), Filename: randomString(t), } @@ -1856,7 +1866,7 @@ func createVariableSet(t *testing.T, client *Client, org *Organization, options } } -func applyVariableSetToWorkspace(t *testing.T, client *Client, vsID string, wsID string) { +func applyVariableSetToWorkspace(t *testing.T, client *Client, vsID, wsID string) { if vsID == "" { t.Fatal("variable set ID must not be empty") } @@ -2077,9 +2087,10 @@ func retry(f retryableFn) (interface{}, error) { //nolint return retryTimes(9, 3, f) // 10 attempts over 30 seconds } -func genSha(t *testing.T, secret, data string) string { - h := hmac.New(sha256.New, []byte(secret)) - _, err := h.Write([]byte(data)) +func genSha(t *testing.T) string { + t.Helper() + h := hmac.New(sha256.New, []byte("secret")) + _, err := h.Write([]byte("data")) if err != nil { t.Fatalf("error writing hmac: %s", err) } @@ -2116,7 +2127,7 @@ func randomStringWithoutSpecialChar(t *testing.T) string { if err != nil { t.Fatal(err) } - uuidWithoutHyphens := strings.Replace(v, "-", "", -1) + uuidWithoutHyphens := strings.ReplaceAll(v, "-", "") return uuidWithoutHyphens } @@ -2130,6 +2141,7 @@ func containsProject(pl []*Project, str string) bool { } func randomSemver(t *testing.T) string { + t.Helper() return fmt.Sprintf("%d.%d.%d", rand.Intn(99)+3, rand.Intn(99)+1, rand.Intn(99)+1) } diff --git a/ip_ranges.go b/ip_ranges.go index 07fc61956..cfb361e0d 100644 --- a/ip_ranges.go +++ b/ip_ranges.go @@ -47,7 +47,7 @@ func (i *ipRanges) Read(ctx context.Context, modifiedSince string) (*IPRange, er } ir := &IPRange{} - err = req.doIpRanges(ctx, ir) + err = req.doIPRanges(ctx, ir) if err != nil { return nil, err } diff --git a/notification_configuration.go b/notification_configuration.go index afdd3cfa6..f2e7eb1c0 100644 --- a/notification_configuration.go +++ b/notification_configuration.go @@ -326,7 +326,6 @@ func (o NotificationConfigurationCreateOptions) valid() error { if *o.DestinationType == NotificationDestinationTypeGeneric || *o.DestinationType == NotificationDestinationTypeSlack || *o.DestinationType == NotificationDestinationTypeMicrosoftTeams { - if o.URL == nil { return ErrRequiredURL } diff --git a/organization_membership_integration_test.go b/organization_membership_integration_test.go index bd36ae238..7ee599eaa 100644 --- a/organization_membership_integration_test.go +++ b/organization_membership_integration_test.go @@ -50,7 +50,7 @@ func TestOrganizationMembershipsList(t *testing.T) { assert.Empty(t, ml.Items) assert.Equal(t, 999, ml.CurrentPage) - // Three because the creator of the organizaiton is a member, in addition to the two we added to setup the test. + // Three because the creator of the organization is a member, in addition to the two we added to setup the test. assert.Equal(t, 3, ml.TotalCount) }) diff --git a/policy_evaluation_beta_test.go b/policy_evaluation_beta_test.go index 8358029b7..8813a5ac6 100644 --- a/policy_evaluation_beta_test.go +++ b/policy_evaluation_beta_test.go @@ -57,7 +57,6 @@ func TestPolicyEvaluationList_Beta(t *testing.T) { }) t.Run("with a invalid policy evaluation ID", func(t *testing.T) { - policyEvaluationeID := "invalid ID" _, err := client.PolicyEvaluations.List(ctx, policyEvaluationeID, nil) @@ -239,7 +238,6 @@ func TestPolicySetOutcomeRead_Beta(t *testing.T) { }) t.Run("with a invalid policy set outcome ID", func(t *testing.T) { - policySetOutcomeID := "invalid ID" _, err := client.PolicySetOutcomes.Read(ctx, policySetOutcomeID) diff --git a/project.go b/project.go index b05b59677..d153c76c1 100644 --- a/project.go +++ b/project.go @@ -27,7 +27,7 @@ type Projects interface { // Update a project. Update(ctx context.Context, projectID string, options ProjectUpdateOptions) (*Project, error) - //Delete a project. + // Delete a project. Delete(ctx context.Context, projectID string) error } diff --git a/projects_integration_test.go b/projects_integration_test.go index 60dff1702..64780e82c 100644 --- a/projects_integration_test.go +++ b/projects_integration_test.go @@ -1,13 +1,11 @@ -//go:build integration -// +build integration - package tfe import ( "context" - "github.com/stretchr/testify/assert" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) diff --git a/registry_module.go b/registry_module.go index ee8698ff2..641474559 100644 --- a/registry_module.go +++ b/registry_module.go @@ -217,13 +217,13 @@ type RegistryModuleVCSRepoOptions struct { } // List all the registory modules within an organization. -func (s *registryModules) List(ctx context.Context, organization string, options *RegistryModuleListOptions) (*RegistryModuleList, error) { +func (r *registryModules) List(ctx context.Context, organization string, options *RegistryModuleListOptions) (*RegistryModuleList, error) { if !validStringID(&organization) { return nil, ErrInvalidOrg } u := fmt.Sprintf("organizations/%s/registry-modules", url.QueryEscape(organization)) - req, err := s.client.NewRequest("GET", u, options) + req, err := r.client.NewRequest("GET", u, options) if err != nil { return nil, err } @@ -306,9 +306,9 @@ func (r *registryModules) Update(ctx context.Context, moduleID RegistryModuleID, namespace := url.QueryEscape(moduleID.Namespace) name := url.QueryEscape(moduleID.Name) provider := url.QueryEscape(moduleID.Provider) - url := fmt.Sprintf("organizations/%s/registry-modules/%s/%s/%s/%s", org, registryName, namespace, name, provider) + registryModuleURL := fmt.Sprintf("organizations/%s/registry-modules/%s/%s/%s/%s", org, registryName, namespace, name, provider) - req, err := r.client.NewRequest(http.MethodPatch, url, &options) + req, err := r.client.NewRequest(http.MethodPatch, registryModuleURL, &options) if err != nil { return nil, err } diff --git a/registry_module_integration_test.go b/registry_module_integration_test.go index 6ba3dabe1..86b54abcd 100644 --- a/registry_module_integration_test.go +++ b/registry_module_integration_test.go @@ -294,7 +294,6 @@ func TestRegistryModuleUpdate(t *testing.T) { require.NoError(t, err) assert.False(t, rm.NoCode) }) - } func TestRegistryModulesCreateVersion(t *testing.T) { @@ -441,7 +440,6 @@ func TestRegistryModulesCreateVersion(t *testing.T) { assert.Nil(t, rmv) assert.EqualError(t, err, ErrInvalidOrg.Error()) }) - } func TestRegistryModulesCreateWithVCSConnection(t *testing.T) { @@ -547,7 +545,6 @@ func TestRegistryModulesCreateWithVCSConnection(t *testing.T) { assert.Nil(t, rm) assert.Equal(t, err, ErrRequiredVCSRepo) }) - } func TestRegistryModulesRead(t *testing.T) { diff --git a/registry_provider_integration_test.go b/registry_provider_integration_test.go index 2f8e41a58..02c545b8b 100644 --- a/registry_provider_integration_test.go +++ b/registry_provider_integration_test.go @@ -161,7 +161,6 @@ func TestRegistryProvidersCreate(t *testing.T) { defer orgTestCleanup() t.Run("with valid options", func(t *testing.T) { - publicProviderOptions := RegistryProviderCreateOptions{ Name: "provider_name", Namespace: "public_namespace", diff --git a/registry_provider_platform_integration_test.go b/registry_provider_platform_integration_test.go index bf9b49f1a..49f452191 100644 --- a/registry_provider_platform_integration_test.go +++ b/registry_provider_platform_integration_test.go @@ -66,9 +66,9 @@ func TestRegistryProviderPlatformsCreate(t *testing.T) { Filename: "filename", } - sad_rpp, err := client.RegistryProviderPlatforms.Create(ctx, versionID, options) + sadRpp, err := client.RegistryProviderPlatforms.Create(ctx, versionID, options) - assert.Nil(t, sad_rpp) + assert.Nil(t, sadRpp) assert.EqualError(t, err, ErrRequiredOS.Error()) }) @@ -80,9 +80,9 @@ func TestRegistryProviderPlatformsCreate(t *testing.T) { Filename: "filename", } - sad_rpp, err := client.RegistryProviderPlatforms.Create(ctx, versionID, options) + sadRpp, err := client.RegistryProviderPlatforms.Create(ctx, versionID, options) - assert.Nil(t, sad_rpp) + assert.Nil(t, sadRpp) assert.EqualError(t, err, ErrRequiredArch.Error()) }) @@ -94,9 +94,9 @@ func TestRegistryProviderPlatformsCreate(t *testing.T) { Filename: "filename", } - sad_rpp, err := client.RegistryProviderPlatforms.Create(ctx, versionID, options) + sadRpp, err := client.RegistryProviderPlatforms.Create(ctx, versionID, options) - assert.Nil(t, sad_rpp) + assert.Nil(t, sadRpp) assert.EqualError(t, err, ErrRequiredShasum.Error()) }) @@ -108,9 +108,9 @@ func TestRegistryProviderPlatformsCreate(t *testing.T) { Filename: "", } - sad_rpp, err := client.RegistryProviderPlatforms.Create(ctx, versionID, options) + sadRpp, err := client.RegistryProviderPlatforms.Create(ctx, versionID, options) - assert.Nil(t, sad_rpp) + assert.Nil(t, sadRpp) assert.EqualError(t, err, ErrRequiredFilename.Error()) }) @@ -195,7 +195,7 @@ func TestRegistryProviderPlatformsDelete(t *testing.T) { require.NoError(t, err) }) - t.Run("with a non-existant version", func(t *testing.T) { + t.Run("with a non-existent version", func(t *testing.T) { platformID := RegistryProviderPlatformID{ RegistryProviderVersionID: versionID, OS: "nope", @@ -262,7 +262,7 @@ func TestRegistryProviderPlatformsRead(t *testing.T) { }) }) - t.Run("with non-existant os", func(t *testing.T) { + t.Run("with non-existent os", func(t *testing.T) { platformID := RegistryProviderPlatformID{ RegistryProviderVersionID: versionID, OS: "DoesNotExist", @@ -273,7 +273,7 @@ func TestRegistryProviderPlatformsRead(t *testing.T) { assert.Error(t, err) }) - t.Run("with non-existant arch", func(t *testing.T) { + t.Run("with non-existent arch", func(t *testing.T) { platformID := RegistryProviderPlatformID{ RegistryProviderVersionID: versionID, OS: platform.OS, diff --git a/registry_provider_version_integration_test.go b/registry_provider_version_integration_test.go index 1c4b4fb72..4680caa78 100644 --- a/registry_provider_version_integration_test.go +++ b/registry_provider_version_integration_test.go @@ -11,19 +11,19 @@ import ( func TestRegistryProviderVersionsIDValidation(t *testing.T) { version := "1.0.0" - validRegistryProviderId := RegistryProviderID{ + validRegistryProviderID := RegistryProviderID{ OrganizationName: "orgName", RegistryName: PrivateRegistry, Namespace: "namespace", Name: "name", } - invalidRegistryProviderId := RegistryProviderID{ + invalidRegistryProviderID := RegistryProviderID{ OrganizationName: badIdentifier, RegistryName: PrivateRegistry, Namespace: "namespace", Name: "name", } - publicRegistryProviderId := RegistryProviderID{ + publicRegistryProviderID := RegistryProviderID{ OrganizationName: "orgName", RegistryName: PublicRegistry, Namespace: "namespace", @@ -33,7 +33,7 @@ func TestRegistryProviderVersionsIDValidation(t *testing.T) { t.Run("valid", func(t *testing.T) { id := RegistryProviderVersionID{ Version: version, - RegistryProviderID: validRegistryProviderId, + RegistryProviderID: validRegistryProviderID, } require.NoError(t, id.valid()) }) @@ -41,7 +41,7 @@ func TestRegistryProviderVersionsIDValidation(t *testing.T) { t.Run("without a version", func(t *testing.T) { id := RegistryProviderVersionID{ Version: "", - RegistryProviderID: validRegistryProviderId, + RegistryProviderID: validRegistryProviderID, } assert.EqualError(t, id.valid(), ErrInvalidVersion.Error()) }) @@ -49,7 +49,7 @@ func TestRegistryProviderVersionsIDValidation(t *testing.T) { t.Run("without a key-id", func(t *testing.T) { id := RegistryProviderVersionID{ Version: "", - RegistryProviderID: validRegistryProviderId, + RegistryProviderID: validRegistryProviderID, } assert.EqualError(t, id.valid(), ErrInvalidVersion.Error()) }) @@ -58,7 +58,7 @@ func TestRegistryProviderVersionsIDValidation(t *testing.T) { t.Skip("This is skipped as we don't actually validate version is a valid semver - the registry does this validation") id := RegistryProviderVersionID{ Version: "foo", - RegistryProviderID: validRegistryProviderId, + RegistryProviderID: validRegistryProviderID, } assert.EqualError(t, id.valid(), ErrInvalidVersion.Error()) }) @@ -66,7 +66,7 @@ func TestRegistryProviderVersionsIDValidation(t *testing.T) { t.Run("invalid registry for parent provider", func(t *testing.T) { id := RegistryProviderVersionID{ Version: version, - RegistryProviderID: publicRegistryProviderId, + RegistryProviderID: publicRegistryProviderID, } assert.EqualError(t, id.valid(), ErrRequiredPrivateRegistry.Error()) }) @@ -76,7 +76,7 @@ func TestRegistryProviderVersionsIDValidation(t *testing.T) { // it is assumed that validity of the registry provider id is delegated to its own valid method id := RegistryProviderVersionID{ Version: version, - RegistryProviderID: invalidRegistryProviderId, + RegistryProviderID: invalidRegistryProviderID, } assert.EqualError(t, id.valid(), ErrInvalidOrg.Error()) }) @@ -89,7 +89,7 @@ func TestRegistryProviderVersionsCreate(t *testing.T) { providerTest, providerTestCleanup := createRegistryProvider(t, client, nil, PrivateRegistry) defer providerTestCleanup() - providerId := RegistryProviderID{ + providerID := RegistryProviderID{ OrganizationName: providerTest.Organization.Name, RegistryName: providerTest.RegistryName, Namespace: providerTest.Namespace, @@ -101,7 +101,7 @@ func TestRegistryProviderVersionsCreate(t *testing.T) { Version: "1.0.0", KeyID: "abcdefg", } - prvv, err := client.RegistryProviderVersions.Create(ctx, providerId, options) + prvv, err := client.RegistryProviderVersions.Create(ctx, providerID, options) require.NoError(t, err) assert.NotEmpty(t, prvv.ID) assert.Equal(t, options.Version, prvv.Version) @@ -145,7 +145,7 @@ func TestRegistryProviderVersionsCreate(t *testing.T) { Version: "", KeyID: "abcdefg", } - rm, err := client.RegistryProviderVersions.Create(ctx, providerId, options) + rm, err := client.RegistryProviderVersions.Create(ctx, providerID, options) assert.Nil(t, rm) assert.EqualError(t, err, ErrInvalidVersion.Error()) }) @@ -155,7 +155,7 @@ func TestRegistryProviderVersionsCreate(t *testing.T) { Version: "1.0.0", KeyID: "", } - rm, err := client.RegistryProviderVersions.Create(ctx, providerId, options) + rm, err := client.RegistryProviderVersions.Create(ctx, providerID, options) assert.Nil(t, rm) assert.EqualError(t, err, ErrInvalidKeyID.Error()) }) @@ -165,13 +165,13 @@ func TestRegistryProviderVersionsCreate(t *testing.T) { Version: "1.0.0", KeyID: "abcdefg", } - providerId := RegistryProviderID{ + providerID := RegistryProviderID{ OrganizationName: providerTest.Organization.Name, RegistryName: PublicRegistry, Namespace: providerTest.Namespace, Name: providerTest.Name, } - rm, err := client.RegistryProviderVersions.Create(ctx, providerId, options) + rm, err := client.RegistryProviderVersions.Create(ctx, providerID, options) assert.Nil(t, rm) assert.EqualError(t, err, ErrRequiredPrivateRegistry.Error()) }) @@ -181,13 +181,13 @@ func TestRegistryProviderVersionsCreate(t *testing.T) { Version: "1.0.0", KeyID: "abcdefg", } - providerId := RegistryProviderID{ + providerID := RegistryProviderID{ OrganizationName: badIdentifier, RegistryName: providerTest.RegistryName, Namespace: providerTest.Namespace, Name: providerTest.Name, } - rm, err := client.RegistryProviderVersions.Create(ctx, providerId, options) + rm, err := client.RegistryProviderVersions.Create(ctx, providerID, options) assert.Nil(t, rm) assert.EqualError(t, err, ErrInvalidOrg.Error()) }) @@ -292,10 +292,6 @@ func TestRegistryProviderVersionsList(t *testing.T) { assert.Equal(t, 0, versions.TotalCount) assert.Equal(t, 0, versions.TotalPages) }) - - // TODO - t.Run("with include provider platforms", func(t *testing.T) { - }) } func TestRegistryProviderVersionsDelete(t *testing.T) { @@ -400,5 +396,4 @@ func TestRegistryProviderVersionsRead(t *testing.T) { _, err := client.RegistryProviderVersions.Read(ctx, versionID) assert.Error(t, err) }) - } diff --git a/request.go b/request.go index a84ccfc37..43a63c7c7 100644 --- a/request.go +++ b/request.go @@ -64,9 +64,9 @@ func (r ClientRequest) Do(ctx context.Context, model interface{}) error { return unmarshalResponse(resp.Body, model) } -// doIpRanges is similar to Do except that The IP ranges API is not returning jsonapi +// doIPRanges is similar to Do except that The IP ranges API is not returning jsonapi // like every other endpoint which means we need to handle it differently. -func (r *ClientRequest) doIpRanges(ctx context.Context, ir *IPRange) error { +func (r *ClientRequest) doIPRanges(ctx context.Context, ir *IPRange) error { // Wait will block until the limiter can obtain a new token // or returns an error if the given context is canceled. if err := r.limiter.Wait(ctx); err != nil { diff --git a/run_task_integration_test.go b/run_task_integration_test.go index ab3348f13..c177a1c5b 100644 --- a/run_task_integration_test.go +++ b/run_task_integration_test.go @@ -226,7 +226,8 @@ func TestRunTasksAttachToWorkspace(t *testing.T) { wr, err := client.RunTasks.AttachToWorkspace(ctx, wkspaceTest.ID, runTaskTest.ID, Advisory) defer func() { - client.WorkspaceRunTasks.Delete(ctx, wkspaceTest.ID, wr.ID) + err = client.WorkspaceRunTasks.Delete(ctx, wkspaceTest.ID, wr.ID) + require.NoError(t, err) }() require.NoError(t, err) diff --git a/state_version_integration_test.go b/state_version_integration_test.go index d71f20388..0037e6bb7 100644 --- a/state_version_integration_test.go +++ b/state_version_integration_test.go @@ -316,6 +316,7 @@ func TestStateVersionsRead(t *testing.T) { t.Run("when the state version exists", func(t *testing.T) { var sv *StateVersion + var ok bool sv, err := client.StateVersions.Read(ctx, svTest.ID) require.NoError(t, err) @@ -335,7 +336,10 @@ func TestStateVersionsRead(t *testing.T) { t.Fatalf("error retrying state version read, err=%s", err) } - sv = svRetry.(*StateVersion) + sv, ok = svRetry.(*StateVersion) + if !ok { + t.Fatalf("Expected sv to be type *StateVersion, got %T", sv) + } } assert.NotEmpty(t, sv.DownloadURL) @@ -528,5 +532,4 @@ func TestStateVersionOutputs(t *testing.T) { assert.Nil(t, outputs) assert.Error(t, err) }) - } diff --git a/task_stages_integration_beta_test.go b/task_stages_integration_beta_test.go index cb1f097e6..31a57983f 100644 --- a/task_stages_integration_beta_test.go +++ b/task_stages_integration_beta_test.go @@ -1,6 +1,3 @@ -//go:build integration -// +build integration - package tfe import ( @@ -106,7 +103,6 @@ func TestTaskStagesRead_Beta(t *testing.T) { assert.NotEmpty(t, taskStage.PolicyEvaluations[0].UpdatedAt) assert.NotNil(t, taskStage.PolicyEvaluations[0].ResultCount) }) - }) } @@ -258,7 +254,7 @@ func TestTaskStageOverride_Beta(t *testing.T) { taskStageOverrideOptions := TaskStageOverrideOptions{ Comment: String("test comment"), } - ts, err := client.TaskStages.Override(ctx, taskStageList.Items[0].ID, taskStageOverrideOptions) + _, err = client.TaskStages.Override(ctx, taskStageList.Items[0].ID, taskStageOverrideOptions) require.NoError(t, err) }) diff --git a/tfe.go b/tfe.go index 83556592a..eb5089c7c 100644 --- a/tfe.go +++ b/tfe.go @@ -40,7 +40,8 @@ const ( DefaultBasePath = "/api/v2/" DefaultRegistryPath = "/api/registry/" // PingEndpoint is a no-op API endpoint used to configure the rate limiter - PingEndpoint = "ping" + PingEndpoint = "ping" + ContentTypeJSONAPI = "application/vnd.api+json" ) // RetryLogHook allows a function to run before each retry. @@ -214,7 +215,7 @@ func (c *Client) NewRequestWithAdditionalQueryParams(method, path string, reqAtt var body interface{} switch method { case "GET": - reqHeaders.Set("Accept", "application/vnd.api+json") + reqHeaders.Set("Accept", ContentTypeJSONAPI) if reqAttr != nil { q, err := query.Values(reqAttr) @@ -227,8 +228,8 @@ func (c *Client) NewRequestWithAdditionalQueryParams(method, path string, reqAtt u.RawQuery = encodeQueryParams(q) } case "DELETE", "PATCH", "POST": - reqHeaders.Set("Accept", "application/vnd.api+json") - reqHeaders.Set("Content-Type", "application/vnd.api+json") + reqHeaders.Set("Accept", ContentTypeJSONAPI) + reqHeaders.Set("Content-Type", ContentTypeJSONAPI) if reqAttr != nil { if body, err = serializeRequestBody(reqAttr); err != nil { @@ -571,7 +572,7 @@ func (c *Client) getRawAPIMetadata() (rawAPIMetadata, error) { for k, v := range c.headers { req.Header[k] = v } - req.Header.Set("Accept", "application/vnd.api+json") + req.Header.Set("Accept", ContentTypeJSONAPI) req.Header.Set("Authorization", "Bearer "+c.token) // Make a single request to retrieve the rate limit headers. diff --git a/tfe_integration_test.go b/tfe_integration_test.go index 9b8bd0513..5e033bed1 100644 --- a/tfe_integration_test.go +++ b/tfe_integration_test.go @@ -11,7 +11,6 @@ import ( "testing" "time" - retryablehttp "github.com/hashicorp/go-retryablehttp" "github.com/hashicorp/jsonapi" "github.com/stretchr/testify/assert" "golang.org/x/time/rate" @@ -19,7 +18,7 @@ import ( func TestClient_newClient(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.api+json") + w.Header().Set("Content-Type", ContentTypeJSONAPI) w.Header().Set("X-RateLimit-Limit", "30") w.Header().Set("TFP-API-Version", "34.21.9") w.Header().Set("X-TFE-Version", "202205-1") @@ -129,13 +128,13 @@ func TestClient_headers(t *testing.T) { testedCalls++ if testedCalls == 1 { - w.Header().Set("Content-Type", "application/vnd.api+json") + w.Header().Set("Content-Type", ContentTypeJSONAPI) w.Header().Set("X-RateLimit-Limit", "30") w.WriteHeader(204) // We query the configured ping URL which should return a 204. return } - if r.Header.Get("Accept") != "application/vnd.api+json" { + if r.Header.Get("Accept") != ContentTypeJSONAPI { t.Fatalf("unexpected accept header: %q", r.Header.Get("Accept")) } if r.Header.Get("Authorization") != "Bearer dummy-token" { @@ -175,11 +174,11 @@ func TestClient_headers(t *testing.T) { ctx := context.Background() // Make a few calls so we can check they all send the expected headers. - _, _ = client.Organizations.List(ctx, nil) - _, _ = client.Plans.Logs(ctx, "plan-123456789") - _ = client.Runs.Apply(ctx, "run-123456789", RunApplyOptions{}) - _, _ = client.Workspaces.Lock(ctx, "ws-123456789", WorkspaceLockOptions{}) - _, _ = client.Workspaces.Read(ctx, "organization", "workspace") + client.Organizations.List(ctx, nil) + client.Plans.Logs(ctx, "plan-123456789") + client.Runs.Apply(ctx, "run-123456789", RunApplyOptions{}) + client.Workspaces.Lock(ctx, "ws-123456789", WorkspaceLockOptions{}) + client.Workspaces.Read(ctx, "organization", "workspace") if testedCalls != 6 { t.Fatalf("expected 6 tested calls, got: %d", testedCalls) @@ -192,7 +191,7 @@ func TestClient_userAgent(t *testing.T) { testedCalls++ if testedCalls == 1 { - w.Header().Set("Content-Type", "application/vnd.api+json") + w.Header().Set("Content-Type", ContentTypeJSONAPI) w.Header().Set("X-RateLimit-Limit", "30") w.WriteHeader(204) // We query the configured ping URL which should return a 204. return @@ -222,11 +221,11 @@ func TestClient_userAgent(t *testing.T) { ctx := context.Background() // Make a few calls so we can check they all send the expected headers. - _, _ = client.Organizations.List(ctx, nil) - _, _ = client.Plans.Logs(ctx, "plan-123456789") - _ = client.Runs.Apply(ctx, "run-123456789", RunApplyOptions{}) - _, _ = client.Workspaces.Lock(ctx, "ws-123456789", WorkspaceLockOptions{}) - _, _ = client.Workspaces.Read(ctx, "organization", "workspace") + client.Organizations.List(ctx, nil) + client.Plans.Logs(ctx, "plan-123456789") + client.Runs.Apply(ctx, "run-123456789", RunApplyOptions{}) + client.Workspaces.Lock(ctx, "ws-123456789", WorkspaceLockOptions{}) + client.Workspaces.Read(ctx, "organization", "workspace") if testedCalls != 6 { t.Fatalf("expected 6 tested calls, got: %d", testedCalls) @@ -249,7 +248,7 @@ type InvalidBody struct { func TestClient_requestBodySerialization(t *testing.T) { t.Run("jsonapi request", func(t *testing.T) { body := JSONAPIBody{StrAttr: "foo"} - _, requestBody, err := createRequest(&body) + requestBody, err := createRequest(&body) if err != nil { t.Fatal(err) } @@ -267,7 +266,7 @@ func TestClient_requestBodySerialization(t *testing.T) { t.Run("jsonapi slice of pointers request", func(t *testing.T) { var body []*JSONAPIBody body = append(body, &JSONAPIBody{StrAttr: "foo"}) - _, requestBody, err := createRequest(body) + requestBody, err := createRequest(body) if err != nil { t.Fatal(err) } @@ -288,7 +287,7 @@ func TestClient_requestBodySerialization(t *testing.T) { t.Run("plain json request", func(t *testing.T) { body := JSONPlainBody{StrAttr: "foo"} - _, requestBody, err := createRequest(&body) + requestBody, err := createRequest(&body) if err != nil { t.Fatal(err) } @@ -306,7 +305,7 @@ func TestClient_requestBodySerialization(t *testing.T) { t.Run("plain json slice of pointers request", func(t *testing.T) { var body []*JSONPlainBody body = append(body, &JSONPlainBody{StrAttr: "foo"}) - _, requestBody, err := createRequest(body) + requestBody, err := createRequest(body) if err != nil { t.Fatal(err) } @@ -322,7 +321,7 @@ func TestClient_requestBodySerialization(t *testing.T) { }) t.Run("nil request", func(t *testing.T) { - _, requestBody, err := createRequest(nil) + requestBody, err := createRequest(nil) if err != nil { t.Fatal(err) } @@ -333,7 +332,7 @@ func TestClient_requestBodySerialization(t *testing.T) { t.Run("invalid struct request", func(t *testing.T) { body := InvalidBody{} - _, _, err := createRequest(&body) + _, err := createRequest(&body) if err == nil || err != ErrInvalidStructFormat { t.Fatalf("unexpected error: %v", err) } @@ -341,7 +340,7 @@ func TestClient_requestBodySerialization(t *testing.T) { t.Run("non-pointer request", func(t *testing.T) { body := InvalidBody{} - _, _, err := createRequest(body) + _, err := createRequest(body) if err == nil || err.Error() != "go-tfe bug: DELETE/PATCH/POST body must be nil, ptr, or ptr slice" { t.Fatalf("unexpected error: %v", err) } @@ -349,7 +348,7 @@ func TestClient_requestBodySerialization(t *testing.T) { t.Run("slice of non-pointer request", func(t *testing.T) { body := []InvalidBody{{}} - _, _, err := createRequest(body) + _, err := createRequest(body) if err == nil || err.Error() != "go-tfe bug: DELETE/PATCH/POST body must be nil, ptr, or ptr slice" { t.Fatalf("unexpected error: %v", err) } @@ -357,7 +356,7 @@ func TestClient_requestBodySerialization(t *testing.T) { t.Run("map request", func(t *testing.T) { body := make(map[string]string) - _, _, err := createRequest(body) + _, err := createRequest(body) if err == nil || err.Error() != "go-tfe bug: DELETE/PATCH/POST body must be nil, ptr, or ptr slice" { t.Fatalf("unexpected error: %v", err) } @@ -365,36 +364,36 @@ func TestClient_requestBodySerialization(t *testing.T) { t.Run("string request", func(t *testing.T) { body := "foo" - _, _, err := createRequest(body) + _, err := createRequest(body) if err == nil || err.Error() != "go-tfe bug: DELETE/PATCH/POST body must be nil, ptr, or ptr slice" { t.Fatalf("unexpected error: %v", err) } }) } -func createRequest(v interface{}) (*retryablehttp.Request, []byte, error) { +func createRequest(v interface{}) ([]byte, error) { config := DefaultConfig() config.Token = "dummy" client, err := NewClient(config) if err != nil { - return nil, nil, err + return nil, err } request, err := client.NewRequest("POST", "/bar", v) if err != nil { - return nil, nil, err + return nil, err } body, err := request.retryableRequest.BodyBytes() if err != nil { - return request.retryableRequest, nil, err + return nil, err } - return request.retryableRequest, body, nil + return body, nil } func TestClient_configureLimiter(t *testing.T) { rateLimit := "" ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.api+json") + w.Header().Set("Content-Type", ContentTypeJSONAPI) w.Header().Set("X-RateLimit-Limit", rateLimit) w.WriteHeader(204) // We query the configured ping URL which should return a 204. })) @@ -454,7 +453,7 @@ func TestClient_configureLimiter(t *testing.T) { func TestClient_retryHTTPCheck(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.api+json") + w.Header().Set("Content-Type", ContentTypeJSONAPI) w.Header().Set("X-RateLimit-Limit", "30") w.WriteHeader(204) // We query the configured ping URL which should return a 204. })) @@ -536,7 +535,7 @@ func TestClient_retryHTTPCheck(t *testing.T) { func TestClient_retryHTTPBackoff(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.api+json") + w.Header().Set("Content-Type", ContentTypeJSONAPI) w.Header().Set("X-RateLimit-Limit", "30") w.WriteHeader(204) // We query the configured ping URL which should return a 204. })) diff --git a/workspace_integration_test.go b/workspace_integration_test.go index 1e01923be..417fe424e 100644 --- a/workspace_integration_test.go +++ b/workspace_integration_test.go @@ -166,14 +166,15 @@ func TestWorkspacesList(t *testing.T) { foundWTest1 := false for _, ws := range wl.Items { - if ws.ID == wTest1.ID { - foundWTest1 = true - require.NotNil(t, wl.Items[0].CurrentStateVersion) - assert.NotEmpty(t, wl.Items[0].CurrentStateVersion.DownloadURL) - - require.NotNil(t, wl.Items[0].CurrentRun) - assert.NotEmpty(t, wl.Items[0].CurrentRun.Message) + if ws.ID != wTest1.ID { + continue } + foundWTest1 = true + require.NotNil(t, wl.Items[0].CurrentStateVersion) + assert.NotEmpty(t, wl.Items[0].CurrentStateVersion.DownloadURL) + + require.NotNil(t, wl.Items[0].CurrentRun) + assert.NotEmpty(t, wl.Items[0].CurrentRun.Message) } assert.True(t, foundWTest1) @@ -1827,7 +1828,6 @@ func TestWorkspaces_UpdateRemoteStateConsumers(t *testing.T) { require.NoError(t, err) assert.Equal(t, 1, len(rsc.Items)) assert.Contains(t, rsc.Items, wTestConsumer2) - }) t.Run("with invalid options", func(t *testing.T) { @@ -2080,7 +2080,8 @@ func TestWorkspace_Unmarshal(t *testing.T) { require.NoError(t, err) iso8601TimeFormat := "2006-01-02T15:04:05Z" - parsedTime, _ := time.Parse(iso8601TimeFormat, "2020-07-15T23:38:43.821Z") + parsedTime, err := time.Parse(iso8601TimeFormat, "2020-07-15T23:38:43.821Z") + assert.NoError(t, err) assert.Equal(t, ws.ID, "ws-1234") assert.Equal(t, ws.Name, "my-workspace") @@ -2181,5 +2182,4 @@ func TestWorkspacesProjects(t *testing.T) { assert.NotNil(t, item.Project.ID, "No project ID set on workspace %s at idx %d", item.ID, idx) } }) - } diff --git a/workspace_run_task_integration_test.go b/workspace_run_task_integration_test.go index 889f763e1..0b952b345 100644 --- a/workspace_run_task_integration_test.go +++ b/workspace_run_task_integration_test.go @@ -31,7 +31,8 @@ func TestWorkspaceRunTasksCreate(t *testing.T) { require.NoError(t, err) defer func() { - client.WorkspaceRunTasks.Delete(ctx, wkspaceTest.ID, wr.ID) + err = client.WorkspaceRunTasks.Delete(ctx, wkspaceTest.ID, wr.ID) + require.NoError(t, err) }() assert.NotEmpty(t, wr.ID) @@ -70,7 +71,8 @@ func TestWorkspaceRunTasksCreateBeta(t *testing.T) { require.NoError(t, err) defer func() { - client.WorkspaceRunTasks.Delete(ctx, wkspaceTest.ID, wr.ID) + err = client.WorkspaceRunTasks.Delete(ctx, wkspaceTest.ID, wr.ID) + require.NoError(t, err) }() assert.NotEmpty(t, wr.ID) From db37cb5388ebc1fb3e9c46ba74cfdcc7ec3ac2e7 Mon Sep 17 00:00:00 2001 From: Brandon Croft Date: Wed, 30 Nov 2022 11:49:58 -0700 Subject: [PATCH 2/3] Is the linter GHA broken? --- .github/workflows/golangci-lint.yml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index d799b55a6..6f31c4a1b 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -9,15 +9,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Set local Go version - run: | - VERSION=`cat .go-version| awk '{printf$1}'` - echo "go_version=$VERSION" >> $GITHUB_ENV - - name: Setup Go Environment - uses: actions/setup-go@v3 + - uses: actions/setup-go@v3 with: - go-version: "${{ env.go_version }}" - - name: golangci-lint - uses: golangci/golangci-lint-action@v2 + go-version-file: 'go.mod' + - uses: golangci/golangci-lint-action@v3 with: version: v1.42 From 983c77ade771118418106759cd352e21b1541e86 Mon Sep 17 00:00:00 2001 From: Brandon Croft Date: Wed, 30 Nov 2022 11:56:29 -0700 Subject: [PATCH 3/3] Update golangci-lint.yml --- .github/workflows/golangci-lint.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 6f31c4a1b..25db4f294 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -1,11 +1,10 @@ name: Linter on: push: - branches: [ main ] + branches: [main] pull_request: jobs: - golangci: - name: lint + lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -14,4 +13,4 @@ jobs: go-version-file: 'go.mod' - uses: golangci/golangci-lint-action@v3 with: - version: v1.42 + version: v1.50.1