generated from LinuxSuRen/github-go
-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
255c95a
commit 464be2c
Showing
4 changed files
with
88 additions
and
25 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
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
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
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,79 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func Test_getRoundTripper(t *testing.T) { | ||
type args struct { | ||
ctx context.Context | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantTripper http.RoundTripper | ||
}{{ | ||
name: "context is nil", | ||
wantTripper: nil, | ||
}, { | ||
name: "invalid type of RounderTripper in the context", | ||
args: args{ | ||
ctx: context.WithValue(context.TODO(), "roundTripper", "invalid"), | ||
}, | ||
wantTripper: nil, | ||
}, { | ||
name: "valid type of RounderTripper in the context", | ||
args: args{ | ||
ctx: context.WithValue(context.TODO(), "roundTripper", &http.Transport{}), | ||
}, | ||
wantTripper: &http.Transport{}, | ||
}} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if gotTripper := getRoundTripper(tt.args.ctx); !reflect.DeepEqual(gotTripper, tt.wantTripper) { | ||
t.Errorf("getRoundTripper() = %v, want %v", gotTripper, tt.wantTripper) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_getOrDefault(t *testing.T) { | ||
type args struct { | ||
key string | ||
def string | ||
data map[string]string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantResult string | ||
}{{ | ||
name: "no key exist", | ||
args: args{ | ||
key: "key", | ||
def: "def", | ||
data: map[string]string{}, | ||
}, | ||
wantResult: "def", | ||
}, { | ||
name: "key exist", | ||
args: args{ | ||
key: "key", | ||
def: "def", | ||
data: map[string]string{ | ||
"key": "key", | ||
}, | ||
}, | ||
wantResult: "key", | ||
}} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if gotResult := getOrDefault(tt.args.key, tt.args.def, tt.args.data); gotResult != tt.wantResult { | ||
t.Errorf("getOrDefault() = %v, want %v", gotResult, tt.wantResult) | ||
} | ||
}) | ||
} | ||
} |