Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix make lint #596

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions admin_run_integration_test.go
Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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)
})
Expand Down Expand Up @@ -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,
},
},
},
Expand All @@ -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{}
Expand Down
4 changes: 2 additions & 2 deletions admin_setting_cost_estimation_integration_test.go
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions admin_setting_saml_integration_test.go
Expand Up @@ -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),
})
Expand Down
8 changes: 4 additions & 4 deletions admin_terraform_version_integration_test.go
Expand Up @@ -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)

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"),
Expand Down
3 changes: 1 addition & 2 deletions admin_user_integration_test.go
Expand Up @@ -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)

Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions admin_workspace_integration_test.go
Expand Up @@ -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)

Expand Down Expand Up @@ -130,15 +130,15 @@ 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)
assert.EqualError(t, err, ErrResourceNotFound.Error())
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()

Expand Down
10 changes: 6 additions & 4 deletions agent_pool_integration_test.go
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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,
})
Expand Down Expand Up @@ -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())
Expand Down
10 changes: 6 additions & 4 deletions apply_integration_test.go
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
},
},
},
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions configuration_version.go
Expand Up @@ -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
}
Expand Down
24 changes: 13 additions & 11 deletions configuration_version_integration_test.go
Expand Up @@ -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()
Expand All @@ -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)

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)

Expand All @@ -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)
})
Expand Down Expand Up @@ -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)

Expand All @@ -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()
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
},
},
},
Expand All @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions cost_estimate_integration_test.go
Expand Up @@ -70,18 +70,18 @@ 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,
},
},
},
}
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)
Expand Down
2 changes: 1 addition & 1 deletion errors.go
Expand Up @@ -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")

Expand Down