-
Notifications
You must be signed in to change notification settings - Fork 0
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
Mads Schou-Andreasen
committed
Mar 4, 2021
1 parent
a36aac0
commit 7a27e46
Showing
7 changed files
with
200 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FALLBACK_IDENTIFIER=VALUE | ||
BOTH_IDENTIFIER=ENV |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
test: | ||
go test -race ./... | ||
|
||
test.cover: | ||
go test -race -coverprofile=coverage.out ./... | ||
#go tool cover -func=coverage.out | ||
go tool cover -html=coverage.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package gcpsecretfetch | ||
|
||
import ( | ||
"fmt" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
const GCP_PROJECT = "ob-playground" | ||
|
||
func TestInitializeConfig(t *testing.T) { | ||
|
||
type config struct { | ||
SECRET_IDENTIFIER string | ||
FALLBACK_IDENTIFIER string | ||
} | ||
|
||
var cfg config | ||
|
||
err := InitializeConfig(&cfg, GCP_PROJECT, PRIORITIZE) | ||
assert.NoError(t, err) | ||
assert.Equal(t, cfg.FALLBACK_IDENTIFIER, "VALUE") | ||
assert.Equal(t, cfg.SECRET_IDENTIFIER, "SECRET_VALUE") | ||
|
||
} | ||
|
||
func TestMissingSecret(t *testing.T) { | ||
|
||
type config struct { | ||
MISSING_SECRET string | ||
} | ||
|
||
var cfg config | ||
|
||
err := InitializeConfig(&cfg, GCP_PROJECT, PRIORITIZE) | ||
assert.Error(t, err) | ||
|
||
} | ||
|
||
func TestInitializeConfigMissing(t *testing.T) { | ||
|
||
type config struct { | ||
SECRET_IDENTIFIER string | ||
FALLBACK_IDENTIFIER string | ||
} | ||
|
||
var cfg config | ||
|
||
err := InitializeConfig(&cfg, GCP_PROJECT, DISABLE) | ||
assert.Error(t, err) | ||
|
||
} | ||
|
||
func TestInitializeConfigEnvPrioritize(t *testing.T) { | ||
|
||
type config struct { | ||
BOTH_IDENTIFIER string | ||
} | ||
|
||
var cfg config | ||
|
||
err := InitializeConfig(&cfg, GCP_PROJECT, PRIORITIZE) | ||
assert.NoError(t, err) | ||
assert.Equal(t, cfg.BOTH_IDENTIFIER, "ENV") | ||
|
||
err = InitializeConfig(&cfg, GCP_PROJECT, FALLBACK) | ||
assert.NoError(t, err) | ||
assert.Equal(t, cfg.BOTH_IDENTIFIER, "GCP") | ||
|
||
} | ||
|
||
func TestSetSecrets(t *testing.T) { | ||
|
||
err := UpdateSecrets(GCP_PROJECT, map[string]string{"SECRET_IDENTIFIER": "SECRET_VALUE", "BOTH_IDENTIFIER": "GCP"}, true) | ||
assert.NoError(t, err) | ||
|
||
} | ||
|
||
func TestBadProjectUpdate(t *testing.T) { | ||
|
||
err := UpdateSecrets("bad-project-name-alkdjwopiunhauwihd", map[string]string{"SECRET_IDENTIFIER": "SECRET_VALUE", "BOTH_IDENTIFIER": "GCP"}, true) | ||
assert.Error(t, err) | ||
|
||
} | ||
|
||
func TestBadProjectInitialize(t *testing.T) { | ||
|
||
type config struct { | ||
BOTH_IDENTIFIER string | ||
} | ||
|
||
var cfg config | ||
|
||
err := InitializeConfig(&cfg, "aawdwadawdawdwaawdawdawdawd", DISABLE) | ||
assert.Error(t, err) | ||
fmt.Println(cfg) | ||
} | ||
|
||
func TestNotAPointer(t *testing.T) { | ||
|
||
type config struct { | ||
BOTH_IDENTIFIER string | ||
} | ||
var cfg config | ||
err := InitializeConfig(cfg, "bad-project-name-alkdjwopiunhauwihd", FALLBACK) | ||
assert.Error(t, err) | ||
|
||
} | ||
|
||
func TestNotAStruct(t *testing.T) { | ||
|
||
err := InitializeConfig("cfg", "bad-project-name-alkdjwopiunhauwihd", FALLBACK) | ||
assert.Error(t, err) | ||
|
||
} | ||
|
||
func TestStructWithNonStringField(t *testing.T) { | ||
|
||
type config struct { | ||
BOTH_IDENTIFIER string | ||
INTFIELD int | ||
} | ||
var cfg config | ||
err := InitializeConfig(cfg, "bad-project-name-alkdjwopiunhauwihd", FALLBACK) | ||
assert.Error(t, err) | ||
|
||
} |
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