Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/cache/cacher test #553

Merged
merged 3 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/cache/cacher/cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ package cacher

import "strings"

// Type represents the cacher type. Currently it support GACHE only.
type Type uint8

const (
Unknown Type = iota
GACHE
)

// String returns the type name.
func (m Type) String() string {
switch m {
case GACHE:
Expand All @@ -34,6 +36,7 @@ func (m Type) String() string {
return "unknown"
}

// ToType returns the type based on the string.
func ToType(str string) Type {
switch strings.ToLower(str) {
case "gache":
Expand Down
110 changes: 66 additions & 44 deletions internal/cache/cacher/cacher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,27 @@ func TestType_String(t *testing.T) {
return nil
}
tests := []test{
// TODO test cases
/*
{
name: "test_case_1",
want: want{},
checkFunc: defaultCheckFunc,
},
*/

// TODO test cases
/*
func() test {
return test {
name: "test_case_2",
want: want{},
checkFunc: defaultCheckFunc,
}
}(),
*/
{
name: "return `gache` when type is gache",
m: GACHE,
want: want{
want: "gache",
},
},
{
name: "return `unknown` when type is unknown",
m: Unknown,
want: want{
want: "unknown",
},
},
kevindiu marked this conversation as resolved.
Show resolved Hide resolved
{
name: "return `unknown` when the type is invalid",
m: Type(100),
want: want{
want: "unknown",
},
},
}

for _, test := range tests {
Expand Down Expand Up @@ -107,31 +109,51 @@ func TestToType(t *testing.T) {
return nil
}
tests := []test{
// TODO test cases
/*
{
name: "test_case_1",
args: args {
str: "",
},
want: want{},
checkFunc: defaultCheckFunc,
},
*/

// TODO test cases
/*
func() test {
return test {
name: "test_case_2",
args: args {
str: "",
},
want: want{},
checkFunc: defaultCheckFunc,
}
}(),
*/
{
name: "return GACHE type when the string is `gache`",
args: args{
str: "gache",
},
want: want{
want: GACHE,
},
},
{
name: "return GACHE type when the string is `Gache`",
args: args{
str: "Gache",
},
want: want{
want: GACHE,
},
},
{
name: "return GACHE type when the string is `GACHE`",
args: args{
str: "GACHE",
},
want: want{
want: GACHE,
},
},
{
name: "return Unknown type when the string is invalid",
args: args{
str: "invalid",
},
want: want{
want: Unknown,
},
kevindiu marked this conversation as resolved.
Show resolved Hide resolved
},
{
name: "return Unknown type when the string is empty",
args: args{
str: "",
},
want: want{
want: Unknown,
},
},
}

for _, test := range tests {
Expand Down