From 0a1afeadf8204bf8da5bdb6aa155830469089473 Mon Sep 17 00:00:00 2001 From: Kevin Diu Date: Tue, 7 Jul 2020 18:06:25 +0900 Subject: [PATCH] :white_check_mark: internal/cache/cacher test (#553) * add test and comment * fix * Apply suggestions from code review Co-authored-by: Kiichiro YUKAWA Co-authored-by: Kiichiro YUKAWA --- internal/cache/cacher/cacher.go | 3 + internal/cache/cacher/cacher_test.go | 110 ++++++++++++++++----------- 2 files changed, 69 insertions(+), 44 deletions(-) diff --git a/internal/cache/cacher/cacher.go b/internal/cache/cacher/cacher.go index e341825675..f2e28683b1 100644 --- a/internal/cache/cacher/cacher.go +++ b/internal/cache/cacher/cacher.go @@ -19,6 +19,7 @@ package cacher import "strings" +// Type represents the cacher type. Currently it support GACHE only. type Type uint8 const ( @@ -26,6 +27,7 @@ const ( GACHE ) +// String returns the type name. func (m Type) String() string { switch m { case GACHE: @@ -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": diff --git a/internal/cache/cacher/cacher_test.go b/internal/cache/cacher/cacher_test.go index abef1369e5..ddbe79d514 100644 --- a/internal/cache/cacher/cacher_test.go +++ b/internal/cache/cacher/cacher_test.go @@ -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", + }, + }, + { + name: "return `unknown` when the type is invalid", + m: Type(100), + want: want{ + want: "unknown", + }, + }, } for _, test := range tests { @@ -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, + }, + }, + { + name: "return Unknown type when the string is empty", + args: args{ + str: "", + }, + want: want{ + want: Unknown, + }, + }, } for _, test := range tests {