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.
test: add unit tests for util package
- Loading branch information
1 parent
4e25252
commit 35a4288
Showing
1 changed file
with
76 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,76 @@ | ||
package utils | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestParseStringToActualValueType(t *testing.T) { | ||
type args struct { | ||
input string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want interface{} | ||
}{ | ||
{`Test \"true\" to true boolean conversion`, args{input: "true"}, true}, | ||
{`Test \"1\" to 1 int conversion`, args{input: "1"}, 1}, | ||
{`Test \"1.5\" to 1.5 int conversion`, args{input: "1.5"}, 1.5}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := ParseStringToActualValueType(tt.args.input); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("ParseStringToActualValueType() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestPasswordGenerator(t *testing.T) { | ||
type args struct { | ||
passwordLength int | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want int | ||
}{ | ||
{"Generate an 8 Char Password", args{passwordLength: 8}, 8}, | ||
{"Generate an 10 Char Password", args{passwordLength: 10}, 10}, | ||
{"Generate an 12 Char Password", args{passwordLength: 12}, 12}, | ||
{"Generate an 16 Char Password", args{passwordLength: 16}, 16}, | ||
{"Generate an 100 Char Password", args{passwordLength: 100}, 100}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := PasswordGenerator(tt.args.passwordLength); len(got) != tt.want { | ||
t.Errorf("PasswordGenerator() Length = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestProcessCustomClaimInput(t *testing.T) { | ||
type args struct { | ||
input map[string]string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want map[string]interface{} | ||
}{ | ||
{"Custom Claims Str to Interface 1 (String)", args{input: map[string]string{"hello": "world"}}, map[string]interface{}{"hello": "world"}}, | ||
{"Custom Claims Str to Interface 2 (Boolean)", args{input: map[string]string{"hello": "true"}}, map[string]interface{}{"hello": true}}, | ||
{"Custom Claims Str to Interface 2 (Int)", args{input: map[string]string{"hello": "1"}}, map[string]interface{}{"hello": 1}}, | ||
{"Custom Claims Str to Interface 2 (Float)", args{input: map[string]string{"hello": "1.23"}}, map[string]interface{}{"hello": 1.23}}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := ProcessCustomClaimInput(tt.args.input); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("ProcessCustomClaimInput() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|