mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-08 14:21:18 +00:00
Merge pull request #7443 from ywk253100/240219_credential
Don't return error when no credential file found
This commit is contained in:
@@ -62,6 +62,10 @@ func LoadCredentials(config map[string]string) (map[string]string, error) {
|
||||
credFile = config[credentialFile]
|
||||
}
|
||||
|
||||
if len(credFile) == 0 {
|
||||
return map[string]string{}, nil
|
||||
}
|
||||
|
||||
// put the credential file content into a map
|
||||
creds, err := godotenv.Read(credFile)
|
||||
if err != nil {
|
||||
|
||||
@@ -28,8 +28,9 @@ import (
|
||||
|
||||
func TestLoadCredentials(t *testing.T) {
|
||||
// no credential file
|
||||
_, err := LoadCredentials(nil)
|
||||
require.NotNil(t, err)
|
||||
credentials, err := LoadCredentials(nil)
|
||||
require.Nil(t, err)
|
||||
assert.NotNil(t, credentials)
|
||||
|
||||
// specified credential file in the config
|
||||
name := filepath.Join(os.TempDir(), "credential")
|
||||
@@ -43,7 +44,7 @@ func TestLoadCredentials(t *testing.T) {
|
||||
config := map[string]string{
|
||||
"credentialsFile": name,
|
||||
}
|
||||
credentials, err := LoadCredentials(config)
|
||||
credentials, err = LoadCredentials(config)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "value", credentials["key"])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user