mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
ffc931aad1
* Added unit tag as argument. Added description to runTests command. Changed code generator to have unit build tag in generated unit test files. * Added unit build tag to all unit test files. * added to new unit test unit build tag * Update verify-go.yml * small fix --------- Co-authored-by: Muhammadali Nazarov <Muhammadali.Nazarov@acronis.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
//go:build unit
|
|
// +build unit
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type mockVaultRotateSecretIDUtilsBundle struct {
|
|
t *testing.T
|
|
newSecret string
|
|
ttl time.Duration
|
|
config *vaultRotateSecretIdOptions
|
|
updateFuncCalled bool
|
|
}
|
|
|
|
func TestRunVaultRotateSecretId(t *testing.T) {
|
|
t.Parallel()
|
|
mock := &mockVaultRotateSecretIDUtilsBundle{t, "test-secret", time.Hour, getTestConfig(), false}
|
|
runVaultRotateSecretID(mock)
|
|
assert.True(t, mock.updateFuncCalled)
|
|
|
|
}
|
|
|
|
func (v *mockVaultRotateSecretIDUtilsBundle) GenerateNewAppRoleSecret(secretID string, roleName string) (string, error) {
|
|
return v.newSecret, nil
|
|
}
|
|
|
|
func (v *mockVaultRotateSecretIDUtilsBundle) GetAppRoleSecretIDTtl(secretID, roleName string) (time.Duration, error) {
|
|
return v.ttl, nil
|
|
}
|
|
func (v *mockVaultRotateSecretIDUtilsBundle) GetAppRoleName() (string, error) {
|
|
return "test", nil
|
|
}
|
|
func (v *mockVaultRotateSecretIDUtilsBundle) UpdateSecretInStore(config *vaultRotateSecretIdOptions, secretID string) error {
|
|
v.updateFuncCalled = true
|
|
assert.Equal(v.t, v.newSecret, secretID)
|
|
return nil
|
|
}
|
|
func (v *mockVaultRotateSecretIDUtilsBundle) GetConfig() *vaultRotateSecretIdOptions {
|
|
return v.config
|
|
}
|
|
|
|
func getTestConfig() *vaultRotateSecretIdOptions {
|
|
return &vaultRotateSecretIdOptions{
|
|
DaysBeforeExpiry: 5,
|
|
}
|
|
}
|