diff --git a/admin_run_integration_test.go b/admin_run_integration_test.go index 375efb7b1..3b7d4936a 100644 --- a/admin_run_integration_test.go +++ b/admin_run_integration_test.go @@ -13,6 +13,10 @@ import ( "github.com/stretchr/testify/require" ) +const testWhenRunDoesNotExist = "when the run does not exist" +const testQueuedAtTime = "2020-03-16T23:15:59+00:00" +const testWithoutListOptions = "without list options" + func TestAdminRuns_List(t *testing.T) { skipIfCloud(t) @@ -30,7 +34,7 @@ func TestAdminRuns_List(t *testing.T) { rTest2, rTestCleanup2 := createRun(t, client, wTest) defer rTestCleanup2() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { rl, err := client.Admin.Runs.List(ctx, nil) require.NoError(t, err) @@ -173,7 +177,7 @@ func TestAdminRuns_ForceCancel(t *testing.T) { assert.Equal(t, true, rTest2.Actions.IsCancelable) assert.Equal(t, true, rTest2.Permissions.CanForceCancel) - t.Run("when the run does not exist", func(t *testing.T) { + t.Run(testWhenRunDoesNotExist, func(t *testing.T) { err := client.Admin.Runs.ForceCancel(ctx, "nonexisting", AdminRunForceCancelOptions{}) assert.Equal(t, err, ErrResourceNotFound) }) @@ -291,7 +295,7 @@ func TestAdminRun_Unmarshal(t *testing.T) { "has-changes": true, "status": RunApplied, "status-timestamps": map[string]string{ - "plan-queued-at": "2020-03-16T23:15:59+00:00", + "plan-queued-at": testQueuedAtTime, }, }, }, @@ -301,7 +305,7 @@ func TestAdminRun_Unmarshal(t *testing.T) { t.Fatal(err) } - planQueuedParsedTime, err := time.Parse(time.RFC3339, "2020-03-16T23:15:59+00:00") + planQueuedParsedTime, err := time.Parse(time.RFC3339, testQueuedAtTime) require.NoError(t, err) adminRun := &AdminRun{} 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..dfe907b9b 100644 --- a/admin_terraform_version_integration_test.go +++ b/admin_terraform_version_integration_test.go @@ -15,7 +15,7 @@ func TestAdminTerraformVersions_List(t *testing.T) { client := testClient(t) ctx := context.Background() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { tfList, err := client.Admin.TerraformVersions.List(ctx, nil) require.NoError(t, err) @@ -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..fbd2fac05 100644 --- a/admin_user_integration_test.go +++ b/admin_user_integration_test.go @@ -20,7 +20,7 @@ func TestAdminUsers_List(t *testing.T) { org, orgCleanup := createOrganization(t, client) defer orgCleanup() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { ul, err := client.Admin.Users.List(ctx, nil) require.NoError(t, err) @@ -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..6e8b40c54 100644 --- a/admin_workspace_integration_test.go +++ b/admin_workspace_integration_test.go @@ -26,7 +26,7 @@ func TestAdminWorkspaces_List(t *testing.T) { wTest2, wTest2Cleanup := createWorkspace(t, client, org) defer wTest2Cleanup() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { wl, err := client.Admin.Workspaces.List(ctx, nil) require.NoError(t, err) @@ -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..b6c013e3d 100644 --- a/agent_pool_integration_test.go +++ b/agent_pool_integration_test.go @@ -8,6 +8,9 @@ import ( "github.com/stretchr/testify/require" ) +const testWhenOptionsMissingName = "when options is missing name" +const testWithoutValidOrganization = "without a valid organization" + func TestAgentPoolsList(t *testing.T) { client := testClient(t) ctx := context.Background() @@ -20,7 +23,7 @@ func TestAgentPoolsList(t *testing.T) { agentPool, agentPoolCleanup := createAgentPool(t, client, orgTest) defer agentPoolCleanup() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { pools, err := client.AgentPools.List(ctx, orgTest.Name, nil) require.NoError(t, err) assert.Contains(t, pools.Items, agentPool) @@ -62,14 +65,13 @@ func TestAgentPoolsList(t *testing.T) { assert.Equal(t, 1, pools.TotalCount) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { pools, err := client.AgentPools.List(ctx, badIdentifier, nil) assert.Nil(t, pools) assert.EqualError(t, err, ErrInvalidOrg.Error()) }) t.Run("with query options", func(t *testing.T) { - pools, err := client.AgentPools.List(ctx, orgTest.Name, &AgentPoolListOptions{ Query: agentPool.Name, }) @@ -113,7 +115,7 @@ func TestAgentPoolsCreate(t *testing.T) { } }) - t.Run("when options is missing name", func(t *testing.T) { + t.Run(testWhenOptionsMissingName, func(t *testing.T) { k, err := client.AgentPools.Create(ctx, "foo", AgentPoolCreateOptions{}) assert.Nil(t, k) assert.EqualError(t, err, ErrRequiredName.Error()) diff --git a/apply_integration_test.go b/apply_integration_test.go index 2219d98b2..725db9d9e 100644 --- a/apply_integration_test.go +++ b/apply_integration_test.go @@ -12,6 +12,8 @@ import ( "github.com/stretchr/testify/require" ) +const testTimeMidnight = "2019-03-16T23:23:59+00:00" + func TestAppliesRead(t *testing.T) { client := testClient(t) ctx := context.Background() @@ -82,8 +84,8 @@ func TestApplies_Unmarshal(t *testing.T) { "resource-destructions": 1, "status": ApplyCanceled, "status-timestamps": map[string]string{ - "queued-at": "2020-03-16T23:15:59+00:00", - "errored-at": "2019-03-16T23:23:59+00:00", + "queued-at": testQueuedAtTime, + "errored-at": testTimeMidnight, }, }, }, @@ -97,9 +99,9 @@ func TestApplies_Unmarshal(t *testing.T) { err = unmarshalResponse(responseBody, apply) require.NoError(t, err) - queuedParsedTime, err := time.Parse(time.RFC3339, "2020-03-16T23:15:59+00:00") + queuedParsedTime, err := time.Parse(time.RFC3339, testQueuedAtTime) require.NoError(t, err) - erroredParsedTime, err := time.Parse(time.RFC3339, "2019-03-16T23:23:59+00:00") + erroredParsedTime, err := time.Parse(time.RFC3339, testTimeMidnight) require.NoError(t, err) assert.Equal(t, apply.ID, "apply-47MBvjwzBG8YKc2v") 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/configuration_version_integration_test.go b/configuration_version_integration_test.go index 9a128a33e..07c4b6349 100644 --- a/configuration_version_integration_test.go +++ b/configuration_version_integration_test.go @@ -14,6 +14,8 @@ import ( "github.com/stretchr/testify/require" ) +const testConfigVersionPath = "test-fixtures/config-version" + func TestConfigurationVersionsList(t *testing.T) { client := testClient(t) ctx := context.Background() @@ -26,7 +28,7 @@ func TestConfigurationVersionsList(t *testing.T) { cvTest2, cvTest2Cleanup := createConfigurationVersion(t, client, wTest) defer cvTest2Cleanup() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { cvl, err := client.ConfigurationVersions.List(ctx, wTest.ID, nil) require.NoError(t, err) @@ -63,7 +65,7 @@ func TestConfigurationVersionsList(t *testing.T) { assert.Equal(t, 2, cvl.TotalCount) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { cvl, err := client.ConfigurationVersions.List(ctx, badIdentifier, nil) assert.Nil(t, cvl) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) @@ -199,7 +201,7 @@ func TestConfigurationVersionsUpload(t *testing.T) { err := client.ConfigurationVersions.Upload( ctx, cv.UploadURL, - "test-fixtures/config-version", + testConfigVersionPath, ) require.NoError(t, err) @@ -210,7 +212,7 @@ func TestConfigurationVersionsUpload(t *testing.T) { err := client.ConfigurationVersions.Upload( ctx, cv.UploadURL[:len(cv.UploadURL)-10]+"nonexisting", - "test-fixtures/config-version", + testConfigVersionPath, ) assert.Error(t, err) }) @@ -239,7 +241,7 @@ func TestConfigurationVersionsArchive(t *testing.T) { err := client.ConfigurationVersions.Upload( ctx, cv.UploadURL, - "test-fixtures/config-version", + testConfigVersionPath, ) require.NoError(t, err) @@ -256,7 +258,7 @@ func TestConfigurationVersionsArchive(t *testing.T) { err = client.ConfigurationVersions.Upload( ctx, newCv.UploadURL, - "test-fixtures/config-version", + testConfigVersionPath, ) require.NoError(t, err) defer newCvCleanup() @@ -288,7 +290,7 @@ func TestConfigurationVersionsDownload(t *testing.T) { defer uploadedCvCleanup() expectedCvFile := bytes.NewBuffer(nil) - _, expectedCvFileErr := slug.Pack("test-fixtures/config-version", expectedCvFile, true) + _, expectedCvFileErr := slug.Pack(testConfigVersionPath, expectedCvFile, true) if expectedCvFileErr != nil { t.Fatal(expectedCvFileErr) } @@ -329,8 +331,8 @@ func TestConfigurationVersions_Unmarshal(t *testing.T) { "source": ConfigurationSourceTerraform, "status": ConfigurationUploaded, "status-timestamps": map[string]string{ - "finished-at": "2020-03-16T23:15:59+00:00", - "started-at": "2019-03-16T23:23:59+00:00", + "finished-at": testQueuedAtTime, + "started-at": testTimeMidnight, }, }, }, @@ -343,9 +345,9 @@ func TestConfigurationVersions_Unmarshal(t *testing.T) { err = unmarshalResponse(responseBody, cv) require.NoError(t, err) - finishedParsedTime, err := time.Parse(time.RFC3339, "2020-03-16T23:15:59+00:00") + finishedParsedTime, err := time.Parse(time.RFC3339, testQueuedAtTime) require.NoError(t, err) - startedParsedTime, err := time.Parse(time.RFC3339, "2019-03-16T23:23:59+00:00") + startedParsedTime, err := time.Parse(time.RFC3339, testTimeMidnight) require.NoError(t, err) assert.Equal(t, cv.ID, "cv-ntv3HbhJqvFzamy7") diff --git a/cost_estimate_integration_test.go b/cost_estimate_integration_test.go index 424060b12..426cddba8 100644 --- a/cost_estimate_integration_test.go +++ b/cost_estimate_integration_test.go @@ -70,8 +70,8 @@ func TestCostEsimate_Unmarshal(t *testing.T) { "resources-count": 1, "status": CostEstimateCanceled, "status-timestamps": map[string]string{ - "queued-at": "2020-03-16T23:15:59+00:00", - "errored-at": "2019-03-16T23:23:59+00:00", + "queued-at": testQueuedAtTime, + "errored-at": testTimeMidnight, }, }, }, @@ -79,9 +79,9 @@ func TestCostEsimate_Unmarshal(t *testing.T) { byteData, err := json.Marshal(data) require.NoError(t, err) - queuedParsedTime, err := time.Parse(time.RFC3339, "2020-03-16T23:15:59+00:00") + queuedParsedTime, err := time.Parse(time.RFC3339, testQueuedAtTime) require.NoError(t, err) - erroredParsedTime, err := time.Parse(time.RFC3339, "2019-03-16T23:23:59+00:00") + erroredParsedTime, err := time.Parse(time.RFC3339, testTimeMidnight) require.NoError(t, err) responseBody := bytes.NewReader(byteData) diff --git a/errors.go b/errors.go index 73b3bf177..63d1837c8 100644 --- a/errors.go +++ b/errors.go @@ -309,7 +309,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/gpg_key.go b/gpg_key.go index 656074aee..27d2d28c0 100644 --- a/gpg_key.go +++ b/gpg_key.go @@ -36,7 +36,7 @@ type gpgKeys struct { // GPGKey represents a signed GPG key for a TFC/E private provider. type GPGKey struct { ID string `jsonapi:"primary,gpg-keys"` - AsciiArmor string `jsonapi:"attr,ascii-armor"` + ASCIIArmor string `jsonapi:"attr,ascii-armor"` CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` KeyID string `jsonapi:"attr,key-id"` Namespace string `jsonapi:"attr,namespace"` @@ -57,7 +57,7 @@ type GPGKeyID struct { type GPGKeyCreateOptions struct { Type string `jsonapi:"primary,gpg-keys"` Namespace string `jsonapi:"attr,namespace"` - AsciiArmor string `jsonapi:"attr,ascii-armor"` + ASCIIArmor string `jsonapi:"attr,ascii-armor"` } // GPGKeyCreateOptions represents all the available options used to update a GPG key. @@ -184,8 +184,8 @@ func (o GPGKeyCreateOptions) valid() error { return ErrInvalidNamespace } - if !validString(&o.AsciiArmor) { - return ErrInvalidAsciiArmor + if !validString(&o.ASCIIArmor) { + return ErrInvalidASCIIArmor } return nil diff --git a/gpg_key_integration_test.go b/gpg_key_integration_test.go index 838909e66..bf549d317 100644 --- a/gpg_key_integration_test.go +++ b/gpg_key_integration_test.go @@ -8,6 +8,8 @@ import ( "github.com/stretchr/testify/require" ) +const testWithInvalidOptions = "with invalid options" + func TestGPGKeyCreate(t *testing.T) { client := testClient(t) ctx := context.Background() @@ -23,14 +25,14 @@ func TestGPGKeyCreate(t *testing.T) { t.Run("with valid options", func(t *testing.T) { opts := GPGKeyCreateOptions{ Namespace: provider.Organization.Name, - AsciiArmor: testGpgArmor, + ASCIIArmor: testGpgArmor, } gpgKey, err := client.GPGKeys.Create(ctx, PrivateRegistry, opts) require.NoError(t, err) assert.NotEmpty(t, gpgKey.ID) - assert.Equal(t, gpgKey.AsciiArmor, opts.AsciiArmor) + assert.Equal(t, gpgKey.ASCIIArmor, opts.ASCIIArmor) assert.Equal(t, gpgKey.Namespace, opts.Namespace) assert.NotEmpty(t, gpgKey.CreatedAt) assert.NotEmpty(t, gpgKey.UpdatedAt) @@ -43,27 +45,27 @@ func TestGPGKeyCreate(t *testing.T) { t.Run("with invalid registry name", func(t *testing.T) { opts := GPGKeyCreateOptions{ Namespace: provider.Organization.Name, - AsciiArmor: testGpgArmor, + ASCIIArmor: testGpgArmor, } _, err := client.GPGKeys.Create(ctx, "foobar", opts) assert.ErrorIs(t, err, ErrInvalidRegistryName) }) - t.Run("with invalid options", func(t *testing.T) { + t.Run(testWithInvalidOptions, func(t *testing.T) { missingNamespaceOpts := GPGKeyCreateOptions{ Namespace: "", - AsciiArmor: testGpgArmor, + ASCIIArmor: testGpgArmor, } _, err := client.GPGKeys.Create(ctx, PrivateRegistry, missingNamespaceOpts) assert.ErrorIs(t, err, ErrInvalidNamespace) - missingAsciiArmorOpts := GPGKeyCreateOptions{ + missingASCIIArmorOpts := GPGKeyCreateOptions{ Namespace: provider.Organization.Name, - AsciiArmor: "", + ASCIIArmor: "", } - _, err = client.GPGKeys.Create(ctx, PrivateRegistry, missingAsciiArmorOpts) - assert.ErrorIs(t, err, ErrInvalidAsciiArmor) + _, err = client.GPGKeys.Create(ctx, PrivateRegistry, missingASCIIArmorOpts) + assert.ErrorIs(t, err, ErrInvalidASCIIArmor) }) } @@ -92,7 +94,7 @@ func TestGPGKeyRead(t *testing.T) { assert.NotEmpty(t, gpgKey.ID) assert.NotEmpty(t, gpgKey.KeyID) - assert.Greater(t, len(gpgKey.AsciiArmor), 0) + assert.Greater(t, len(gpgKey.ASCIIArmor), 0) assert.Equal(t, fetched.Namespace, provider.Organization.Name) }) diff --git a/helper_test.go b/helper_test.go index a54e7e349..5c3fef521 100644 --- a/helper_test.go +++ b/helper_test.go @@ -32,6 +32,12 @@ const agentVersion = "1.3.0" var _testAccountDetails *TestAccountDetails +const githubURL = "https://github.com" + +const githubAPIURL = "https://api.github.com" + +const envGithubPolicySetIdentifier = "GITHUB_POLICY_SET_IDENTIFIER" + type featureSet struct { ID string `jsonapi:"primary,feature-sets"` } @@ -114,16 +120,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 +151,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,31 +167,32 @@ 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 +235,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 +268,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 +282,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 +303,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.Fatal("could not return an agent") + } return agent, agentPool, cleanup } @@ -379,7 +395,7 @@ func createUploadedConfigurationVersion(t *testing.T, client *Client, w *Workspa cv, cvCleanup := createConfigurationVersion(t, client, w) ctx := context.Background() - err := client.ConfigurationVersions.Upload(ctx, cv.UploadURL, "test-fixtures/config-version") + err := client.ConfigurationVersions.Upload(ctx, cv.UploadURL, testConfigVersionPath) if err != nil { cvCleanup() t.Fatal(err) @@ -427,7 +443,7 @@ func createGPGKey(t *testing.T, client *Client, org *Organization, provider *Reg gpgKey, err := client.GPGKeys.Create(ctx, PrivateRegistry, GPGKeyCreateOptions{ Namespace: provider.Organization.Name, - AsciiArmor: testGpgArmor, + ASCIIArmor: testGpgArmor, }) if err != nil { t.Fatal(err) @@ -716,8 +732,9 @@ func createUploadedPolicy(t *testing.T, client *Client, pass bool, org *Organiza } } -func createUploadedPolicyWithOptions(t *testing.T, client *Client, pass bool, org *Organization, opts PolicyCreateOptions) (*Policy, func()) { +func createUploadedPolicyWithOptions(t *testing.T, client *Client, org *Organization, opts PolicyCreateOptions) (*Policy, func()) { var orgCleanup func() + var pass = true if org == nil { org, orgCleanup = createOrganization(t, client) @@ -765,8 +782,8 @@ func createOAuthClient(t *testing.T, client *Client, org *Organization) (*OAuthC } options := OAuthClientCreateOptions{ - APIURL: String("https://api.github.com"), - HTTPURL: String("https://github.com"), + APIURL: String(githubAPIURL), + HTTPURL: String(githubURL), OAuthToken: String(githubToken), ServiceProvider: ServiceProvider(ServiceProviderGithub), } @@ -926,9 +943,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 +1419,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), } @@ -1452,7 +1468,7 @@ func createRegistryProviderVersion(t *testing.T, client *Client, provider *Regis ctx := context.Background() options := RegistryProviderVersionCreateOptions{ - Version: randomSemver(t), + Version: randomSemver(), KeyID: randomString(t), Protocols: []string{"4.0", "5.0", "6.0"}, } @@ -1635,7 +1651,7 @@ func createTeamAccess(t *testing.T, client *Client, tm *Team, w *Workspace, org } } -func createTeamToken(t *testing.T, client *Client, tm *Team) (*TeamToken, func()) { +func createTeamToken(t *testing.T, client *Client, tm *Team) func() { var tmCleanup func() if tm == nil { @@ -1643,12 +1659,12 @@ func createTeamToken(t *testing.T, client *Client, tm *Team) (*TeamToken, func() } ctx := context.Background() - tt, err := client.TeamTokens.Create(ctx, tm.ID) + _, err := client.TeamTokens.Create(ctx, tm.ID) if err != nil { t.Fatal(err) } - return tt, func() { + return func() { if err := client.TeamTokens.Delete(ctx, tm.ID); err != nil { t.Errorf("Error destroying team token! WARNING: Dangling resources\n"+ "may exist! The full error is shown below.\n\n"+ @@ -1737,9 +1753,9 @@ func createWorkspaceWithVCS(t *testing.T, client *Client, org *Organization, opt oc, ocCleanup := createOAuthToken(t, client, org) - githubIdentifier := os.Getenv("GITHUB_POLICY_SET_IDENTIFIER") + githubIdentifier := os.Getenv(envGithubPolicySetIdentifier) if githubIdentifier == "" { - t.Fatal("Export a valid GITHUB_POLICY_SET_IDENTIFIER before running this test!") + t.Fatalf("Export a valid %s before running this test!", envGithubPolicySetIdentifier) } if options.Name == nil { @@ -1856,7 +1872,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") } @@ -2049,9 +2065,9 @@ 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 { + h := hmac.New(sha256.New, []byte("secret")) + _, err := h.Write([]byte("data")) if err != nil { t.Fatalf("error writing hmac: %s", err) } @@ -2083,7 +2099,7 @@ func randomString(t *testing.T) string { return v } -func randomSemver(t *testing.T) string { +func randomSemver() string { 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/logreader_integration_test.go b/logreader_integration_test.go index 1000f92cc..17f785752 100644 --- a/logreader_integration_test.go +++ b/logreader_integration_test.go @@ -9,6 +9,9 @@ import ( "testing" ) +const testExpectedGotFmt = "expected %s, got: %s" +const testLogReaderExpected = "Terraform run started - logs - Terraform run finished" + // checkedWrite writes message to w and fails the test if there's an error. func checkedWrite(t *testing.T, w io.Writer, message []byte) { _, err := w.Write(message) @@ -72,9 +75,8 @@ func TestLogReader_withMarkersSingle(t *testing.T) { t.Fatal(err) } - expected := "Terraform run started - logs - Terraform run finished" - if string(logs) != expected { - t.Fatalf("expected %s, got: %s", expected, string(logs)) + if string(logs) != testLogReaderExpected { + t.Fatalf(testExpectedGotFmt, testLogReaderExpected, string(logs)) } if doneReads != 1 { t.Fatalf("expected 1 done reads, got %d reads", doneReads) @@ -113,9 +115,8 @@ func TestLogReader_withMarkersDouble(t *testing.T) { t.Fatal(err) } - expected := "Terraform run started - logs - Terraform run finished" - if string(logs) != expected { - t.Fatalf("expected %s, got: %s", expected, string(logs)) + if string(logs) != testLogReaderExpected { + t.Fatalf(testExpectedGotFmt, testLogReaderExpected, string(logs)) } if doneReads != 1 { t.Fatalf("expected 1 done reads, got %d reads", doneReads) @@ -160,9 +161,8 @@ func TestLogReader_withMarkersMulti(t *testing.T) { t.Fatal(err) } - expected := "Terraform run started - logs - Terraform run finished" - if string(logs) != expected { - t.Fatalf("expected %s, got: %s", expected, string(logs)) + if string(logs) != testLogReaderExpected { + t.Fatalf(testExpectedGotFmt, testLogReaderExpected, string(logs)) } if doneReads != 3 { t.Fatalf("expected 3 done reads, got %d reads", doneReads) @@ -203,9 +203,8 @@ func TestLogReader_withoutMarkers(t *testing.T) { t.Fatal(err) } - expected := "Terraform run started - logs - Terraform run finished" - if string(logs) != expected { - t.Fatalf("expected %s, got: %s", expected, string(logs)) + if string(logs) != testLogReaderExpected { + t.Fatalf(testExpectedGotFmt, testLogReaderExpected, string(logs)) } if doneReads != 25 { t.Fatalf("expected 14 done reads, got %d reads", doneReads) @@ -248,9 +247,8 @@ func TestLogReader_withoutEndOfTextMarker(t *testing.T) { t.Fatal(err) } - expected := "Terraform run started - logs - Terraform run finished" - if string(logs) != expected { - t.Fatalf("expected %s, got: %s", expected, string(logs)) + if string(logs) != testLogReaderExpected { + t.Fatalf(testExpectedGotFmt, testLogReaderExpected, string(logs)) } if doneReads != 3 { t.Fatalf("expected 3 done reads, got %d reads", doneReads) diff --git a/notification_configuration.go b/notification_configuration.go index afdd3cfa6..8730068fb 100644 --- a/notification_configuration.go +++ b/notification_configuration.go @@ -323,10 +323,7 @@ func (o NotificationConfigurationCreateOptions) valid() error { return ErrInvalidNotificationTrigger } - if *o.DestinationType == NotificationDestinationTypeGeneric || - *o.DestinationType == NotificationDestinationTypeSlack || - *o.DestinationType == NotificationDestinationTypeMicrosoftTeams { - + if *o.DestinationType == NotificationDestinationTypeGeneric || *o.DestinationType == NotificationDestinationTypeSlack || *o.DestinationType == NotificationDestinationTypeMicrosoftTeams { if o.URL == nil { return ErrRequiredURL } diff --git a/notification_configuration_integration_test.go b/notification_configuration_integration_test.go index ee0d9d3d5..86bd2398b 100644 --- a/notification_configuration_integration_test.go +++ b/notification_configuration_integration_test.go @@ -8,6 +8,9 @@ import ( "github.com/stretchr/testify/require" ) +const testSkipPagingNotSupportedYet = "paging not supported yet in API" +const testWithoutValidWorkspace = "without a valid workspace" + func TestNotificationConfigurationList(t *testing.T) { client := testClient(t) ctx := context.Background() @@ -30,13 +33,13 @@ func TestNotificationConfigurationList(t *testing.T) { assert.Contains(t, ncl.Items, ncTest1) assert.Contains(t, ncl.Items, ncTest2) - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) assert.Equal(t, 1, ncl.CurrentPage) assert.Equal(t, 2, ncl.TotalCount) }) t.Run("with list options", func(t *testing.T) { - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) // Request a page number which is out of range. The result should // be successful, but return no results if the paging options are // properly passed along. @@ -56,7 +59,7 @@ func TestNotificationConfigurationList(t *testing.T) { assert.Equal(t, 2, ncl.TotalCount) }) - t.Run("without a valid workspace", func(t *testing.T) { + t.Run(testWithoutValidWorkspace, func(t *testing.T) { ncl, err := client.NotificationConfigurations.List( ctx, badIdentifier, @@ -151,7 +154,7 @@ func TestNotificationConfigurationCreate(t *testing.T) { assert.Equal(t, err, ErrRequiredURL) }) - t.Run("without a valid workspace", func(t *testing.T) { + t.Run(testWithoutValidWorkspace, func(t *testing.T) { nc, err := client.NotificationConfigurations.Create(ctx, badIdentifier, NotificationConfigurationCreateOptions{}) assert.Nil(t, nc) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) diff --git a/oauth_client_integration_test.go b/oauth_client_integration_test.go index 9bc5863f5..e4695f188 100644 --- a/oauth_client_integration_test.go +++ b/oauth_client_integration_test.go @@ -22,7 +22,7 @@ func TestOAuthClientsList(t *testing.T) { ocTest2, ocTestCleanup2 := createOAuthClient(t, client, orgTest) defer ocTestCleanup2() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { ocl, err := client.OAuthClients.List(ctx, orgTest.Name, nil) require.NoError(t, err) @@ -41,13 +41,13 @@ func TestOAuthClientsList(t *testing.T) { assert.Contains(t, ocl.Items, ocTest1) assert.Contains(t, ocl.Items, ocTest2) - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) assert.Equal(t, 1, ocl.CurrentPage) assert.Equal(t, 2, ocl.TotalCount) }) t.Run("with list options", func(t *testing.T) { - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) // Request a page number which is out of range. The result should // be successful, but return no results if the paging options are // properly passed along. @@ -76,7 +76,7 @@ func TestOAuthClientsList(t *testing.T) { assert.NotEmpty(t, ocl.Items[0].OAuthTokens[0].ID) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { ocl, err := client.OAuthClients.List(ctx, badIdentifier, nil) assert.Nil(t, ocl) assert.EqualError(t, err, ErrInvalidOrg.Error()) @@ -97,8 +97,8 @@ func TestOAuthClientsCreate(t *testing.T) { t.Run("with valid options", func(t *testing.T) { options := OAuthClientCreateOptions{ - APIURL: String("https://api.github.com"), - HTTPURL: String("https://github.com"), + APIURL: String(githubAPIURL), + HTTPURL: String(githubURL), OAuthToken: String(githubToken), ServiceProvider: ServiceProvider(ServiceProviderGithub), } @@ -107,8 +107,8 @@ func TestOAuthClientsCreate(t *testing.T) { require.NoError(t, err) assert.NotEmpty(t, oc.ID) assert.Nil(t, oc.Name) - assert.Equal(t, "https://api.github.com", oc.APIURL) - assert.Equal(t, "https://github.com", oc.HTTPURL) + assert.Equal(t, githubAPIURL, oc.APIURL) + assert.Equal(t, githubURL, oc.HTTPURL) assert.Equal(t, 1, len(oc.OAuthTokens)) assert.Equal(t, ServiceProviderGithub, oc.ServiceProvider) @@ -119,8 +119,8 @@ func TestOAuthClientsCreate(t *testing.T) { t.Run("without an valid organization", func(t *testing.T) { options := OAuthClientCreateOptions{ - APIURL: String("https://api.github.com"), - HTTPURL: String("https://github.com"), + APIURL: String(githubAPIURL), + HTTPURL: String(githubURL), OAuthToken: String(githubToken), ServiceProvider: ServiceProvider(ServiceProviderGithub), } @@ -131,7 +131,7 @@ func TestOAuthClientsCreate(t *testing.T) { t.Run("without an API URL", func(t *testing.T) { options := OAuthClientCreateOptions{ - HTTPURL: String("https://github.com"), + HTTPURL: String(githubURL), OAuthToken: String(githubToken), ServiceProvider: ServiceProvider(ServiceProviderGithub), } @@ -142,7 +142,7 @@ func TestOAuthClientsCreate(t *testing.T) { t.Run("without a HTTP URL", func(t *testing.T) { options := OAuthClientCreateOptions{ - APIURL: String("https://api.github.com"), + APIURL: String(githubAPIURL), OAuthToken: String(githubToken), ServiceProvider: ServiceProvider(ServiceProviderGithub), } @@ -153,8 +153,8 @@ func TestOAuthClientsCreate(t *testing.T) { t.Run("without an OAuth token", func(t *testing.T) { options := OAuthClientCreateOptions{ - APIURL: String("https://api.github.com"), - HTTPURL: String("https://github.com"), + APIURL: String(githubAPIURL), + HTTPURL: String(githubURL), ServiceProvider: ServiceProvider(ServiceProviderGithub), } @@ -164,8 +164,8 @@ func TestOAuthClientsCreate(t *testing.T) { t.Run("without a service provider", func(t *testing.T) { options := OAuthClientCreateOptions{ - APIURL: String("https://api.github.com"), - HTTPURL: String("https://github.com"), + APIURL: String(githubAPIURL), + HTTPURL: String(githubURL), OAuthToken: String(githubToken), } @@ -274,8 +274,8 @@ func TestOAuthClientsDelete(t *testing.T) { func TestOAuthClientsCreateOptionsValid(t *testing.T) { t.Run("with valid options", func(t *testing.T) { options := OAuthClientCreateOptions{ - APIURL: String("https://api.github.com"), - HTTPURL: String("https://github.com"), + APIURL: String(githubAPIURL), + HTTPURL: String(githubURL), OAuthToken: String("NOTHING"), ServiceProvider: ServiceProvider(ServiceProviderGithub), } @@ -286,7 +286,7 @@ func TestOAuthClientsCreateOptionsValid(t *testing.T) { t.Run("without an API URL", func(t *testing.T) { options := OAuthClientCreateOptions{ - HTTPURL: String("https://github.com"), + HTTPURL: String(githubURL), OAuthToken: String("NOTHING"), ServiceProvider: ServiceProvider(ServiceProviderGithub), } @@ -297,7 +297,7 @@ func TestOAuthClientsCreateOptionsValid(t *testing.T) { t.Run("without a HTTP URL", func(t *testing.T) { options := OAuthClientCreateOptions{ - APIURL: String("https://api.github.com"), + APIURL: String(githubAPIURL), OAuthToken: String("NOTHING"), ServiceProvider: ServiceProvider(ServiceProviderGithub), } @@ -308,8 +308,8 @@ func TestOAuthClientsCreateOptionsValid(t *testing.T) { t.Run("without an OAuth token", func(t *testing.T) { options := OAuthClientCreateOptions{ - APIURL: String("https://api.github.com"), - HTTPURL: String("https://github.com"), + APIURL: String(githubAPIURL), + HTTPURL: String(githubURL), ServiceProvider: ServiceProvider(ServiceProviderGithub), } @@ -319,8 +319,8 @@ func TestOAuthClientsCreateOptionsValid(t *testing.T) { t.Run("without a service provider", func(t *testing.T) { options := OAuthClientCreateOptions{ - APIURL: String("https://api.github.com"), - HTTPURL: String("https://github.com"), + APIURL: String(githubAPIURL), + HTTPURL: String(githubURL), OAuthToken: String("NOTHING"), } @@ -330,8 +330,8 @@ func TestOAuthClientsCreateOptionsValid(t *testing.T) { t.Run("without private key and not ado_server options", func(t *testing.T) { options := OAuthClientCreateOptions{ - APIURL: String("https://api.github.com"), - HTTPURL: String("https://github.com"), + APIURL: String(githubAPIURL), + HTTPURL: String(githubURL), OAuthToken: String("NOTHING"), ServiceProvider: ServiceProvider(ServiceProviderGitlabEE), } @@ -342,8 +342,8 @@ func TestOAuthClientsCreateOptionsValid(t *testing.T) { t.Run("with empty private key and not ado_server options", func(t *testing.T) { options := OAuthClientCreateOptions{ - APIURL: String("https://api.github.com"), - HTTPURL: String("https://github.com"), + APIURL: String(githubAPIURL), + HTTPURL: String(githubURL), OAuthToken: String("NOTHING"), ServiceProvider: ServiceProvider(ServiceProviderGitlabEE), PrivateKey: String(""), @@ -355,8 +355,8 @@ func TestOAuthClientsCreateOptionsValid(t *testing.T) { t.Run("with private key and not ado_server options", func(t *testing.T) { options := OAuthClientCreateOptions{ - APIURL: String("https://api.github.com"), - HTTPURL: String("https://github.com"), + APIURL: String(githubAPIURL), + HTTPURL: String(githubURL), OAuthToken: String("NOTHING"), ServiceProvider: ServiceProvider(ServiceProviderGithub), PrivateKey: String("NOTHING"), diff --git a/oauth_token_integration_test.go b/oauth_token_integration_test.go index 4fa332446..7920112fb 100644 --- a/oauth_token_integration_test.go +++ b/oauth_token_integration_test.go @@ -9,6 +9,8 @@ import ( "github.com/stretchr/testify/require" ) +var testWithoutValidPolicyID = "without a valid policy ID" + func TestOAuthTokensList(t *testing.T) { client := testClient(t) ctx := context.Background() @@ -21,7 +23,7 @@ func TestOAuthTokensList(t *testing.T) { otTest2, otTest2Cleanup := createOAuthToken(t, client, orgTest) defer otTest2Cleanup() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { otl, err := client.OAuthTokens.List(ctx, orgTest.Name, nil) require.NoError(t, err) @@ -41,13 +43,13 @@ func TestOAuthTokensList(t *testing.T) { assert.Contains(t, otl.Items, otTest1) assert.Contains(t, otl.Items, otTest2) - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) assert.Equal(t, 1, otl.CurrentPage) assert.Equal(t, 2, otl.TotalCount) }) t.Run("with list options", func(t *testing.T) { - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) // Request a page number which is out of range. The result should // be successful, but return no results if the paging options are // properly passed along. @@ -65,7 +67,7 @@ func TestOAuthTokensList(t *testing.T) { assert.Equal(t, 2, otl.TotalCount) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { otl, err := client.OAuthTokens.List(ctx, badIdentifier, nil) assert.Nil(t, otl) assert.EqualError(t, err, ErrInvalidOrg.Error()) @@ -150,7 +152,7 @@ dpIe8YOINN27XaojJvVpT5uBVCcZLF+G7kaMjSwCTlDx3Q== assert.Contains(t, err.Error(), "Ssh key is invalid") }) - t.Run("without a valid policy ID", func(t *testing.T) { + t.Run(testWithoutValidPolicyID, func(t *testing.T) { ot, err := client.OAuthTokens.Update(ctx, badIdentifier, OAuthTokenUpdateOptions{}) assert.Nil(t, ot) assert.Equal(t, err, ErrInvalidOauthTokenID) diff --git a/organization_integration_test.go b/organization_integration_test.go index ea609cdcf..8eec3b335 100644 --- a/organization_integration_test.go +++ b/organization_integration_test.go @@ -11,6 +11,8 @@ import ( "github.com/stretchr/testify/require" ) +const testPermissionsProperlyDecoded = "permissions are properly decoded" + func TestOrganizationsList(t *testing.T) { client := testClient(t) ctx := context.Background() @@ -26,13 +28,13 @@ func TestOrganizationsList(t *testing.T) { assert.Contains(t, orgl.Items, orgTest1) assert.Contains(t, orgl.Items, orgTest2) - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) assert.Equal(t, 1, orgl.CurrentPage) assert.Equal(t, 2, orgl.TotalCount) }) t.Run("with list options", func(t *testing.T) { - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) // Request a page number which is out of range. The result should // be successful, but return no results if the paging options are // properly passed along. @@ -159,7 +161,7 @@ func TestOrganizationsRead(t *testing.T) { assert.Equal(t, orgTest, org) assert.NotEmpty(t, org.Permissions) - t.Run("permissions are properly decoded", func(t *testing.T) { + t.Run(testPermissionsProperlyDecoded, func(t *testing.T) { assert.True(t, org.Permissions.CanDestroy) }) @@ -523,7 +525,7 @@ func TestOrganizationsReadRunTasksPermission(t *testing.T) { assert.Equal(t, orgTest, org) assert.NotEmpty(t, org.Permissions) - t.Run("permissions are properly decoded", func(t *testing.T) { + t.Run(testPermissionsProperlyDecoded, func(t *testing.T) { assert.True(t, org.Permissions.CanManageRunTasks) }) }) diff --git a/organization_membership_integration_test.go b/organization_membership_integration_test.go index bd36ae238..fdeed0805 100644 --- a/organization_membership_integration_test.go +++ b/organization_membership_integration_test.go @@ -9,6 +9,8 @@ import ( "github.com/stretchr/testify/require" ) +const testWhenErrorFromAPI = "when an error is returned from the api" + func TestOrganizationMembershipsList(t *testing.T) { client := testClient(t) ctx := context.Background() @@ -16,7 +18,7 @@ func TestOrganizationMembershipsList(t *testing.T) { orgTest, orgTestCleanup := createOrganization(t, client) defer orgTestCleanup() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { memTest1, memTest1Cleanup := createOrganizationMembership(t, client, orgTest) defer memTest1Cleanup() memTest2, memTest2Cleanup := createOrganizationMembership(t, client, orgTest) @@ -50,7 +52,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) }) @@ -138,7 +140,7 @@ func TestOrganizationMembershipsList(t *testing.T) { }) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { ml, err := client.OrganizationMemberships.List(ctx, badIdentifier, nil) assert.Nil(t, ml) assert.EqualError(t, err, ErrInvalidOrg.Error()) @@ -184,7 +186,7 @@ func TestOrganizationMembershipsCreate(t *testing.T) { assert.EqualError(t, err, ErrInvalidOrg.Error()) }) - t.Run("when an error is returned from the api", func(t *testing.T) { + t.Run(testWhenErrorFromAPI, func(t *testing.T) { mem, err := client.OrganizationMemberships.Create(ctx, orgTest.Name, OrganizationMembershipCreateOptions{ Email: String("not-an-email-address"), }) @@ -295,7 +297,7 @@ func TestOrganizationMembershipsDelete(t *testing.T) { assert.Equal(t, err, ErrInvalidMembership) }) - t.Run("when an error is returned from the api", func(t *testing.T) { + t.Run(testWhenErrorFromAPI, func(t *testing.T) { err := client.OrganizationMemberships.Delete(ctx, "not-an-identifier") assert.Error(t, err) diff --git a/plan_export_integration_test.go b/plan_export_integration_test.go index a67833c86..4705c59d3 100644 --- a/plan_export_integration_test.go +++ b/plan_export_integration_test.go @@ -131,8 +131,8 @@ func TestPlanExport_Unmarshal(t *testing.T) { "data-type": PlanExportSentinelMockBundleV0, "status": PlanExportCanceled, "status-timestamps": map[string]string{ - "queued-at": "2020-03-16T23:15:59+00:00", - "errored-at": "2019-03-16T23:23:59+00:00", + "queued-at": testQueuedAtTime, + "errored-at": testTimeMidnight, }, }, }, @@ -146,9 +146,9 @@ func TestPlanExport_Unmarshal(t *testing.T) { err = unmarshalResponse(responseBody, pe) require.NoError(t, err) - queuedParsedTime, err := time.Parse(time.RFC3339, "2020-03-16T23:15:59+00:00") + queuedParsedTime, err := time.Parse(time.RFC3339, testQueuedAtTime) require.NoError(t, err) - erroredParsedTime, err := time.Parse(time.RFC3339, "2019-03-16T23:23:59+00:00") + erroredParsedTime, err := time.Parse(time.RFC3339, testTimeMidnight) require.NoError(t, err) assert.Equal(t, pe.DataType, PlanExportSentinelMockBundleV0) diff --git a/plan_integration_test.go b/plan_integration_test.go index da4e2ea1d..54e4a28fd 100644 --- a/plan_integration_test.go +++ b/plan_integration_test.go @@ -82,8 +82,8 @@ func TestPlan_Unmarshal(t *testing.T) { "resource-destructions": 1, "status": PlanCanceled, "status-timestamps": map[string]string{ - "queued-at": "2020-03-16T23:15:59+00:00", - "errored-at": "2019-03-16T23:23:59+00:00", + "queued-at": testQueuedAtTime, + "errored-at": testTimeMidnight, }, }, }, @@ -97,9 +97,9 @@ func TestPlan_Unmarshal(t *testing.T) { err = unmarshalResponse(responseBody, plan) require.NoError(t, err) - queuedParsedTime, err := time.Parse(time.RFC3339, "2020-03-16T23:15:59+00:00") + queuedParsedTime, err := time.Parse(time.RFC3339, testQueuedAtTime) require.NoError(t, err) - erroredParsedTime, err := time.Parse(time.RFC3339, "2019-03-16T23:23:59+00:00") + erroredParsedTime, err := time.Parse(time.RFC3339, testTimeMidnight) require.NoError(t, err) assert.Equal(t, plan.HasChanges, true) diff --git a/policy_check_integration_test.go b/policy_check_integration_test.go index 5d242ac18..5088fa805 100644 --- a/policy_check_integration_test.go +++ b/policy_check_integration_test.go @@ -32,7 +32,7 @@ func TestPolicyChecksList(t *testing.T) { rTest, runCleanup := createPolicyCheckedRun(t, client, wTest) defer runCleanup() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { pcl, err := client.PolicyChecks.List(ctx, rTest.ID, nil) require.NoError(t, err) require.Equal(t, 1, len(pcl.Items)) @@ -44,7 +44,7 @@ func TestPolicyChecksList(t *testing.T) { }) t.Run("with list options", func(t *testing.T) { - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) // Request a page number which is out of range. The result should // be successful, but return no results if the paging options are // properly passed along. @@ -244,8 +244,8 @@ func TestPolicyCheck_Unmarshal(t *testing.T) { "scope": PolicyScopeOrganization, "status": PolicyOverridden, "status-timestamps": map[string]string{ - "queued-at": "2020-03-16T23:15:59+00:00", - "errored-at": "2019-03-16T23:23:59+00:00", + "queued-at": testQueuedAtTime, + "errored-at": testTimeMidnight, }, }, }, @@ -259,9 +259,9 @@ func TestPolicyCheck_Unmarshal(t *testing.T) { err = unmarshalResponse(responseBody, pc) require.NoError(t, err) - queuedParsedTime, err := time.Parse(time.RFC3339, "2020-03-16T23:15:59+00:00") + queuedParsedTime, err := time.Parse(time.RFC3339, testQueuedAtTime) require.NoError(t, err) - erroredParsedTime, err := time.Parse(time.RFC3339, "2019-03-16T23:23:59+00:00") + erroredParsedTime, err := time.Parse(time.RFC3339, testTimeMidnight) require.NoError(t, err) assert.Equal(t, pc.ID, "1") diff --git a/policy_evaluation_beta_test.go b/policy_evaluation_beta_test.go index 8358029b7..8e6f21451 100644 --- a/policy_evaluation_beta_test.go +++ b/policy_evaluation_beta_test.go @@ -31,7 +31,7 @@ func TestPolicyEvaluationList_Beta(t *testing.T) { }, }, } - policyTest, policyTestCleanup := createUploadedPolicyWithOptions(t, client, true, orgTest, options) + policyTest, policyTestCleanup := createUploadedPolicyWithOptions(t, client, orgTest, options) defer policyTestCleanup() policySet := []*Policy{policyTest} @@ -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) @@ -88,7 +87,7 @@ func TestPolicySetOutcomeList_Beta(t *testing.T) { }, }, } - policyTest, policyTestCleanup := createUploadedPolicyWithOptions(t, client, true, orgTest, options) + policyTest, policyTestCleanup := createUploadedPolicyWithOptions(t, client, orgTest, options) defer policyTestCleanup() policySet := []*Policy{policyTest} @@ -200,7 +199,7 @@ func TestPolicySetOutcomeRead_Beta(t *testing.T) { }, }, } - policyTest, policyTestCleanup := createUploadedPolicyWithOptions(t, client, true, orgTest, options) + policyTest, policyTestCleanup := createUploadedPolicyWithOptions(t, client, orgTest, options) defer policyTestCleanup() policySet := []*Policy{policyTest} @@ -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/policy_integration_beta_test.go b/policy_integration_beta_test.go index ee8ad3b7e..4398ebe91 100644 --- a/policy_integration_beta_test.go +++ b/policy_integration_beta_test.go @@ -210,7 +210,7 @@ func TestPoliciesCreate_Beta(t *testing.T) { assert.Equal(t, err, ErrRequiredEnforcementMode) }) - t.Run("when options has an invalid organization", func(t *testing.T) { + t.Run(testWhenOptionsHasInvalidOrganization, func(t *testing.T) { p, err := client.Policies.Create(ctx, badIdentifier, PolicyCreateOptions{ Name: String("foo"), }) @@ -245,7 +245,7 @@ func TestPoliciesList_Beta(t *testing.T) { pTest3, pTestCleanup3 := createPolicyWithOptions(t, client, orgTest, opaOptions) defer pTestCleanup3() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { pl, err := client.Policies.List(ctx, orgTest.Name, nil) require.NoError(t, err) assert.Contains(t, pl.Items, pTest1) @@ -300,7 +300,7 @@ func TestPoliciesList_Beta(t *testing.T) { assert.Equal(t, 1, pl.TotalCount) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { ps, err := client.Policies.List(ctx, badIdentifier, nil) assert.Nil(t, ps) assert.EqualError(t, err, ErrInvalidOrg.Error()) @@ -328,7 +328,7 @@ func TestPoliciesUpdate_Beta(t *testing.T) { }, }, } - pBefore, pBeforeCleanup := createUploadedPolicyWithOptions(t, client, true, orgTest, options) + pBefore, pBeforeCleanup := createUploadedPolicyWithOptions(t, client, orgTest, options) defer pBeforeCleanup() pAfter, err := client.Policies.Update(ctx, pBefore.ID, PolicyUpdateOptions{ diff --git a/policy_integration_test.go b/policy_integration_test.go index a0f68ec3e..ed1c48ae5 100644 --- a/policy_integration_test.go +++ b/policy_integration_test.go @@ -26,7 +26,7 @@ func TestPoliciesList(t *testing.T) { pTest2, pTestCleanup2 := createPolicy(t, client, orgTest) defer pTestCleanup2() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { pl, err := client.Policies.List(ctx, orgTest.Name, nil) require.NoError(t, err) assert.Contains(t, pl.Items, pTest1) @@ -67,7 +67,7 @@ func TestPoliciesList(t *testing.T) { assert.Equal(t, 1, pl.TotalCount) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { ps, err := client.Policies.List(ctx, badIdentifier, nil) assert.Nil(t, ps) assert.EqualError(t, err, ErrInvalidOrg.Error()) @@ -127,7 +127,7 @@ func TestPoliciesCreate(t *testing.T) { assert.EqualError(t, err, ErrInvalidName.Error()) }) - t.Run("when options is missing name", func(t *testing.T) { + t.Run(testWhenOptionsMissingName, func(t *testing.T) { p, err := client.Policies.Create(ctx, orgTest.Name, PolicyCreateOptions{ Enforce: []*EnforcementOptions{ { @@ -181,7 +181,7 @@ func TestPoliciesCreate(t *testing.T) { assert.Equal(t, err, ErrRequiredEnforcementMode) }) - t.Run("when options has an invalid organization", func(t *testing.T) { + t.Run(testWhenOptionsHasInvalidOrganization, func(t *testing.T) { p, err := client.Policies.Create(ctx, badIdentifier, PolicyCreateOptions{ Name: String("foo"), }) @@ -236,7 +236,7 @@ func TestPoliciesRead(t *testing.T) { assert.Equal(t, ErrResourceNotFound, err) }) - t.Run("without a valid policy ID", func(t *testing.T) { + t.Run(testWithoutValidPolicyID, func(t *testing.T) { p, err := client.Policies.Read(ctx, badIdentifier) assert.Nil(t, p) assert.Equal(t, err, ErrInvalidPolicyID) @@ -320,7 +320,7 @@ func TestPoliciesUpdate(t *testing.T) { assert.Equal(t, "A brand new description", pAfter.Description) }) - t.Run("without a valid policy ID", func(t *testing.T) { + t.Run(testWithoutValidPolicyID, func(t *testing.T) { p, err := client.Policies.Update(ctx, badIdentifier, PolicyUpdateOptions{}) assert.Nil(t, p) assert.Equal(t, err, ErrInvalidPolicyID) @@ -382,7 +382,7 @@ func TestPoliciesUpload(t *testing.T) { require.NoError(t, err) }) - t.Run("without a valid policy ID", func(t *testing.T) { + t.Run(testWithoutValidPolicyID, func(t *testing.T) { err := client.Policies.Upload(ctx, badIdentifier, []byte(`main = rule { true }`)) assert.Equal(t, err, ErrInvalidPolicyID) }) @@ -414,7 +414,7 @@ func TestPoliciesDownload(t *testing.T) { assert.Equal(t, testContent, content) }) - t.Run("without a valid policy ID", func(t *testing.T) { + t.Run(testWithoutValidPolicyID, func(t *testing.T) { content, err := client.Policies.Download(ctx, badIdentifier) assert.Equal(t, err, ErrInvalidPolicyID) assert.Nil(t, content) diff --git a/policy_set_integration_beta_test.go b/policy_set_integration_beta_test.go index cffad1fba..683d33f4b 100644 --- a/policy_set_integration_beta_test.go +++ b/policy_set_integration_beta_test.go @@ -11,6 +11,12 @@ import ( "github.com/stretchr/testify/require" ) +const testWebhookVscRegex = "^%s/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$" +const testWhenOptionsHasInvalidOrganization = "when options has an invalid organization" +const testPolicySetDescription = "Policies in this set will be checked in ALL workspaces!" +const testWithValidAttributes = "with valid attributes" +const githubFmt = "https://github.com/%s" + func TestPolicySetsList_Beta(t *testing.T) { skipIfFreeOnly(t) skipIfBeta(t) @@ -33,7 +39,7 @@ func TestPolicySetsList_Beta(t *testing.T) { psTest3, psTestCleanup3 := createPolicySet(t, client, orgTest, nil, []*Workspace{workspace}, OPA) defer psTestCleanup3() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { psl, err := client.PolicySets.List(ctx, orgTest.Name, nil) require.NoError(t, err) @@ -102,7 +108,7 @@ func TestPolicySetsList_Beta(t *testing.T) { assert.Equal(t, workspace.ID, psl.Items[0].Workspaces[0].ID) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { ps, err := client.PolicySets.List(ctx, badIdentifier, nil) assert.Nil(t, ps) assert.EqualError(t, err, ErrInvalidOrg.Error()) @@ -123,7 +129,7 @@ func TestPolicySetsCreate_Beta(t *testing.T) { var vcsPolicyID string - t.Run("with valid attributes", func(t *testing.T) { + t.Run(testWithValidAttributes, func(t *testing.T) { options := PolicySetCreateOptions{ Name: String("policy-set"), Kind: OPA, @@ -155,7 +161,7 @@ func TestPolicySetsCreate_Beta(t *testing.T) { t.Run("with all attributes provided - sentinel", func(t *testing.T) { options := PolicySetCreateOptions{ Name: String("global"), - Description: String("Policies in this set will be checked in ALL workspaces!"), + Description: String(testPolicySetDescription), Kind: Sentinel, Global: Bool(true), } @@ -172,7 +178,7 @@ func TestPolicySetsCreate_Beta(t *testing.T) { t.Run("with all attributes provided - OPA", func(t *testing.T) { options := PolicySetCreateOptions{ Name: String("global1"), - Description: String("Policies in this set will be checked in ALL workspaces!"), + Description: String(testPolicySetDescription), Kind: OPA, Overridable: Bool(true), Global: Bool(true), @@ -191,7 +197,7 @@ func TestPolicySetsCreate_Beta(t *testing.T) { t.Run("with missing overridable attribute", func(t *testing.T) { options := PolicySetCreateOptions{ Name: String("global2"), - Description: String("Policies in this set will be checked in ALL workspaces!"), + Description: String(testPolicySetDescription), Kind: OPA, Global: Bool(true), } @@ -231,9 +237,9 @@ func TestPolicySetsCreate_Beta(t *testing.T) { }) t.Run("with vcs policy set", func(t *testing.T) { - githubIdentifier := os.Getenv("GITHUB_POLICY_SET_IDENTIFIER") + githubIdentifier := os.Getenv(envGithubPolicySetIdentifier) if githubIdentifier == "" { - t.Skip("Export a valid GITHUB_POLICY_SET_IDENTIFIER before running this test") + t.Skipf("Export a valid %s before running this test", envGithubPolicySetIdentifier) } oc, ocTestCleanup := createOAuthToken(t, client, orgTest) @@ -267,15 +273,15 @@ func TestPolicySetsCreate_Beta(t *testing.T) { assert.Equal(t, ps.VCSRepo.Identifier, githubIdentifier) assert.Equal(t, ps.VCSRepo.IngressSubmodules, true) assert.Equal(t, ps.VCSRepo.OAuthTokenID, oc.ID) - assert.Equal(t, ps.VCSRepo.RepositoryHTTPURL, fmt.Sprintf("https://github.com/%s", githubIdentifier)) + assert.Equal(t, ps.VCSRepo.RepositoryHTTPURL, fmt.Sprintf(githubFmt, githubIdentifier)) assert.Equal(t, ps.VCSRepo.ServiceProvider, string(ServiceProviderGithub)) - assert.Regexp(t, fmt.Sprintf("^%s/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", regexp.QuoteMeta(DefaultConfig().Address)), ps.VCSRepo.WebhookURL) + assert.Regexp(t, fmt.Sprintf(testWebhookVscRegex, regexp.QuoteMeta(DefaultConfig().Address)), ps.VCSRepo.WebhookURL) }) t.Run("with vcs policy updated", func(t *testing.T) { - githubIdentifier := os.Getenv("GITHUB_POLICY_SET_IDENTIFIER") + githubIdentifier := os.Getenv(envGithubPolicySetIdentifier) if githubIdentifier == "" { - t.Skip("Export a valid GITHUB_POLICY_SET_IDENTIFIER before running this test") + t.Skipf("Export a valid %s before running this test", envGithubPolicySetIdentifier) } oc, ocTestCleanup := createOAuthToken(t, client, orgTest) @@ -304,9 +310,9 @@ func TestPolicySetsCreate_Beta(t *testing.T) { assert.Equal(t, ps.VCSRepo.Identifier, githubIdentifier) assert.Equal(t, ps.VCSRepo.IngressSubmodules, false) assert.Equal(t, ps.VCSRepo.OAuthTokenID, oc.ID) - assert.Equal(t, ps.VCSRepo.RepositoryHTTPURL, fmt.Sprintf("https://github.com/%s", githubIdentifier)) + assert.Equal(t, ps.VCSRepo.RepositoryHTTPURL, fmt.Sprintf(githubFmt, githubIdentifier)) assert.Equal(t, ps.VCSRepo.ServiceProvider, string(ServiceProviderGithub)) - assert.Regexp(t, fmt.Sprintf("^%s/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", regexp.QuoteMeta(DefaultConfig().Address)), ps.VCSRepo.WebhookURL) + assert.Regexp(t, fmt.Sprintf(testWebhookVscRegex, regexp.QuoteMeta(DefaultConfig().Address)), ps.VCSRepo.WebhookURL) }) t.Run("without a name provided", func(t *testing.T) { @@ -323,7 +329,7 @@ func TestPolicySetsCreate_Beta(t *testing.T) { assert.EqualError(t, err, ErrInvalidName.Error()) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { ps, err := client.PolicySets.Create(ctx, badIdentifier, PolicySetCreateOptions{ Name: String("policy-set"), }) @@ -347,10 +353,10 @@ func TestPolicySetsUpdate_Beta(t *testing.T) { psTest, psTestCleanup := createPolicySet(t, client, orgTest, nil, nil, "opa") defer psTestCleanup() - t.Run("with valid attributes", func(t *testing.T) { + t.Run(testWithValidAttributes, func(t *testing.T) { options := PolicySetUpdateOptions{ Name: String("global"), - Description: String("Policies in this set will be checked in ALL workspaces!"), + Description: String(testPolicySetDescription), Global: Bool(true), Overridable: Bool(true), } diff --git a/policy_set_integration_test.go b/policy_set_integration_test.go index 05637dbd8..3861a0143 100644 --- a/policy_set_integration_test.go +++ b/policy_set_integration_test.go @@ -30,7 +30,7 @@ func TestPolicySetsList(t *testing.T) { psTest2, psTestCleanup2 := createPolicySet(t, client, orgTest, nil, []*Workspace{workspace}, "") defer psTestCleanup2() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { psl, err := client.PolicySets.List(ctx, orgTest.Name, nil) require.NoError(t, err) @@ -84,7 +84,7 @@ func TestPolicySetsList(t *testing.T) { assert.Equal(t, workspace.ID, psl.Items[0].Workspaces[0].ID) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { ps, err := client.PolicySets.List(ctx, badIdentifier, nil) assert.Nil(t, ps) assert.EqualError(t, err, ErrInvalidOrg.Error()) @@ -104,7 +104,7 @@ func TestPolicySetsCreate(t *testing.T) { var vcsPolicyID string - t.Run("with valid attributes", func(t *testing.T) { + t.Run(testWithValidAttributes, func(t *testing.T) { options := PolicySetCreateOptions{ Name: String("policy-set"), } @@ -120,7 +120,7 @@ func TestPolicySetsCreate(t *testing.T) { t.Run("with all attributes provided", func(t *testing.T) { options := PolicySetCreateOptions{ Name: String("global"), - Description: String("Policies in this set will be checked in ALL workspaces!"), + Description: String(testPolicySetDescription), Global: Bool(true), } @@ -155,9 +155,9 @@ func TestPolicySetsCreate(t *testing.T) { }) t.Run("with vcs policy set", func(t *testing.T) { - githubIdentifier := os.Getenv("GITHUB_POLICY_SET_IDENTIFIER") + githubIdentifier := os.Getenv(envGithubPolicySetIdentifier) if githubIdentifier == "" { - t.Skip("Export a valid GITHUB_POLICY_SET_IDENTIFIER before running this test") + t.Skipf("Export a valid %s before running this test", envGithubPolicySetIdentifier) } oc, ocTestCleanup := createOAuthToken(t, client, orgTest) @@ -189,15 +189,15 @@ func TestPolicySetsCreate(t *testing.T) { assert.Equal(t, ps.VCSRepo.Identifier, githubIdentifier) assert.Equal(t, ps.VCSRepo.IngressSubmodules, true) assert.Equal(t, ps.VCSRepo.OAuthTokenID, oc.ID) - assert.Equal(t, ps.VCSRepo.RepositoryHTTPURL, fmt.Sprintf("https://github.com/%s", githubIdentifier)) + assert.Equal(t, ps.VCSRepo.RepositoryHTTPURL, fmt.Sprintf(githubFmt, githubIdentifier)) assert.Equal(t, ps.VCSRepo.ServiceProvider, string(ServiceProviderGithub)) - assert.Regexp(t, fmt.Sprintf("^%s/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", regexp.QuoteMeta(DefaultConfig().Address)), ps.VCSRepo.WebhookURL) + assert.Regexp(t, fmt.Sprintf(testWebhookVscRegex, regexp.QuoteMeta(DefaultConfig().Address)), ps.VCSRepo.WebhookURL) }) t.Run("with vcs policy updated", func(t *testing.T) { - githubIdentifier := os.Getenv("GITHUB_POLICY_SET_IDENTIFIER") + githubIdentifier := os.Getenv(envGithubPolicySetIdentifier) if githubIdentifier == "" { - t.Skip("Export a valid GITHUB_POLICY_SET_IDENTIFIER before running this test") + t.Skipf("Export a valid %s before running this test", envGithubPolicySetIdentifier) } oc, ocTestCleanup := createOAuthToken(t, client, orgTest) @@ -226,9 +226,9 @@ func TestPolicySetsCreate(t *testing.T) { assert.Equal(t, ps.VCSRepo.Identifier, githubIdentifier) assert.Equal(t, ps.VCSRepo.IngressSubmodules, false) assert.Equal(t, ps.VCSRepo.OAuthTokenID, oc.ID) - assert.Equal(t, ps.VCSRepo.RepositoryHTTPURL, fmt.Sprintf("https://github.com/%s", githubIdentifier)) + assert.Equal(t, ps.VCSRepo.RepositoryHTTPURL, fmt.Sprintf(githubFmt, githubIdentifier)) assert.Equal(t, ps.VCSRepo.ServiceProvider, string(ServiceProviderGithub)) - assert.Regexp(t, fmt.Sprintf("^%s/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", regexp.QuoteMeta(DefaultConfig().Address)), ps.VCSRepo.WebhookURL) + assert.Regexp(t, fmt.Sprintf(testWebhookVscRegex, regexp.QuoteMeta(DefaultConfig().Address)), ps.VCSRepo.WebhookURL) }) t.Run("without a name provided", func(t *testing.T) { @@ -245,7 +245,7 @@ func TestPolicySetsCreate(t *testing.T) { assert.EqualError(t, err, ErrInvalidName.Error()) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { ps, err := client.PolicySets.Create(ctx, badIdentifier, PolicySetCreateOptions{ Name: String("policy-set"), }) @@ -336,10 +336,10 @@ func TestPolicySetsUpdate(t *testing.T) { psTest, psTestCleanup := createPolicySet(t, client, orgTest, nil, nil, "") defer psTestCleanup() - t.Run("with valid attributes", func(t *testing.T) { + t.Run(testWithValidAttributes, func(t *testing.T) { options := PolicySetUpdateOptions{ Name: String("global"), - Description: String("Policies in this set will be checked in ALL workspaces!"), + Description: String(testPolicySetDescription), Global: Bool(true), } diff --git a/policy_set_parameter_integration_test.go b/policy_set_parameter_integration_test.go index 52e98f48f..b0736d6de 100644 --- a/policy_set_parameter_integration_test.go +++ b/policy_set_parameter_integration_test.go @@ -8,6 +8,8 @@ import ( "github.com/stretchr/testify/require" ) +const testWhenUpdatingSubsetOfValues = "when updating a subset of values" + func TestPolicySetParametersList(t *testing.T) { skipIfFreeOnly(t) @@ -25,19 +27,19 @@ func TestPolicySetParametersList(t *testing.T) { pTest2, pTestCleanup2 := createPolicySetParameter(t, client, psTest) defer pTestCleanup2() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { pl, err := client.PolicySetParameters.List(ctx, psTest.ID, nil) require.NoError(t, err) assert.Contains(t, pl.Items, pTest1) assert.Contains(t, pl.Items, pTest2) - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) assert.Equal(t, 1, pl.CurrentPage) assert.Equal(t, 2, pl.TotalCount) }) t.Run("with list options", func(t *testing.T) { - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) // Request a page number which is out of range. The result should // be successful, but return no results if the paging options are // properly passed along. @@ -223,7 +225,7 @@ func TestPolicySetParametersUpdate(t *testing.T) { assert.Equal(t, *options.Value, p.Value) }) - t.Run("when updating a subset of values", func(t *testing.T) { + t.Run(testWhenUpdatingSubsetOfValues, func(t *testing.T) { options := PolicySetParameterUpdateOptions{ Key: String("someothername"), } 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..67a458223 100644 --- a/registry_module_integration_test.go +++ b/registry_module_integration_test.go @@ -15,6 +15,11 @@ import ( "github.com/stretchr/testify/require" ) +const testWithInvalidProvider = "with an invalid provider" +const testRelationshipsProperlyDecoded = "relationships are properly decoded" +const testWithInvalidName = "with an invalid name" +const testTimestampsProperlyDecoded = "timestamps are properly decoded" + func TestRegistryModulesList(t *testing.T) { client := testClient(t) ctx := context.Background() @@ -69,19 +74,19 @@ func TestRegistryModulesCreate(t *testing.T) { t.Run("with valid options", func(t *testing.T) { assertRegistryModuleAttributes := func(t *testing.T, registryModule *RegistryModule) { - t.Run("permissions are properly decoded", func(t *testing.T) { + t.Run(testPermissionsProperlyDecoded, func(t *testing.T) { require.NotEmpty(t, registryModule.Permissions) assert.True(t, registryModule.Permissions.CanDelete) assert.True(t, registryModule.Permissions.CanResync) assert.True(t, registryModule.Permissions.CanRetry) }) - t.Run("relationships are properly decoded", func(t *testing.T) { + t.Run(testRelationshipsProperlyDecoded, func(t *testing.T) { require.NotEmpty(t, registryModule.Organization) assert.Equal(t, orgTest.Name, registryModule.Organization.Name) }) - t.Run("timestamps are properly decoded", func(t *testing.T) { + t.Run(testTimestampsProperlyDecoded, func(t *testing.T) { assert.NotEmpty(t, registryModule.CreatedAt) assert.NotEmpty(t, registryModule.UpdatedAt) }) @@ -162,7 +167,7 @@ func TestRegistryModulesCreate(t *testing.T) { }) }) - t.Run("with invalid options", func(t *testing.T) { + t.Run(testWithInvalidOptions, func(t *testing.T) { t.Run("without a name", func(t *testing.T) { options := RegistryModuleCreateOptions{ Provider: String("provider"), @@ -172,7 +177,7 @@ func TestRegistryModulesCreate(t *testing.T) { assert.EqualError(t, err, ErrRequiredName.Error()) }) - t.Run("with an invalid name", func(t *testing.T) { + t.Run(testWithInvalidName, func(t *testing.T) { options := RegistryModuleCreateOptions{ Name: String("invalid name"), Provider: String("provider"), @@ -191,7 +196,7 @@ func TestRegistryModulesCreate(t *testing.T) { assert.Equal(t, err, ErrRequiredProvider) }) - t.Run("with an invalid provider", func(t *testing.T) { + t.Run(testWithInvalidProvider, func(t *testing.T) { options := RegistryModuleCreateOptions{ Name: String("name"), Provider: String("invalid provider"), @@ -236,7 +241,7 @@ func TestRegistryModulesCreate(t *testing.T) { }) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { options := RegistryModuleCreateOptions{ Name: String("name"), Provider: String("provider"), @@ -294,7 +299,6 @@ func TestRegistryModuleUpdate(t *testing.T) { require.NoError(t, err) assert.False(t, rm.NoCode) }) - } func TestRegistryModulesCreateVersion(t *testing.T) { @@ -321,11 +325,11 @@ func TestRegistryModulesCreateVersion(t *testing.T) { assert.NotEmpty(t, rmv.ID) assert.Equal(t, *options.Version, rmv.Version) - t.Run("relationships are properly decoded", func(t *testing.T) { + t.Run(testRelationshipsProperlyDecoded, func(t *testing.T) { assert.Equal(t, registryModuleTest.ID, rmv.RegistryModule.ID) }) - t.Run("timestamps are properly decoded", func(t *testing.T) { + t.Run(testTimestampsProperlyDecoded, func(t *testing.T) { assert.NotEmpty(t, rmv.CreatedAt) assert.NotEmpty(t, rmv.UpdatedAt) }) @@ -351,7 +355,7 @@ func TestRegistryModulesCreateVersion(t *testing.T) { assert.Equal(t, *options.Version, rmv.Version) }) - t.Run("with invalid options", func(t *testing.T) { + t.Run(testWithInvalidOptions, func(t *testing.T) { t.Run("without version", func(t *testing.T) { options := RegistryModuleCreateVersionOptions{} rmv, err := client.RegistryModules.CreateVersion(ctx, RegistryModuleID{ @@ -390,7 +394,7 @@ func TestRegistryModulesCreateVersion(t *testing.T) { assert.EqualError(t, err, ErrRequiredName.Error()) }) - t.Run("with an invalid name", func(t *testing.T) { + t.Run(testWithInvalidName, func(t *testing.T) { options := RegistryModuleCreateVersionOptions{ Version: String("1.2.3"), } @@ -416,7 +420,7 @@ func TestRegistryModulesCreateVersion(t *testing.T) { assert.Equal(t, err, ErrRequiredProvider) }) - t.Run("with an invalid provider", func(t *testing.T) { + t.Run(testWithInvalidProvider, func(t *testing.T) { options := RegistryModuleCreateVersionOptions{ Version: String("1.2.3"), } @@ -429,7 +433,7 @@ func TestRegistryModulesCreateVersion(t *testing.T) { assert.Equal(t, err, ErrInvalidProvider) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { options := RegistryModuleCreateVersionOptions{ Version: String("1.2.3"), } @@ -441,7 +445,6 @@ func TestRegistryModulesCreateVersion(t *testing.T) { assert.Nil(t, rmv) assert.EqualError(t, err, ErrInvalidOrg.Error()) }) - } func TestRegistryModulesCreateWithVCSConnection(t *testing.T) { @@ -480,27 +483,27 @@ func TestRegistryModulesCreateWithVCSConnection(t *testing.T) { assert.Equal(t, rm.VCSRepo.Identifier, githubIdentifier) assert.Equal(t, rm.VCSRepo.IngressSubmodules, true) assert.Equal(t, rm.VCSRepo.OAuthTokenID, oauthTokenTest.ID) - assert.Equal(t, rm.VCSRepo.RepositoryHTTPURL, fmt.Sprintf("https://github.com/%s", githubIdentifier)) + assert.Equal(t, rm.VCSRepo.RepositoryHTTPURL, fmt.Sprintf(githubFmt, githubIdentifier)) assert.Equal(t, rm.VCSRepo.ServiceProvider, string(ServiceProviderGithub)) - assert.Regexp(t, fmt.Sprintf("^%s/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", regexp.QuoteMeta(DefaultConfig().Address)), rm.VCSRepo.WebhookURL) + assert.Regexp(t, fmt.Sprintf(testWebhookVscRegex, regexp.QuoteMeta(DefaultConfig().Address)), rm.VCSRepo.WebhookURL) - t.Run("permissions are properly decoded", func(t *testing.T) { + t.Run(testPermissionsProperlyDecoded, func(t *testing.T) { assert.True(t, rm.Permissions.CanDelete) assert.True(t, rm.Permissions.CanResync) assert.True(t, rm.Permissions.CanRetry) }) - t.Run("relationships are properly decoded", func(t *testing.T) { + t.Run(testRelationshipsProperlyDecoded, func(t *testing.T) { assert.Equal(t, orgTest.Name, rm.Organization.Name) }) - t.Run("timestamps are properly decoded", func(t *testing.T) { + t.Run(testTimestampsProperlyDecoded, func(t *testing.T) { assert.NotEmpty(t, rm.CreatedAt) assert.NotEmpty(t, rm.UpdatedAt) }) }) - t.Run("with invalid options", func(t *testing.T) { + t.Run(testWithInvalidOptions, func(t *testing.T) { t.Run("without an identifier", func(t *testing.T) { options := RegistryModuleCreateWithVCSConnectionOptions{ VCSRepo: &RegistryModuleVCSRepoOptions{ @@ -547,7 +550,6 @@ func TestRegistryModulesCreateWithVCSConnection(t *testing.T) { assert.Nil(t, rm) assert.Equal(t, err, ErrRequiredVCSRepo) }) - } func TestRegistryModulesRead(t *testing.T) { @@ -572,13 +574,13 @@ func TestRegistryModulesRead(t *testing.T) { require.NoError(t, err) assert.Equal(t, registryModuleTest.ID, rm.ID) - t.Run("permissions are properly decoded", func(t *testing.T) { + t.Run(testPermissionsProperlyDecoded, func(t *testing.T) { assert.True(t, rm.Permissions.CanDelete) assert.True(t, rm.Permissions.CanResync) assert.True(t, rm.Permissions.CanRetry) }) - t.Run("timestamps are properly decoded", func(t *testing.T) { + t.Run(testTimestampsProperlyDecoded, func(t *testing.T) { assert.NotEmpty(t, rm.CreatedAt) assert.NotEmpty(t, rm.UpdatedAt) }) @@ -596,14 +598,14 @@ func TestRegistryModulesRead(t *testing.T) { require.NotEmpty(t, rm) assert.Equal(t, registryModuleTest.ID, rm.ID) - t.Run("permissions are properly decoded", func(t *testing.T) { + t.Run(testPermissionsProperlyDecoded, func(t *testing.T) { require.NotEmpty(t, rm.Permissions) assert.True(t, rm.Permissions.CanDelete) assert.True(t, rm.Permissions.CanResync) assert.True(t, rm.Permissions.CanRetry) }) - t.Run("timestamps are properly decoded", func(t *testing.T) { + t.Run(testTimestampsProperlyDecoded, func(t *testing.T) { assert.NotEmpty(t, rm.CreatedAt) assert.NotEmpty(t, rm.UpdatedAt) }) @@ -621,14 +623,14 @@ func TestRegistryModulesRead(t *testing.T) { require.NotEmpty(t, rm) assert.Equal(t, publicRegistryModuleTest.ID, rm.ID) - t.Run("permissions are properly decoded", func(t *testing.T) { + t.Run(testPermissionsProperlyDecoded, func(t *testing.T) { require.NotEmpty(t, rm.Permissions) assert.True(t, rm.Permissions.CanDelete) assert.True(t, rm.Permissions.CanResync) assert.True(t, rm.Permissions.CanRetry) }) - t.Run("timestamps are properly decoded", func(t *testing.T) { + t.Run(testTimestampsProperlyDecoded, func(t *testing.T) { assert.NotEmpty(t, rm.CreatedAt) assert.NotEmpty(t, rm.UpdatedAt) }) @@ -644,7 +646,7 @@ func TestRegistryModulesRead(t *testing.T) { assert.EqualError(t, err, ErrRequiredName.Error()) }) - t.Run("with an invalid name", func(t *testing.T) { + t.Run(testWithInvalidName, func(t *testing.T) { rm, err := client.RegistryModules.Read(ctx, RegistryModuleID{ Organization: orgTest.Name, Name: badIdentifier, @@ -664,7 +666,7 @@ func TestRegistryModulesRead(t *testing.T) { assert.Equal(t, err, ErrRequiredProvider) }) - t.Run("with an invalid provider", func(t *testing.T) { + t.Run(testWithInvalidProvider, func(t *testing.T) { rm, err := client.RegistryModules.Read(ctx, RegistryModuleID{ Organization: orgTest.Name, Name: registryModuleTest.Name, @@ -686,7 +688,7 @@ func TestRegistryModulesRead(t *testing.T) { assert.Equal(t, err, ErrInvalidRegistryName) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { rm, err := client.RegistryModules.Read(ctx, RegistryModuleID{ Organization: badIdentifier, Name: registryModuleTest.Name, @@ -745,12 +747,12 @@ func TestRegistryModulesDelete(t *testing.T) { assert.EqualError(t, err, ErrRequiredName.Error()) }) - t.Run("with an invalid name", func(t *testing.T) { + t.Run(testWithInvalidName, func(t *testing.T) { err := client.RegistryModules.Delete(ctx, orgTest.Name, badIdentifier) assert.EqualError(t, err, ErrInvalidName.Error()) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { err := client.RegistryModules.Delete(ctx, badIdentifier, registryModuleTest.Name) assert.EqualError(t, err, ErrInvalidOrg.Error()) }) @@ -797,7 +799,7 @@ func TestRegistryModulesDeleteProvider(t *testing.T) { assert.EqualError(t, err, ErrRequiredName.Error()) }) - t.Run("with an invalid name", func(t *testing.T) { + t.Run(testWithInvalidName, func(t *testing.T) { err := client.RegistryModules.DeleteProvider(ctx, RegistryModuleID{ Organization: orgTest.Name, Name: badIdentifier, @@ -815,7 +817,7 @@ func TestRegistryModulesDeleteProvider(t *testing.T) { assert.Equal(t, err, ErrRequiredProvider) }) - t.Run("with an invalid provider", func(t *testing.T) { + t.Run(testWithInvalidProvider, func(t *testing.T) { err := client.RegistryModules.DeleteProvider(ctx, RegistryModuleID{ Organization: orgTest.Name, Name: registryModuleTest.Name, @@ -824,7 +826,7 @@ func TestRegistryModulesDeleteProvider(t *testing.T) { assert.Equal(t, err, ErrInvalidProvider) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { err := client.RegistryModules.DeleteProvider(ctx, RegistryModuleID{ Organization: badIdentifier, Name: registryModuleTest.Name, @@ -943,7 +945,7 @@ func TestRegistryModulesDeleteVersion(t *testing.T) { assert.EqualError(t, err, ErrRequiredName.Error()) }) - t.Run("with an invalid name", func(t *testing.T) { + t.Run(testWithInvalidName, func(t *testing.T) { err := client.RegistryModules.DeleteVersion(ctx, RegistryModuleID{ Organization: orgTest.Name, Name: badIdentifier, @@ -961,7 +963,7 @@ func TestRegistryModulesDeleteVersion(t *testing.T) { assert.Equal(t, err, ErrRequiredProvider) }) - t.Run("with an invalid provider", func(t *testing.T) { + t.Run(testWithInvalidProvider, func(t *testing.T) { err := client.RegistryModules.DeleteVersion(ctx, RegistryModuleID{ Organization: orgTest.Name, Name: registryModuleTest.Name, @@ -988,7 +990,7 @@ func TestRegistryModulesDeleteVersion(t *testing.T) { assert.Equal(t, err, ErrInvalidVersion) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { err := client.RegistryModules.DeleteVersion(ctx, RegistryModuleID{ Organization: badIdentifier, Name: registryModuleTest.Name, @@ -1032,7 +1034,7 @@ func TestRegistryModulesUpload(t *testing.T) { err = client.RegistryModules.Upload( ctx, *rmv, - "test-fixtures/config-version", + testConfigVersionPath, ) require.NoError(t, err) }) @@ -1043,7 +1045,7 @@ func TestRegistryModulesUpload(t *testing.T) { err = client.RegistryModules.Upload( ctx, *rmv, - "test-fixtures/config-version", + testConfigVersionPath, ) assert.EqualError(t, err, "provided RegistryModuleVersion does not contain an upload link") }) diff --git a/registry_provider_integration_test.go b/registry_provider_integration_test.go index 2f8e41a58..8de8a7ff9 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", @@ -185,15 +184,15 @@ func TestRegistryProvidersCreate(t *testing.T) { assert.Equal(t, options.Namespace, prv.Namespace) assert.Equal(t, options.RegistryName, prv.RegistryName) - t.Run("permissions are properly decoded", func(t *testing.T) { + t.Run(testPermissionsProperlyDecoded, func(t *testing.T) { assert.True(t, prv.Permissions.CanDelete) }) - t.Run("relationships are properly decoded", func(t *testing.T) { + t.Run(testRelationshipsProperlyDecoded, func(t *testing.T) { assert.Equal(t, orgTest.Name, prv.Organization.Name) }) - t.Run("timestamps are properly decoded", func(t *testing.T) { + t.Run(testTimestampsProperlyDecoded, func(t *testing.T) { assert.NotEmpty(t, prv.CreatedAt) assert.NotEmpty(t, prv.UpdatedAt) }) @@ -201,7 +200,7 @@ func TestRegistryProvidersCreate(t *testing.T) { } }) - t.Run("with invalid options", func(t *testing.T) { + t.Run(testWithInvalidOptions, func(t *testing.T) { t.Run("without a name", func(t *testing.T) { options := RegistryProviderCreateOptions{ Namespace: "namespace", @@ -212,7 +211,7 @@ func TestRegistryProvidersCreate(t *testing.T) { assert.EqualError(t, err, ErrInvalidName.Error()) }) - t.Run("with an invalid name", func(t *testing.T) { + t.Run(testWithInvalidName, func(t *testing.T) { options := RegistryProviderCreateOptions{ Name: "invalid name", Namespace: "namespace", @@ -268,7 +267,7 @@ func TestRegistryProvidersCreate(t *testing.T) { }) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { options := RegistryProviderCreateOptions{ Name: "name", Namespace: "namespace", @@ -322,15 +321,15 @@ func TestRegistryProvidersRead(t *testing.T) { assert.Equal(t, registryProviderTest.Namespace, prv.Namespace) assert.Equal(t, registryProviderTest.RegistryName, prv.RegistryName) - t.Run("permissions are properly decoded", func(t *testing.T) { + t.Run(testPermissionsProperlyDecoded, func(t *testing.T) { assert.True(t, prv.Permissions.CanDelete) }) - t.Run("relationships are properly decoded", func(t *testing.T) { + t.Run(testRelationshipsProperlyDecoded, func(t *testing.T) { assert.Equal(t, orgTest.Name, prv.Organization.Name) }) - t.Run("timestamps are properly decoded", func(t *testing.T) { + t.Run(testTimestampsProperlyDecoded, func(t *testing.T) { assert.NotEmpty(t, prv.CreatedAt) assert.NotEmpty(t, prv.UpdatedAt) }) @@ -478,7 +477,7 @@ func TestRegistryProvidersIDValidation(t *testing.T) { assert.EqualError(t, id.valid(), ErrInvalidName.Error()) }) - t.Run("with an invalid name", func(t *testing.T) { + t.Run(testWithInvalidName, func(t *testing.T) { id := RegistryProviderID{ OrganizationName: orgName, RegistryName: registryName, @@ -518,7 +517,7 @@ func TestRegistryProvidersIDValidation(t *testing.T) { assert.EqualError(t, id.valid(), ErrInvalidRegistryName.Error()) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { id := RegistryProviderID{ OrganizationName: badIdentifier, RegistryName: registryName, diff --git a/registry_provider_platform_integration_test.go b/registry_provider_platform_integration_test.go index bf9b49f1a..71f9ae21e 100644 --- a/registry_provider_platform_integration_test.go +++ b/registry_provider_platform_integration_test.go @@ -45,7 +45,7 @@ func TestRegistryProviderPlatformsCreate(t *testing.T) { assert.Equal(t, options.Shasum, rpp.Shasum) assert.Equal(t, options.Filename, rpp.Filename) - t.Run("relationships are properly decoded", func(t *testing.T) { + t.Run(testRelationshipsProperlyDecoded, func(t *testing.T) { assert.Equal(t, version.ID, rpp.RegistryProviderVersion.ID) }) @@ -57,7 +57,7 @@ func TestRegistryProviderPlatformsCreate(t *testing.T) { }) }) - t.Run("with invalid options", func(t *testing.T) { + t.Run(testWithInvalidOptions, func(t *testing.T) { t.Run("without an OS", func(t *testing.T) { options := RegistryProviderPlatformCreateOptions{ OS: "", @@ -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", @@ -247,7 +247,7 @@ func TestRegistryProviderPlatformsRead(t *testing.T) { assert.Equal(t, platform.Filename, readPlatform.Filename) assert.Equal(t, platform.Shasum, readPlatform.Shasum) - t.Run("relationships are properly decoded", func(t *testing.T) { + t.Run(testRelationshipsProperlyDecoded, func(t *testing.T) { assert.Equal(t, platform.RegistryProviderVersion.ID, readPlatform.RegistryProviderVersion.ID) }) @@ -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..cc04da66b 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,17 +101,17 @@ 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) assert.Equal(t, options.KeyID, prvv.KeyID) - t.Run("relationships are properly decoded", func(t *testing.T) { + t.Run(testRelationshipsProperlyDecoded, func(t *testing.T) { assert.Equal(t, providerTest.ID, prvv.RegistryProvider.ID) }) - t.Run("timestamps are properly decoded", func(t *testing.T) { + t.Run(testTimestampsProperlyDecoded, func(t *testing.T) { assert.NotEmpty(t, prvv.CreatedAt) assert.NotEmpty(t, prvv.UpdatedAt) }) @@ -139,13 +139,13 @@ func TestRegistryProviderVersionsCreate(t *testing.T) { }) }) - t.Run("with invalid options", func(t *testing.T) { + t.Run(testWithInvalidOptions, func(t *testing.T) { t.Run("without a version", func(t *testing.T) { options := RegistryProviderVersionCreateOptions{ 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()) }) @@ -293,7 +293,7 @@ func TestRegistryProviderVersionsList(t *testing.T) { assert.Equal(t, 0, versions.TotalPages) }) - // TODO + // TODO: complete with include provider platforms t.Run("with include provider platforms", func(t *testing.T) { }) } @@ -362,11 +362,11 @@ func TestRegistryProviderVersionsRead(t *testing.T) { assert.Equal(t, version.Version, readVersion.Version) assert.Equal(t, version.KeyID, readVersion.KeyID) - t.Run("relationships are properly decoded", func(t *testing.T) { + t.Run(testRelationshipsProperlyDecoded, func(t *testing.T) { assert.Equal(t, version.RegistryProvider.ID, readVersion.RegistryProvider.ID) }) - t.Run("timestamps are properly decoded", func(t *testing.T) { + t.Run(testTimestampsProperlyDecoded, func(t *testing.T) { assert.NotEmpty(t, readVersion.CreatedAt) assert.NotEmpty(t, readVersion.UpdatedAt) }) @@ -400,5 +400,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..82add1619 100644 --- a/request.go +++ b/request.go @@ -66,7 +66,7 @@ func (r ClientRequest) Do(ctx context.Context, model interface{}) error { // 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_integration_test.go b/run_integration_test.go index 4670de4e3..98c52cdbf 100644 --- a/run_integration_test.go +++ b/run_integration_test.go @@ -13,6 +13,8 @@ import ( "github.com/stretchr/testify/require" ) +const testWithoutValidWorkspaceID = "without a valid workspace ID" + func TestRunsList(t *testing.T) { client := testClient(t) ctx := context.Background() @@ -24,7 +26,7 @@ func TestRunsList(t *testing.T) { rTest1, _ := createRun(t, client, wTest) rTest2, _ := createRun(t, client, wTest) - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { rl, err := client.Runs.List(ctx, wTest.ID, nil) require.NoError(t, err) @@ -58,7 +60,7 @@ func TestRunsList(t *testing.T) { }) t.Run("with list options", func(t *testing.T) { - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) // Request a page number which is out of range. The result should // be successful, but return no results if the paging options are @@ -86,7 +88,7 @@ func TestRunsList(t *testing.T) { assert.NotEmpty(t, rl.Items[0].Workspace.Name) }) - t.Run("without a valid workspace ID", func(t *testing.T) { + t.Run(testWithoutValidWorkspaceID, func(t *testing.T) { rl, err := client.Runs.List(ctx, badIdentifier, nil) assert.Nil(t, rl) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) @@ -339,7 +341,7 @@ func TestRunsRead_CostEstimate(t *testing.T) { assert.Equal(t, rTest, r) }) - t.Run("when the run does not exist", func(t *testing.T) { + t.Run(testWhenRunDoesNotExist, func(t *testing.T) { r, err := client.Runs.Read(ctx, "nonexisting") assert.Nil(t, r) assert.Equal(t, err, ErrResourceNotFound) @@ -398,7 +400,7 @@ func TestRunsApply(t *testing.T) { assert.Equal(t, "Hello, Earl", c.Body) }) - t.Run("when the run does not exist", func(t *testing.T) { + t.Run(testWhenRunDoesNotExist, func(t *testing.T) { err := client.Runs.Apply(ctx, "nonexisting", RunApplyOptions{}) assert.Equal(t, err, ErrResourceNotFound) }) @@ -429,7 +431,7 @@ func TestRunsCancel(t *testing.T) { require.NoError(t, err) }) - t.Run("when the run does not exist", func(t *testing.T) { + t.Run(testWhenRunDoesNotExist, func(t *testing.T) { err := client.Runs.Cancel(ctx, "nonexisting", RunCancelOptions{}) assert.Equal(t, err, ErrResourceNotFound) }) @@ -497,7 +499,7 @@ func TestRunsForceCancel(t *testing.T) { // https://www.terraform.io/docs/cloud/api/run.html#forcefully-cancel-a-run). }) - t.Run("when the run does not exist", func(t *testing.T) { + t.Run(testWhenRunDoesNotExist, func(t *testing.T) { err := client.Runs.ForceCancel(ctx, "nonexisting", RunForceCancelOptions{}) assert.Equal(t, err, ErrResourceNotFound) }) @@ -552,7 +554,7 @@ func TestRunsForceExecute(t *testing.T) { assert.Equal(t, RunDiscarded, rToCancel.Status) }) - t.Run("when the run does not exist", func(t *testing.T) { + t.Run(testWhenRunDoesNotExist, func(t *testing.T) { err := client.Runs.ForceExecute(ctx, "nonexisting") assert.Equal(t, err, ErrResourceNotFound) }) @@ -577,7 +579,7 @@ func TestRunsDiscard(t *testing.T) { require.NoError(t, err) }) - t.Run("when the run does not exist", func(t *testing.T) { + t.Run(testWhenRunDoesNotExist, func(t *testing.T) { err := client.Runs.Discard(ctx, "nonexisting", RunDiscardOptions{}) assert.Equal(t, err, ErrResourceNotFound) }) @@ -612,8 +614,8 @@ func TestRun_Unmarshal(t *testing.T) { "can-force-execute": true, }, "status-timestamps": map[string]string{ - "plan-queued-at": "2020-03-16T23:15:59+00:00", - "errored-at": "2019-03-16T23:23:59+00:00", + "plan-queued-at": testQueuedAtTime, + "errored-at": testTimeMidnight, }, "variables": []map[string]string{{"key": "a-key", "value": "\"a-value\""}}, }, @@ -627,9 +629,9 @@ func TestRun_Unmarshal(t *testing.T) { err = unmarshalResponse(responseBody, run) require.NoError(t, err) - planQueuedParsedTime, err := time.Parse(time.RFC3339, "2020-03-16T23:15:59+00:00") + planQueuedParsedTime, err := time.Parse(time.RFC3339, testQueuedAtTime) require.NoError(t, err) - erroredParsedTime, err := time.Parse(time.RFC3339, "2019-03-16T23:23:59+00:00") + erroredParsedTime, err := time.Parse(time.RFC3339, testTimeMidnight) require.NoError(t, err) iso8601TimeFormat := "2006-01-02T15:04:05Z" 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/run_trigger_integration_test.go b/run_trigger_integration_test.go index c20913475..022876935 100644 --- a/run_trigger_integration_test.go +++ b/run_trigger_integration_test.go @@ -65,7 +65,7 @@ func TestRunTriggerList(t *testing.T) { assert.Equal(t, 2, rtl.TotalCount) }) - t.Run("without a valid workspace", func(t *testing.T) { + t.Run(testWithoutValidWorkspace, func(t *testing.T) { rtl, err := client.RunTriggers.List( ctx, badIdentifier, @@ -172,13 +172,13 @@ func TestRunTriggerCreate(t *testing.T) { assert.Equal(t, err, ErrRequiredSourceable) }) - t.Run("without a valid workspace", func(t *testing.T) { + t.Run(testWithoutValidWorkspace, func(t *testing.T) { rt, err := client.RunTriggers.Create(ctx, badIdentifier, RunTriggerCreateOptions{}) assert.Nil(t, rt) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) }) - t.Run("when an error is returned from the api", func(t *testing.T) { + t.Run(testWhenErrorFromAPI, func(t *testing.T) { // There are many cases that would cause the server to return an error // on run trigger creation. This tests one of them: setting workspace // and sourceable to the same workspace diff --git a/ssh_key_integration_test.go b/ssh_key_integration_test.go index 240aa89c9..31346e644 100644 --- a/ssh_key_integration_test.go +++ b/ssh_key_integration_test.go @@ -20,19 +20,19 @@ func TestSSHKeysList(t *testing.T) { kTest2, kTestCleanup2 := createSSHKey(t, client, orgTest) defer kTestCleanup2() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { kl, err := client.SSHKeys.List(ctx, orgTest.Name, nil) require.NoError(t, err) assert.Contains(t, kl.Items, kTest1) assert.Contains(t, kl.Items, kTest2) - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) assert.Equal(t, 1, kl.CurrentPage) assert.Equal(t, 2, kl.TotalCount) }) t.Run("with list options", func(t *testing.T) { - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) // Request a page number which is out of range. The result should // be successful, but return no results if the paging options are // properly passed along. @@ -48,7 +48,7 @@ func TestSSHKeysList(t *testing.T) { assert.Equal(t, 2, kl.TotalCount) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { kl, err := client.SSHKeys.List(ctx, badIdentifier, nil) assert.Nil(t, kl) assert.EqualError(t, err, ErrInvalidOrg.Error()) @@ -84,7 +84,7 @@ func TestSSHKeysCreate(t *testing.T) { } }) - t.Run("when options is missing name", func(t *testing.T) { + t.Run(testWhenOptionsMissingName, func(t *testing.T) { k, err := client.SSHKeys.Create(ctx, "foo", SSHKeyCreateOptions{ Value: String(randomString(t)), }) @@ -100,7 +100,7 @@ func TestSSHKeysCreate(t *testing.T) { assert.Equal(t, err, ErrRequiredValue) }) - t.Run("when options has an invalid organization", func(t *testing.T) { + t.Run(testWhenOptionsHasInvalidOrganization, func(t *testing.T) { k, err := client.SSHKeys.Create(ctx, badIdentifier, SSHKeyCreateOptions{ Name: String("foo"), }) diff --git a/state_version_integration_test.go b/state_version_integration_test.go index d71f20388..3e32befcb 100644 --- a/state_version_integration_test.go +++ b/state_version_integration_test.go @@ -12,6 +12,8 @@ import ( "github.com/stretchr/testify/require" ) +const testWhenStateVersionExists = "when the state version exists" + func containsStateVersion(versions []*StateVersion, item *StateVersion) bool { for _, sv := range versions { if sv.ID == item.ID { @@ -42,7 +44,7 @@ func TestStateVersionsList(t *testing.T) { assert.Equal(t, err, ErrRequiredStateVerListOps) }) - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { options := &StateVersionListOptions{ Organization: orgTest.Name, Workspace: wTest.Name, @@ -314,8 +316,9 @@ func TestStateVersionsRead(t *testing.T) { svTest, svTestCleanup := createStateVersion(t, client, 0, nil) t.Cleanup(svTestCleanup) - t.Run("when the state version exists", func(t *testing.T) { + t.Run(testWhenStateVersionExists, func(t *testing.T) { var sv *StateVersion + var ok bool sv, err := client.StateVersions.Read(ctx, svTest.ID) require.NoError(t, err) @@ -335,7 +338,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.Fatal("could not retrieve state version") + } } assert.NotEmpty(t, sv.DownloadURL) @@ -367,7 +373,7 @@ func TestStateVersionsReadWithOptions(t *testing.T) { // give TFC some time to process the statefile and extract the outputs. waitForSVOutputs(t, client, svTest.ID) - t.Run("when the state version exists", func(t *testing.T) { + t.Run(testWhenStateVersionExists, func(t *testing.T) { curOpts := &StateVersionReadOptions{ Include: []StateVersionIncludeOpt{SVoutputs}, } @@ -437,7 +443,7 @@ func TestStateVersionsCurrentWithOptions(t *testing.T) { // give TFC some time to process the statefile and extract the outputs. waitForSVOutputs(t, client, svTest.ID) - t.Run("when the state version exists", func(t *testing.T) { + t.Run(testWhenStateVersionExists, func(t *testing.T) { curOpts := &StateVersionCurrentOptions{ Include: []StateVersionIncludeOpt{SVoutputs}, } @@ -459,7 +465,7 @@ func TestStateVersionsDownload(t *testing.T) { stateTest, err := os.ReadFile("test-fixtures/state-version/terraform.tfstate") require.NoError(t, err) - t.Run("when the state version exists", func(t *testing.T) { + t.Run(testWhenStateVersionExists, func(t *testing.T) { state, err := client.StateVersions.Download(ctx, svTest.DownloadURL) require.NoError(t, err) assert.Equal(t, stateTest, state) @@ -485,7 +491,7 @@ func TestStateVersionOutputs(t *testing.T) { // give TFC some time to process the statefile and extract the outputs. waitForSVOutputs(t, client, sv.ID) - t.Run("when the state version exists", func(t *testing.T) { + t.Run(testWhenStateVersionExists, func(t *testing.T) { outputs, err := client.StateVersions.ListOutputs(ctx, sv.ID, nil) require.NoError(t, err) @@ -528,5 +534,4 @@ func TestStateVersionOutputs(t *testing.T) { assert.Nil(t, outputs) assert.Error(t, err) }) - } diff --git a/team_access_integration_test.go b/team_access_integration_test.go index 49b4af2d4..e6bc976b2 100644 --- a/team_access_integration_test.go +++ b/team_access_integration_test.go @@ -38,13 +38,13 @@ func TestTeamAccessesList(t *testing.T) { assert.Contains(t, tal.Items, taTest1) assert.Contains(t, tal.Items, taTest2) - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) assert.Equal(t, 1, tal.CurrentPage) assert.Equal(t, 2, tal.TotalCount) }) t.Run("with list options", func(t *testing.T) { - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) // Request a page number which is out of range. The result should // be successful, but return no results if the paging options are // properly passed along. @@ -288,7 +288,7 @@ func TestTeamAccessesUpdate(t *testing.T) { taTest, taTestCleanup := createTeamAccess(t, client, tmTest, wTest, orgTest) defer taTestCleanup() - t.Run("with valid attributes", func(t *testing.T) { + t.Run(testWithValidAttributes, func(t *testing.T) { options := TeamAccessUpdateOptions{ Access: Access(AccessCustom), Runs: RunsPermission(RunsPermissionPlan), @@ -385,7 +385,7 @@ func TestTeamAccessesUpdateRunTasks(t *testing.T) { taTest, taTestCleanup := createTeamAccess(t, client, tmTest, wTest, orgTest) defer taTestCleanup() - t.Run("with valid attributes", func(t *testing.T) { + t.Run(testWithValidAttributes, func(t *testing.T) { newAccess := !taTest.RunTasks options := TeamAccessUpdateOptions{ Access: Access(AccessCustom), diff --git a/team_integration_test.go b/team_integration_test.go index 0602d5fe3..971708c78 100644 --- a/team_integration_test.go +++ b/team_integration_test.go @@ -27,19 +27,19 @@ func TestTeamsList(t *testing.T) { tmTest3, tmTest3Cleanup := createTeam(t, client, orgTest) defer tmTest3Cleanup() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { tl, err := client.Teams.List(ctx, orgTest.Name, nil) require.NoError(t, err) assert.Contains(t, tl.Items, tmTest1) assert.Contains(t, tl.Items, tmTest2) - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) assert.Equal(t, 1, tl.CurrentPage) assert.Equal(t, 2, tl.TotalCount) }) t.Run("with list options", func(t *testing.T) { - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) // Request a page number which is out of range. The result should // be successful, but return no results if the paging options are // properly passed along. @@ -71,7 +71,7 @@ func TestTeamsList(t *testing.T) { }) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { tl, err := client.Teams.List(ctx, badIdentifier, nil) assert.Nil(t, tl) assert.EqualError(t, err, ErrInvalidOrg.Error()) @@ -122,13 +122,13 @@ func TestTeamsCreate(t *testing.T) { assert.Equal(t, *options.SSOTeamID, team.SSOTeamID) }) - t.Run("when options is missing name", func(t *testing.T) { + t.Run(testWhenOptionsMissingName, func(t *testing.T) { tm, err := client.Teams.Create(ctx, "foo", TeamCreateOptions{}) assert.Nil(t, tm) assert.EqualError(t, err, ErrRequiredName.Error()) }) - t.Run("when options has an invalid organization", func(t *testing.T) { + t.Run(testWhenOptionsHasInvalidOrganization, func(t *testing.T) { tm, err := client.Teams.Create(ctx, badIdentifier, TeamCreateOptions{ Name: String("foo"), }) @@ -172,7 +172,7 @@ func TestTeamsRead(t *testing.T) { assert.Equal(t, "secret", tm.Visibility) }) - t.Run("permissions are properly decoded", func(t *testing.T) { + t.Run(testPermissionsProperlyDecoded, func(t *testing.T) { assert.True(t, tm.Permissions.CanDestroy) }) diff --git a/team_token_integration_test.go b/team_token_integration_test.go index 8efd59849..350c4e207 100644 --- a/team_token_integration_test.go +++ b/team_token_integration_test.go @@ -48,7 +48,7 @@ func TestTeamTokensRead(t *testing.T) { defer tmTestCleanup() t.Run("with valid options", func(t *testing.T) { - _, ttTestCleanup := createTeamToken(t, client, tmTest) + ttTestCleanup := createTeamToken(t, client, tmTest) tt, err := client.TeamTokens.Read(ctx, tmTest.ID) require.NoError(t, err) diff --git a/tfe.go b/tfe.go index 2c155dd93..7d40f0aad 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" + ContentTypeVndJSON = "application/vnd.api+json" ) // RetryLogHook allows a function to run before each retry. @@ -213,7 +214,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", ContentTypeVndJSON) if reqAttr != nil { q, err := query.Values(reqAttr) @@ -226,8 +227,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", ContentTypeVndJSON) + reqHeaders.Set("Content-Type", ContentTypeVndJSON) if reqAttr != nil { if body, err = serializeRequestBody(reqAttr); err != nil { @@ -569,7 +570,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", ContentTypeVndJSON) 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..06a238a9d 100644 --- a/tfe_integration_test.go +++ b/tfe_integration_test.go @@ -11,15 +11,17 @@ import ( "testing" "time" - retryablehttp "github.com/hashicorp/go-retryablehttp" "github.com/hashicorp/jsonapi" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "golang.org/x/time/rate" ) +const testUnexpectedErrorFmt = "unexpected error: %v" + 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", ContentTypeVndJSON) w.Header().Set("X-RateLimit-Limit", "30") w.Header().Set("TFP-API-Version", "34.21.9") w.Header().Set("X-TFE-Version", "202205-1") @@ -51,7 +53,7 @@ func TestClient_newClient(t *testing.T) { _, err := NewClient(cfg) if err == nil || err.Error() != "missing API token" { - t.Fatalf("unexpected error: %v", err) + t.Fatalf(testUnexpectedErrorFmt, err) } }) @@ -129,13 +131,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", ContentTypeVndJSON) 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") != ContentTypeVndJSON { t.Fatalf("unexpected accept header: %q", r.Header.Get("Accept")) } if r.Header.Get("Authorization") != "Bearer dummy-token" { @@ -175,11 +177,16 @@ 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") + _, err = client.Organizations.List(ctx, nil) + require.NoError(t, err) + _, err = client.Plans.Logs(ctx, "plan-123456789") + require.NoError(t, err) + err = client.Runs.Apply(ctx, "run-123456789", RunApplyOptions{}) + require.NoError(t, err) + _, err = client.Workspaces.Lock(ctx, "ws-123456789", WorkspaceLockOptions{}) + require.NoError(t, err) + _, err = client.Workspaces.Read(ctx, "organization", "workspace") + require.NoError(t, err) if testedCalls != 6 { t.Fatalf("expected 6 tested calls, got: %d", testedCalls) @@ -192,7 +199,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", ContentTypeVndJSON) w.Header().Set("X-RateLimit-Limit", "30") w.WriteHeader(204) // We query the configured ping URL which should return a 204. return @@ -222,11 +229,16 @@ 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") + _, err = client.Organizations.List(ctx, nil) + require.NoError(t, err) + _, err = client.Plans.Logs(ctx, "plan-123456789") + require.NoError(t, err) + err = client.Runs.Apply(ctx, "run-123456789", RunApplyOptions{}) + require.NoError(t, err) + _, err = client.Workspaces.Lock(ctx, "ws-123456789", WorkspaceLockOptions{}) + require.NoError(t, err) + _, err = client.Workspaces.Read(ctx, "organization", "workspace") + require.NoError(t, err) if testedCalls != 6 { t.Fatalf("expected 6 tested calls, got: %d", testedCalls) @@ -249,7 +261,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 +279,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 +300,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 +318,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 +334,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,68 +345,68 @@ 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) + t.Fatalf(testUnexpectedErrorFmt, err) } }) t.Run("non-pointer request", func(t *testing.T) { body := InvalidBody{} - _, _, 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) + _, err := createRequest(body) + if err == nil || err != ErrInvalidRequestBody { + t.Fatalf(testUnexpectedErrorFmt, err) } }) t.Run("slice of non-pointer request", func(t *testing.T) { body := []InvalidBody{{}} - _, _, 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) + _, err := createRequest(body) + if err == nil || err != ErrInvalidRequestBody { + t.Fatalf(testUnexpectedErrorFmt, err) } }) t.Run("map request", func(t *testing.T) { body := make(map[string]string) - _, _, 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) + _, err := createRequest(body) + if err == nil || err != ErrInvalidRequestBody { + t.Fatalf(testUnexpectedErrorFmt, err) } }) t.Run("string request", func(t *testing.T) { body := "foo" - _, _, 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) + _, err := createRequest(body) + if err == nil || err != ErrInvalidRequestBody { + t.Fatalf(testUnexpectedErrorFmt, 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", ContentTypeVndJSON) w.Header().Set("X-RateLimit-Limit", rateLimit) w.WriteHeader(204) // We query the configured ping URL which should return a 204. })) @@ -454,7 +466,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", ContentTypeVndJSON) w.Header().Set("X-RateLimit-Limit", "30") w.WriteHeader(204) // We query the configured ping URL which should return a 204. })) @@ -536,7 +548,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", ContentTypeVndJSON) w.Header().Set("X-RateLimit-Limit", "30") w.WriteHeader(204) // We query the configured ping URL which should return a 204. })) diff --git a/tfe_test.go b/tfe_test.go index 1fe614cf8..f17eae009 100644 --- a/tfe_test.go +++ b/tfe_test.go @@ -63,7 +63,7 @@ func Test_unmarshalResponse(t *testing.T) { }, }, "status-timestamps": map[string]string{ - "queued-at": "2020-03-16T23:15:59+00:00", + "queued-at": testQueuedAtTime, }, }, }, @@ -75,7 +75,7 @@ func Test_unmarshalResponse(t *testing.T) { unmarshalledRequestBody := tfeAPI{} err := unmarshalResponse(responseBody, &unmarshalledRequestBody) require.NoError(t, err) - queuedParsedTime, err := time.Parse(time.RFC3339, "2020-03-16T23:15:59+00:00") + queuedParsedTime, err := time.Parse(time.RFC3339, testQueuedAtTime) require.NoError(t, err) assert.Equal(t, unmarshalledRequestBody.ID, "1") diff --git a/variable_integration_test.go b/variable_integration_test.go index 6b4a52da8..fc4b9b736 100644 --- a/variable_integration_test.go +++ b/variable_integration_test.go @@ -8,6 +8,8 @@ import ( "github.com/stretchr/testify/require" ) +const testWithInvalidVariableID = "with invalid variable ID" + func TestVariablesList(t *testing.T) { client := testClient(t) ctx := context.Background() @@ -23,19 +25,19 @@ func TestVariablesList(t *testing.T) { vTest2, vTestCleanup2 := createVariable(t, client, wTest) defer vTestCleanup2() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { vl, err := client.Variables.List(ctx, wTest.ID, nil) require.NoError(t, err) assert.Contains(t, vl.Items, vTest1) assert.Contains(t, vl.Items, vTest2) - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) assert.Equal(t, 1, vl.CurrentPage) assert.Equal(t, 2, vl.TotalCount) }) t.Run("with list options", func(t *testing.T) { - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) // Request a page number which is out of range. The result should // be successful, but return no results if the paging options are // properly passed along. @@ -215,7 +217,7 @@ func TestVariablesRead(t *testing.T) { assert.Equal(t, ErrResourceNotFound, err) }) - t.Run("without a valid workspace ID", func(t *testing.T) { + t.Run(testWithoutValidWorkspaceID, func(t *testing.T) { v, err := client.Variables.Read(ctx, badIdentifier, vTest.ID) assert.Nil(t, v) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) @@ -250,7 +252,7 @@ func TestVariablesUpdate(t *testing.T) { assert.Equal(t, *options.Value, v.Value) }) - t.Run("when updating a subset of values", func(t *testing.T) { + t.Run(testWhenUpdatingSubsetOfValues, func(t *testing.T) { options := VariableUpdateOptions{ Key: String("someothername"), HCL: Bool(false), @@ -297,12 +299,12 @@ func TestVariablesUpdate(t *testing.T) { assert.Equal(t, vTest, v) }) - t.Run("with invalid variable ID", func(t *testing.T) { + t.Run(testWithInvalidVariableID, func(t *testing.T) { _, err := client.Variables.Update(ctx, badIdentifier, vTest.ID, VariableUpdateOptions{}) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) }) - t.Run("with invalid variable ID", func(t *testing.T) { + t.Run(testWithInvalidVariableID, func(t *testing.T) { _, err := client.Variables.Update(ctx, vTest.Workspace.ID, badIdentifier, VariableUpdateOptions{}) assert.Equal(t, err, ErrInvalidVariableID) }) @@ -332,7 +334,7 @@ func TestVariablesDelete(t *testing.T) { assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) }) - t.Run("with invalid variable ID", func(t *testing.T) { + t.Run(testWithInvalidVariableID, func(t *testing.T) { err := client.Variables.Delete(ctx, wTest.ID, badIdentifier) assert.Equal(t, err, ErrInvalidVariableID) }) diff --git a/variable_set_test.go b/variable_set_test.go index 3f9d9edb6..4ef5faf87 100644 --- a/variable_set_test.go +++ b/variable_set_test.go @@ -20,20 +20,20 @@ func TestVariableSetsList(t *testing.T) { vsTest2, vsTestCleanup2 := createVariableSet(t, client, orgTest, VariableSetCreateOptions{}) defer vsTestCleanup2() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { vsl, err := client.VariableSets.List(ctx, orgTest.Name, nil) require.NoError(t, err) require.NotEmpty(t, vsl.Items) assert.Contains(t, vsl.Items, vsTest1) assert.Contains(t, vsl.Items, vsTest2) - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) assert.Equal(t, 1, vsl.CurrentPage) assert.Equal(t, 2, vsl.TotalCount) }) t.Run("with list options", func(t *testing.T) { - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) // Request a page number which is out of range. The result should // be successful, but return no results if the paging options are // properly passed along. @@ -73,7 +73,7 @@ func TestVariableSetsListForWorkspace(t *testing.T) { applyVariableSetToWorkspace(t, client, vsTest1.ID, workspaceTest.ID) applyVariableSetToWorkspace(t, client, vsTest2.ID, workspaceTest.ID) - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { vsl, err := client.VariableSets.ListForWorkspace(ctx, workspaceTest.ID, nil) require.NoError(t, err) require.Len(t, vsl.Items, 2) @@ -85,7 +85,7 @@ func TestVariableSetsListForWorkspace(t *testing.T) { }) t.Run("with list options", func(t *testing.T) { - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) // Request a page number which is out of range. The result should // be successful, but return no results if the paging options are // properly passed along. @@ -140,7 +140,7 @@ func TestVariableSetsCreate(t *testing.T) { } }) - t.Run("when options is missing name", func(t *testing.T) { + t.Run(testWhenOptionsMissingName, func(t *testing.T) { vs, err := client.VariableSets.Create(ctx, "foo", &VariableSetCreateOptions{ Global: Bool(true), }) @@ -193,7 +193,7 @@ func TestVariableSetsUpdate(t *testing.T) { Global: Bool(false), }) - t.Run("when updating a subset of values", func(t *testing.T) { + t.Run(testWhenUpdatingSubsetOfValues, func(t *testing.T) { options := VariableSetUpdateOptions{ Name: String("UpdatedName"), Description: String("Updated Description"), diff --git a/variable_set_variable_test.go b/variable_set_variable_test.go index 629b5acdd..0faf03ba6 100644 --- a/variable_set_variable_test.go +++ b/variable_set_variable_test.go @@ -31,7 +31,7 @@ func TestVariableSetVariablesList(t *testing.T) { }) defer vTestCleanup2() - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { vl, err := client.VariableSetVariables.List(ctx, vsTest.ID, nil) require.NoError(t, err) require.NotEmpty(t, vl.Items) @@ -45,7 +45,7 @@ func TestVariableSetVariablesList(t *testing.T) { }) t.Run("with list options", func(t *testing.T) { - t.Skip("paging not supported yet in API") + t.Skip(testSkipPagingNotSupportedYet) // Request a page number which is out of range. The result should // be successful, but return no results if the paging options are // properly passed along. @@ -272,7 +272,7 @@ func TestVariableSetVariablesUpdate(t *testing.T) { assert.Equal(t, *options.Value, v.Value) }) - t.Run("when updating a subset of values", func(t *testing.T) { + t.Run(testWhenUpdatingSubsetOfValues, func(t *testing.T) { options := VariableSetVariableUpdateOptions{ Key: String("someothername"), HCL: Bool(false), @@ -315,12 +315,12 @@ func TestVariableSetVariablesUpdate(t *testing.T) { assert.Equal(t, vTest, v) }) - t.Run("with invalid variable ID", func(t *testing.T) { + t.Run(testWithInvalidVariableID, func(t *testing.T) { _, err := client.VariableSetVariables.Update(ctx, badIdentifier, vTest.ID, nil) assert.EqualError(t, err, ErrInvalidVariableSetID.Error()) }) - t.Run("with invalid variable ID", func(t *testing.T) { + t.Run(testWithInvalidVariableID, func(t *testing.T) { _, err := client.VariableSetVariables.Update(ctx, vsTest.ID, badIdentifier, nil) assert.EqualError(t, err, ErrInvalidVariableID.Error()) }) @@ -350,7 +350,7 @@ func TestVariableSetVariablesDelete(t *testing.T) { assert.EqualError(t, err, ErrInvalidVariableSetID.Error()) }) - t.Run("with invalid variable ID", func(t *testing.T) { + t.Run(testWithInvalidVariableID, func(t *testing.T) { err := client.VariableSetVariables.Delete(ctx, vsTest.ID, badIdentifier) assert.EqualError(t, err, ErrInvalidVariableID.Error()) }) diff --git a/workspace_integration_test.go b/workspace_integration_test.go index 8128d0f2c..90f93f1cc 100644 --- a/workspace_integration_test.go +++ b/workspace_integration_test.go @@ -40,7 +40,7 @@ func TestWorkspacesList(t *testing.T) { wTest2, wTest2Cleanup := createWorkspace(t, client, orgTest) t.Cleanup(wTest2Cleanup) - t.Run("without list options", func(t *testing.T) { + t.Run(testWithoutListOptions, func(t *testing.T) { wl, err := client.Workspaces.List(ctx, orgTest.Name, nil) require.NoError(t, err) assert.Contains(t, wl.Items, wTest1) @@ -136,7 +136,7 @@ func TestWorkspacesList(t *testing.T) { assert.Equal(t, 0, wl.TotalCount) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { wl, err := client.Workspaces.List(ctx, badIdentifier, nil) assert.Nil(t, wl) assert.EqualError(t, err, ErrInvalidOrg.Error()) @@ -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) @@ -410,7 +411,7 @@ func TestWorkspacesCreate(t *testing.T) { } }) - t.Run("when options is missing name", func(t *testing.T) { + t.Run(testWhenOptionsMissingName, func(t *testing.T) { w, err := client.Workspaces.Create(ctx, "foo", WorkspaceCreateOptions{}) assert.Nil(t, w) assert.EqualError(t, err, ErrRequiredName.Error()) @@ -424,7 +425,7 @@ func TestWorkspacesCreate(t *testing.T) { assert.EqualError(t, err, ErrInvalidName.Error()) }) - t.Run("when options has an invalid organization", func(t *testing.T) { + t.Run(testWhenOptionsHasInvalidOrganization, func(t *testing.T) { w, err := client.Workspaces.Create(ctx, badIdentifier, WorkspaceCreateOptions{ Name: String("foo"), }) @@ -466,7 +467,7 @@ func TestWorkspacesCreate(t *testing.T) { assert.Equal(t, err, ErrRequiredAgentPoolID) }) - t.Run("when an error is returned from the API", func(t *testing.T) { + t.Run(testWhenErrorFromAPI, func(t *testing.T) { w, err := client.Workspaces.Create(ctx, "bar", WorkspaceCreateOptions{ Name: String(fmt.Sprintf("bar-%s", randomString(t))), TerraformVersion: String("nonexisting"), @@ -572,13 +573,13 @@ func TestWorkspacesRead(t *testing.T) { assert.Error(t, err) }) - t.Run("without a valid organization", func(t *testing.T) { + t.Run(testWithoutValidOrganization, func(t *testing.T) { w, err := client.Workspaces.Read(ctx, badIdentifier, wTest.Name) assert.Nil(t, w) assert.EqualError(t, err, ErrInvalidOrg.Error()) }) - t.Run("without a valid workspace", func(t *testing.T) { + t.Run(testWithoutValidWorkspace, func(t *testing.T) { w, err := client.Workspaces.Read(ctx, orgTest.Name, badIdentifier) assert.Nil(t, w) assert.EqualError(t, err, ErrInvalidWorkspaceValue.Error()) @@ -699,7 +700,7 @@ func TestWorkspacesReadReadme(t *testing.T) { assert.Error(t, err) }) - t.Run("without a valid workspace ID", func(t *testing.T) { + t.Run(testWithoutValidWorkspaceID, func(t *testing.T) { w, err := client.Workspaces.Readme(ctx, badIdentifier) assert.Nil(t, w) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) @@ -733,7 +734,7 @@ func TestWorkspacesReadByID(t *testing.T) { assert.Error(t, err) }) - t.Run("without a valid workspace ID", func(t *testing.T) { + t.Run(testWithoutValidWorkspaceID, func(t *testing.T) { w, err := client.Workspaces.ReadByID(ctx, badIdentifier) assert.Nil(t, w) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) @@ -752,7 +753,7 @@ func TestWorkspacesUpdate(t *testing.T) { wTest, wCleanup := createWorkspace(t, client, orgTest) t.Cleanup(wCleanup) - t.Run("when updating a subset of values", func(t *testing.T) { + t.Run(testWhenUpdatingSubsetOfValues, func(t *testing.T) { options := WorkspaceUpdateOptions{ Name: String(wTest.Name), AllowDestroyPlan: Bool(false), @@ -838,7 +839,7 @@ func TestWorkspacesUpdate(t *testing.T) { assert.Equal(t, err, ErrRequiredAgentPoolID) }) - t.Run("when an error is returned from the api", func(t *testing.T) { + t.Run(testWhenErrorFromAPI, func(t *testing.T) { w, err := client.Workspaces.Update(ctx, orgTest.Name, wTest.Name, WorkspaceUpdateOptions{ TerraformVersion: String("nonexisting"), }) @@ -852,7 +853,7 @@ func TestWorkspacesUpdate(t *testing.T) { assert.EqualError(t, err, ErrInvalidWorkspaceValue.Error()) }) - t.Run("when options has an invalid organization", func(t *testing.T) { + t.Run(testWhenOptionsHasInvalidOrganization, func(t *testing.T) { w, err := client.Workspaces.Update(ctx, badIdentifier, wTest.Name, WorkspaceUpdateOptions{}) assert.Nil(t, w) assert.EqualError(t, err, ErrInvalidOrg.Error()) @@ -1091,7 +1092,7 @@ func TestWorkspacesUpdateByID(t *testing.T) { wTest, wCleanup := createWorkspace(t, client, orgTest) t.Cleanup(wCleanup) - t.Run("when updating a subset of values", func(t *testing.T) { + t.Run(testWhenUpdatingSubsetOfValues, func(t *testing.T) { options := WorkspaceUpdateOptions{ Name: String(wTest.Name), AllowDestroyPlan: Bool(false), @@ -1152,7 +1153,7 @@ func TestWorkspacesUpdateByID(t *testing.T) { } }) - t.Run("when an error is returned from the api", func(t *testing.T) { + t.Run(testWhenErrorFromAPI, func(t *testing.T) { w, err := client.Workspaces.UpdateByID(ctx, wTest.ID, WorkspaceUpdateOptions{ TerraformVersion: String("nonexisting"), }) @@ -1160,7 +1161,7 @@ func TestWorkspacesUpdateByID(t *testing.T) { assert.Error(t, err) }) - t.Run("without a valid workspace ID", func(t *testing.T) { + t.Run(testWithoutValidWorkspaceID, func(t *testing.T) { w, err := client.Workspaces.UpdateByID(ctx, badIdentifier, WorkspaceUpdateOptions{}) assert.Nil(t, w) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) @@ -1216,7 +1217,7 @@ func TestWorkspacesDeleteByID(t *testing.T) { assert.Equal(t, ErrResourceNotFound, err) }) - t.Run("without a valid workspace ID", func(t *testing.T) { + t.Run(testWithoutValidWorkspaceID, func(t *testing.T) { err := client.Workspaces.DeleteByID(ctx, badIdentifier) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) }) @@ -1315,7 +1316,7 @@ func TestWorkspacesSafeDeleteByID(t *testing.T) { assert.Equal(t, ErrResourceNotFound, err) }) - t.Run("without a valid workspace ID", func(t *testing.T) { + t.Run(testWithoutValidWorkspaceID, func(t *testing.T) { err := client.Workspaces.SafeDeleteByID(ctx, badIdentifier) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) }) @@ -1400,7 +1401,7 @@ func TestWorkspacesLock(t *testing.T) { assert.Equal(t, ErrWorkspaceLocked, err) }) - t.Run("without a valid workspace ID", func(t *testing.T) { + t.Run(testWithoutValidWorkspaceID, func(t *testing.T) { w, err := client.Workspaces.Lock(ctx, badIdentifier, WorkspaceLockOptions{}) assert.Nil(t, w) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) @@ -1449,7 +1450,7 @@ func TestWorkspacesUnlock(t *testing.T) { assert.Equal(t, ErrWorkspaceLockedByRun, err) }) - t.Run("without a valid workspace ID", func(t *testing.T) { + t.Run(testWithoutValidWorkspaceID, func(t *testing.T) { w, err := client.Workspaces.Unlock(ctx, badIdentifier) assert.Nil(t, w) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) @@ -1484,7 +1485,7 @@ func TestWorkspacesForceUnlock(t *testing.T) { assert.Equal(t, ErrWorkspaceNotLocked, err) }) - t.Run("without a valid workspace ID", func(t *testing.T) { + t.Run(testWithoutValidWorkspaceID, func(t *testing.T) { w, err := client.Workspaces.ForceUnlock(ctx, badIdentifier) assert.Nil(t, w) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) @@ -1527,7 +1528,7 @@ func TestWorkspacesAssignSSHKey(t *testing.T) { assert.Equal(t, err, ErrInvalidSHHKeyID) }) - t.Run("without a valid workspace ID", func(t *testing.T) { + t.Run(testWithoutValidWorkspaceID, func(t *testing.T) { w, err := client.Workspaces.AssignSSHKey(ctx, badIdentifier, WorkspaceAssignSSHKeyOptions{ SSHKeyID: String(sshKeyTest.ID), }) @@ -1565,7 +1566,7 @@ func TestWorkspacesUnassignSSHKey(t *testing.T) { assert.Nil(t, w.SSHKey) }) - t.Run("without a valid workspace ID", func(t *testing.T) { + t.Run(testWithoutValidWorkspaceID, func(t *testing.T) { w, err := client.Workspaces.UnassignSSHKey(ctx, badIdentifier) assert.Nil(t, w) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) @@ -1610,7 +1611,7 @@ func TestWorkspaces_AddRemoteStateConsumers(t *testing.T) { assert.Contains(t, rsc.Items, wTestConsumer2) }) - t.Run("with invalid options", func(t *testing.T) { + t.Run(testWithInvalidOptions, func(t *testing.T) { err := client.Workspaces.AddRemoteStateConsumers(ctx, wTest.ID, WorkspaceAddRemoteStateConsumersOptions{}) require.Error(t, err) assert.EqualError(t, err, ErrWorkspacesRequired.Error()) @@ -1622,7 +1623,7 @@ func TestWorkspaces_AddRemoteStateConsumers(t *testing.T) { assert.EqualError(t, err, ErrWorkspaceMinLimit.Error()) }) - t.Run("without a valid workspace ID", func(t *testing.T) { + t.Run(testWithoutValidWorkspaceID, func(t *testing.T) { err := client.Workspaces.AddRemoteStateConsumers(ctx, badIdentifier, WorkspaceAddRemoteStateConsumersOptions{}) require.Error(t, err) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) @@ -1686,7 +1687,7 @@ func TestWorkspaces_RemoveRemoteStateConsumers(t *testing.T) { assert.Empty(t, len(rsc.Items)) }) - t.Run("with invalid options", func(t *testing.T) { + t.Run(testWithInvalidOptions, func(t *testing.T) { err := client.Workspaces.RemoveRemoteStateConsumers(ctx, wTest.ID, WorkspaceRemoveRemoteStateConsumersOptions{}) require.Error(t, err) assert.EqualError(t, err, ErrWorkspacesRequired.Error()) @@ -1698,7 +1699,7 @@ func TestWorkspaces_RemoveRemoteStateConsumers(t *testing.T) { assert.EqualError(t, err, ErrWorkspaceMinLimit.Error()) }) - t.Run("without a valid workspace ID", func(t *testing.T) { + t.Run(testWithoutValidWorkspaceID, func(t *testing.T) { err := client.Workspaces.RemoveRemoteStateConsumers(ctx, badIdentifier, WorkspaceRemoveRemoteStateConsumersOptions{}) require.Error(t, err) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) @@ -1747,10 +1748,9 @@ 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) { + t.Run(testWithInvalidOptions, func(t *testing.T) { err := client.Workspaces.UpdateRemoteStateConsumers(ctx, wTest.ID, WorkspaceUpdateRemoteStateConsumersOptions{}) require.Error(t, err) assert.EqualError(t, err, ErrWorkspacesRequired.Error()) @@ -1762,7 +1762,7 @@ func TestWorkspaces_UpdateRemoteStateConsumers(t *testing.T) { assert.EqualError(t, err, ErrWorkspaceMinLimit.Error()) }) - t.Run("without a valid workspace ID", func(t *testing.T) { + t.Run(testWithoutValidWorkspaceID, func(t *testing.T) { err := client.Workspaces.UpdateRemoteStateConsumers(ctx, badIdentifier, WorkspaceUpdateRemoteStateConsumersOptions{}) require.Error(t, err) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) @@ -1866,7 +1866,7 @@ func TestWorkspaces_AddTags(t *testing.T) { assert.Equal(t, wt.Items[4].Name, "tagbyid") }) - t.Run("with invalid options", func(t *testing.T) { + t.Run(testWithInvalidOptions, func(t *testing.T) { err := client.Workspaces.AddTags(ctx, wTest.ID, WorkspaceAddTagsOptions{ Tags: []*Tag{}, }) @@ -1874,7 +1874,7 @@ func TestWorkspaces_AddTags(t *testing.T) { assert.EqualError(t, err, ErrMissingTagIdentifier.Error()) }) - t.Run("without a valid workspace ID", func(t *testing.T) { + t.Run(testWithoutValidWorkspaceID, func(t *testing.T) { err := client.Workspaces.AddTags(ctx, badIdentifier, WorkspaceAddTagsOptions{}) require.Error(t, err) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) @@ -1943,7 +1943,7 @@ func TestWorkspaces_RemoveTags(t *testing.T) { require.NoError(t, err) }) - t.Run("with invalid options", func(t *testing.T) { + t.Run(testWithInvalidOptions, func(t *testing.T) { err := client.Workspaces.RemoveTags(ctx, wTest.ID, WorkspaceRemoveTagsOptions{ Tags: []*Tag{}, }) @@ -1951,7 +1951,7 @@ func TestWorkspaces_RemoveTags(t *testing.T) { assert.EqualError(t, err, ErrMissingTagIdentifier.Error()) }) - t.Run("without a valid workspace ID", func(t *testing.T) { + t.Run(testWithoutValidWorkspaceID, func(t *testing.T) { err := client.Workspaces.RemoveTags(ctx, badIdentifier, WorkspaceRemoveTagsOptions{}) require.Error(t, err) assert.EqualError(t, err, ErrInvalidWorkspaceID.Error()) @@ -2000,7 +2000,10 @@ 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") + if err != nil { + t.Error(err) + } assert.Equal(t, ws.ID, "ws-1234") assert.Equal(t, ws.Name, "my-workspace") 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)