Skip to content

Commit

Permalink
fix: Move description to the last column in secrets get
Browse files Browse the repository at this point in the history
Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com>
  • Loading branch information
eamansour committed Oct 31, 2024
1 parent 54bb55a commit a224de1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 43 deletions.
10 changes: 5 additions & 5 deletions pkg/secrets/secretsGet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ func TestCanGetASecretByName(t *testing.T) {

// Then...
expectedOutput :=
`name type description last-updated(UTC) last-updated-by
SYSTEM1 UsernamePassword my SYSTEM1 secret 2024-01-01 10:00:00 dummy-username
`name type last-updated(UTC) last-updated-by description
SYSTEM1 UsernamePassword 2024-01-01 10:00:00 dummy-username my SYSTEM1 secret
Total:1
`
Expand Down Expand Up @@ -211,9 +211,9 @@ func TestCanGetAllSecretsOk(t *testing.T) {

// Then...
expectedOutput :=
`name type description last-updated(UTC) last-updated-by
BOB UsernamePassword my BOB secret 2024-01-01 10:00:00 dummy-username
BLAH UsernamePassword my BLAH secret 2024-01-01 10:00:00 dummy-username
`name type last-updated(UTC) last-updated-by description
BOB UsernamePassword 2024-01-01 10:00:00 dummy-username my BOB secret
BLAH UsernamePassword 2024-01-01 10:00:00 dummy-username my BLAH secret
Total:2
`
Expand Down
26 changes: 13 additions & 13 deletions pkg/secretsformatter/summaryFormatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,28 @@ func (*SecretSummaryFormatter) FormatSecrets(secrets []galasaapi.GalasaSecret) (
var table [][]string

var headers = []string{
HEADER_SECRET_NAME,
HEADER_SECRET_TYPE,
HEADER_SECRET_DESCRIPTION,
HEADER_LAST_UPDATED_TIME,
HEADER_LAST_UPDATED_BY,
}
HEADER_SECRET_NAME,
HEADER_SECRET_TYPE,
HEADER_LAST_UPDATED_TIME,
HEADER_LAST_UPDATED_BY,
HEADER_SECRET_DESCRIPTION,
}

table = append(table, headers)
for _, secret := range secrets {
var line []string
name := secret.Metadata.GetName()
secretType := secret.Metadata.GetType()
secretDescription := secret.Metadata.GetDescription()
lastUpdatedTime := secret.Metadata.GetLastUpdatedTime()
lastUpdatedTime := secret.Metadata.GetLastUpdatedTime()

lastUpdatedTimeReadable := ""
if !lastUpdatedTime.IsZero() {
lastUpdatedTimeReadable = lastUpdatedTime.Format("2006-01-02 15:04:05")
}
lastUpdatedBy := secret.Metadata.GetLastUpdatedBy()
lastUpdatedTimeReadable := ""
if !lastUpdatedTime.IsZero() {
lastUpdatedTimeReadable = lastUpdatedTime.Format("2006-01-02 15:04:05")
}
lastUpdatedBy := secret.Metadata.GetLastUpdatedBy()

line = append(line, name, string(secretType), secretDescription, lastUpdatedTimeReadable, lastUpdatedBy)
line = append(line, name, string(secretType), lastUpdatedTimeReadable, lastUpdatedBy, secretDescription)
table = append(table, line)
}

Expand Down
50 changes: 25 additions & 25 deletions pkg/secretsformatter/summaryFormatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
package secretsformatter

import (
"testing"
"time"
"testing"
"time"

"github.com/galasa-dev/cli/pkg/galasaapi"
"github.com/stretchr/testify/assert"
"github.com/galasa-dev/cli/pkg/galasaapi"
"github.com/stretchr/testify/assert"
)

const (
Expand All @@ -21,8 +21,8 @@ const (
)

func createMockGalasaSecretWithDescription(
secretName string,
description string,
secretName string,
description string,
) galasaapi.GalasaSecret {
secret := *galasaapi.NewGalasaSecret()

Expand All @@ -33,12 +33,12 @@ func createMockGalasaSecretWithDescription(
secretMetadata.SetName(secretName)
secretMetadata.SetEncoding(DUMMY_ENCODING)
secretMetadata.SetType("UsernamePassword")
secretMetadata.SetLastUpdatedBy(DUMMY_USERNAME)
secretMetadata.SetLastUpdatedTime(time.Date(2024, 01, 01, 10, 0, 0, 0, time.UTC))
secretMetadata.SetLastUpdatedBy(DUMMY_USERNAME)
secretMetadata.SetLastUpdatedTime(time.Date(2024, 01, 01, 10, 0, 0, 0, time.UTC))

if description != "" {
secretMetadata.SetDescription(description)
}
if description != "" {
secretMetadata.SetDescription(description)
}

secretData := *galasaapi.NewGalasaSecretData()
secretData.SetUsername(DUMMY_USERNAME)
Expand Down Expand Up @@ -66,8 +66,8 @@ func TestSecretSummaryFormatterNoDataReturnsTotalCountAllZeros(t *testing.T) {
func TestSecretSummaryFormatterSingleDataReturnsCorrectly(t *testing.T) {
// Given...
formatter := NewSecretSummaryFormatter()
description := "secret for system1"
secretName := "MYSECRET"
description := "secret for system1"
secretName := "MYSECRET"
secret1 := createMockGalasaSecretWithDescription(secretName, description)
secrets := []galasaapi.GalasaSecret{ secret1 }

Expand All @@ -77,8 +77,8 @@ func TestSecretSummaryFormatterSingleDataReturnsCorrectly(t *testing.T) {
// Then...
assert.Nil(t, err)
expectedFormattedOutput :=
`name type description last-updated(UTC) last-updated-by
MYSECRET UsernamePassword secret for system1 2024-01-01 10:00:00 dummy-username
`name type last-updated(UTC) last-updated-by description
MYSECRET UsernamePassword 2024-01-01 10:00:00 dummy-username secret for system1
Total:1
`
Expand All @@ -90,12 +90,12 @@ func TestSecretSummaryFormatterMultipleDataSeperatesWithNewLine(t *testing.T) {
formatter := NewSecretSummaryFormatter()
secrets := make([]galasaapi.GalasaSecret, 0)

secret1Name := "SECRET1"
secret1Description := "my first secret"
secret2Name := "SECRET2"
secret2Description := "my second secret"
secret3Name := "SECRET3"
secret3Description := "my third secret"
secret1Name := "SECRET1"
secret1Description := "my first secret"
secret2Name := "SECRET2"
secret2Description := "my second secret"
secret3Name := "SECRET3"
secret3Description := "my third secret"

secret1 := createMockGalasaSecretWithDescription(secret1Name, secret1Description)
secret2 := createMockGalasaSecretWithDescription(secret2Name, secret2Description)
Expand All @@ -108,10 +108,10 @@ func TestSecretSummaryFormatterMultipleDataSeperatesWithNewLine(t *testing.T) {
// Then...
assert.Nil(t, err)
expectedFormattedOutput :=
`name type description last-updated(UTC) last-updated-by
SECRET1 UsernamePassword my first secret 2024-01-01 10:00:00 dummy-username
SECRET2 UsernamePassword my second secret 2024-01-01 10:00:00 dummy-username
SECRET3 UsernamePassword my third secret 2024-01-01 10:00:00 dummy-username
`name type last-updated(UTC) last-updated-by description
SECRET1 UsernamePassword 2024-01-01 10:00:00 dummy-username my first secret
SECRET2 UsernamePassword 2024-01-01 10:00:00 dummy-username my second secret
SECRET3 UsernamePassword 2024-01-01 10:00:00 dummy-username my third secret
Total:3
`
Expand Down

0 comments on commit a224de1

Please sign in to comment.