This repository has been archived by the owner on May 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
bde6231
commit 9613b31
Showing
1 changed file
with
37 additions
and
0 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,37 @@ | ||
package configs | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/spf13/viper" | ||
) | ||
|
||
func TestUnsetViperConfig(t *testing.T) { | ||
viper.SetConfigFile("./../testdata/.viper.yaml") | ||
keys := []string{"key1", "key2", "key3", "key4", "key5"} | ||
for _, v := range keys { | ||
viper.Set(v, v) | ||
} | ||
type args struct { | ||
keys []string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantErr bool | ||
}{ | ||
{"Test Case", args{keys: keys}, false}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := UnsetViperConfig(tt.args.keys...); (err != nil) != tt.wantErr { | ||
t.Errorf("UnsetViperConfig() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
for _, v := range keys { | ||
if viper.GetString(v) != "" { | ||
t.Errorf("UnsetViperConfig() Expected viper key %s to be empty", v) | ||
} | ||
} | ||
}) | ||
} | ||
} |