From a224de15c8c208282c9dcf352c6e58f166b50127 Mon Sep 17 00:00:00 2001 From: Eamonn Mansour <47121388+eamansour@users.noreply.github.com> Date: Thu, 31 Oct 2024 12:07:13 +0000 Subject: [PATCH] fix: Move description to the last column in secrets get Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com> --- pkg/secrets/secretsGet_test.go | 10 ++-- pkg/secretsformatter/summaryFormatter.go | 26 +++++----- pkg/secretsformatter/summaryFormatter_test.go | 50 +++++++++---------- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/pkg/secrets/secretsGet_test.go b/pkg/secrets/secretsGet_test.go index a33c1fc1..8ce3ec11 100644 --- a/pkg/secrets/secretsGet_test.go +++ b/pkg/secrets/secretsGet_test.go @@ -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 ` @@ -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 ` diff --git a/pkg/secretsformatter/summaryFormatter.go b/pkg/secretsformatter/summaryFormatter.go index 4007b19a..23437731 100644 --- a/pkg/secretsformatter/summaryFormatter.go +++ b/pkg/secretsformatter/summaryFormatter.go @@ -39,12 +39,12 @@ 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 { @@ -52,15 +52,15 @@ func (*SecretSummaryFormatter) FormatSecrets(secrets []galasaapi.GalasaSecret) ( 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) } diff --git a/pkg/secretsformatter/summaryFormatter_test.go b/pkg/secretsformatter/summaryFormatter_test.go index a04c257e..6debbe8f 100644 --- a/pkg/secretsformatter/summaryFormatter_test.go +++ b/pkg/secretsformatter/summaryFormatter_test.go @@ -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 ( @@ -21,8 +21,8 @@ const ( ) func createMockGalasaSecretWithDescription( - secretName string, - description string, + secretName string, + description string, ) galasaapi.GalasaSecret { secret := *galasaapi.NewGalasaSecret() @@ -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) @@ -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 } @@ -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 ` @@ -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) @@ -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 `