-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
109 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,70 @@ | ||
package actions | ||
|
||
import ( | ||
"errors" | ||
"github.com/stretchr/testify/require" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestSecureString(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input string | ||
err error | ||
envVarToSet map[string]string | ||
expectedOut SecureString | ||
}{ | ||
{ | ||
name: "No env var", | ||
input: "this is just a string", | ||
expectedOut: SecureString{val: "this is just a string", secret: false}, | ||
}, | ||
{ | ||
name: "simple env var", | ||
input: "{{ ENV.SIMPLE_FIRST }}", | ||
envVarToSet: map[string]string{"SIMPLE_FIRST": "some value"}, | ||
expectedOut: SecureString{val: "some value", secret: true}, | ||
}, | ||
{ | ||
name: "no spaces env var", | ||
input: "{{ENV.NO_SPACES_FIRST}}", | ||
envVarToSet: map[string]string{"NO_SPACES_FIRST": "this is some value"}, | ||
expectedOut: SecureString{val: "this is some value", secret: true}, | ||
}, | ||
{ | ||
name: "wrapped with text", | ||
input: "this {{ ENV.WRAPPED_FIRST }} value", | ||
envVarToSet: map[string]string{"WRAPPED_FIRST": "is another"}, | ||
expectedOut: SecureString{val: "this is another value", secret: true}, | ||
}, | ||
{ | ||
name: "multiple vars and text", | ||
input: "let me count: {{ ENV.MULTIPLE_FIRST }}, {{ENV.MULTIPLE_SECOND}}, {{ ENV.MULTIPLE_THIRD }}", | ||
envVarToSet: map[string]string{"MULTIPLE_FIRST": "one", "MULTIPLE_SECOND": "two", "MULTIPLE_THIRD": "three"}, | ||
expectedOut: SecureString{val: "let me count: one, two, three", secret: true}, | ||
}, | ||
{ | ||
name: "missing env var", | ||
input: "{{ ENV.MISSING_FIRST }}", | ||
envVarToSet: map[string]string{"SIMPLE_FIRST": "some value"}, | ||
expectedOut: SecureString{}, | ||
err: errMissingEnvVar, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
for k, v := range tt.envVarToSet { | ||
require.NoError(t, os.Setenv(k, v)) | ||
} | ||
|
||
out, err := NewSecureString(tt.input) | ||
if tt.err == nil { | ||
require.Nil(t, err) | ||
} else { | ||
require.True(t, errors.Is(err, tt.err)) | ||
} | ||
require.Equal(t, tt.expectedOut, out) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters