-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vault provider tests): Add more tests, and minor fixes
Signed-off-by: Bence Csati <[email protected]>
- Loading branch information
Showing
8 changed files
with
118 additions
and
52 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
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package vault | ||
|
||
import ( | ||
"bytes" | ||
"log/slog" | ||
"os" | ||
"testing" | ||
|
||
"github.com/bank-vaults/internal/injector" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewProvider(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
config *Config | ||
wantInjectorConfig injector.Config | ||
wantErr bool | ||
wantType bool | ||
}{ | ||
{ | ||
name: "Valid Provider with Token", | ||
config: &Config{ | ||
Islogin: true, | ||
TokenFile: "root", | ||
Token: "root", | ||
TransitKeyID: "test-key", | ||
TransitPath: "transit", | ||
TransitBatchSize: 10, | ||
DaemonMode: true, | ||
IgnoreMissingSecrets: true, | ||
FromPath: "secret/data/test", | ||
RevokeToken: true, | ||
}, | ||
wantErr: false, | ||
wantType: true, | ||
}, | ||
{ | ||
name: "Fail to create vault client", | ||
config: &Config{}, | ||
wantErr: true, | ||
wantType: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
ttp := tt | ||
|
||
// Redirect logs to avoid polluting the test output | ||
var buf bytes.Buffer | ||
handler := slog.NewTextHandler(&buf, nil) | ||
logger := slog.New(handler) | ||
|
||
t.Run(ttp.name, func(t *testing.T) { | ||
provider, err := NewProvider(ttp.config, logger, make(chan os.Signal)) | ||
|
||
assert.Equal(t, ttp.wantErr, err != nil, "Unexpected error status") | ||
assert.Equal(t, ttp.wantType, provider != nil, "Unexpected provider type") | ||
}) | ||
|
||
buf.Truncate(0) | ||
} | ||
|
||
} |