Skip to content

Commit

Permalink
fix env var output (#1507)
Browse files Browse the repository at this point in the history
* fix env var output

* add test
  • Loading branch information
sunkickr committed Feb 2, 2024
1 parent 104a2a3 commit a7d9c31
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cloud/deployment/deployment_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ func VariableModify(deploymentID, variableKey, variableValue, ws, envFile, deplo
var index int
for i := range environmentVariablesObjects {
index = i + 1
varTab.AddRow([]string{strconv.Itoa(index), environmentVariablesObjects[i].Key, *environmentVariablesObjects[i].Value, strconv.FormatBool(environmentVariablesObjects[i].IsSecret)}, false)
printValue := notApplicable
if environmentVariablesObjects[i].Value != nil {
printValue = *environmentVariablesObjects[i].Value
}
varTab.AddRow([]string{strconv.Itoa(index), environmentVariablesObjects[i].Key, printValue, strconv.FormatBool(environmentVariablesObjects[i].IsSecret)}, false)
}

if index == 0 {
Expand Down
30 changes: 30 additions & 0 deletions cloud/deployment/deployment_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,36 @@ func TestVariableModify(t *testing.T) {
mockPlatformCoreClient.AssertExpectations(t)
})

t.Run("success with secret value", func(t *testing.T) {
mockCoreClient.On("GetDeploymentOptionsWithResponse", mock.Anything, mock.Anything, mock.Anything).Return(&GetDeploymentOptionsResponseOK, nil).Times(1)
mockPlatformCoreClient.On("UpdateDeploymentWithResponse", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&mockUpdateDeploymentResponse, nil).Times(1)
mockPlatformCoreClient.On("ListDeploymentsWithResponse", mock.Anything, mock.Anything, mock.Anything).Return(&mockListDeploymentsResponse, nil).Times(2)
mockPlatformCoreClient.On("GetDeploymentWithResponse", mock.Anything, mock.Anything, mock.Anything).Return(&deploymentResponse, nil).Times(3)
mockPlatformCoreClient.On("GetClusterWithResponse", mock.Anything, mock.Anything, mock.Anything).Return(&mockGetClusterResponse, nil).Once()

deploymentResponse.JSON200.EnvironmentVariables = &[]astroplatformcore.DeploymentEnvironmentVariable{
{
Key: "test-key-1",
Value: nil,
IsSecret: true,
},
{
Key: "test-key-2",
Value: nil,
IsSecret: true,
},
}

buf := new(bytes.Buffer)
err := VariableModify("test-id-1", "test-key-2", "test-value-2", ws, "", "", []string{}, false, false, false, mockCoreClient, mockPlatformCoreClient, buf)
assert.NoError(t, err)
assert.Contains(t, buf.String(), "test-key-1")
assert.Contains(t, buf.String(), "test-key-2")
assert.Contains(t, buf.String(), "N/A")
mockCoreClient.AssertExpectations(t)
mockPlatformCoreClient.AssertExpectations(t)
})

t.Run("list deployment failure", func(t *testing.T) {
mockPlatformCoreClient.On("ListDeploymentsWithResponse", mock.Anything, mock.Anything, mock.Anything).Return(&mockListDeploymentsResponse, errMock).Times(1)

Expand Down

0 comments on commit a7d9c31

Please sign in to comment.