本文整理汇总了Golang中testing.T.Format方法的典型用法代码示例。如果您正苦于以下问题:Golang T.Format方法的具体用法?Golang T.Format怎么用?Golang T.Format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testing.T
的用法示例。
在下文中一共展示了T.Format方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Test_main_unit
func Test_main_unit(t *testing.T) {
Convey("main", t, func() {
parts := strings.Split(time.Now().Format("2006-01-02-07:00"), "-")
y, m, d, z := parts[0], parts[1], parts[2], parts[3]
testTable := map[string]string{
"01/01 01:52 pm": fmt.Sprintf("%s-01-01T13:52:00-%s", y, z), // full
"1/01 01:00 pm": fmt.Sprintf("%s-01-01T13:00:00-%s", y, z), // short day/month
"01/1 01:00 pm": fmt.Sprintf("%s-01-01T13:00:00-%s", y, z), // short day/month
"1/1 01:00 pm": fmt.Sprintf("%s-01-01T13:00:00-%s", y, z), // short day/month
"01/01 1:00 pm": fmt.Sprintf("%s-01-01T13:00:00-%s", y, z), // short hour
"1/01 1:00 pm": fmt.Sprintf("%s-01-01T13:00:00-%s", y, z), // short hour
"01/1 1:00 pm": fmt.Sprintf("%s-01-01T13:00:00-%s", y, z), // short hour
"1/1 1:00 pm": fmt.Sprintf("%s-01-01T13:00:00-%s", y, z), // short hour
"01:52 pm": fmt.Sprintf("%s-%s-%sT13:52:00-%s", y, m, d, z), // time
"1:52 pm": fmt.Sprintf("%s-%s-%sT13:52:00-%s", y, m, d, z), // time
"01/01 13:52": fmt.Sprintf("%s-01-01T13:52:00-%s", y, z), // 24hr time
"1/01 13:52": fmt.Sprintf("%s-01-01T13:52:00-%s", y, z), // 24hr time
"01/1 13:52": fmt.Sprintf("%s-01-01T13:52:00-%s", y, z), // 24hr time
"1/1 13:52": fmt.Sprintf("%s-01-01T13:52:00-%s", y, z), // 24hr time
"13:52": fmt.Sprintf("%s-%s-%sT13:52:00-%s", y, m, d, z), // 24hr time
}
for teststr, goodstr := range testTable {
Convey("Given "+teststr, func() {
Convey("time should equal "+goodstr, func() {
t, err := ParseTime(teststr)
So(err, ShouldBeNil)
So(t.Format(time.RFC3339), ShouldEqual, goodstr)
})
})
}
})
}
示例2: TestTokenized
func TestTokenized(t *testing.T) {
Convey("Tokenizing data from a request works as expected", t, func() {
// Let's setup a test server.
var ts *httptest.Server
ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" && r.URL.Path == "/test" {
defer r.Body.Close()
w.Header().Add("X-Custom-Hdr", "Custom Header")
w.Header().Add("Set-Cookie", "session_id=42 ; Path=/")
w.WriteHeader(200)
fmt.Fprint(w, fmt.Sprintf(`{"URL": "%s", "json": true, "foolMeOnce": "shame on you"}`, r.URL))
}
}))
Convey("Given a Tokenized objects, confirm that it formats the right information if does not format anything.", func() {
t := Tokenized{Data: "test"}
So(t.Format(nil), ShouldEqual, "test")
So(t.String(), ShouldEqual, "{Tokenized with data}")
})
Convey("Given a Tokenized objects, confirm that it formats the right information if response is nil.", func() {
t := Tokenized{Data: "test", Cookie: "ChocChip"}
So(t.Format(nil), ShouldEqual, "test")
So(t.String(), ShouldEqual, "{Tokenized with cookie with data}")
})
Convey("Given a Tokenized objects, confirm that it formats the right information.", func() {
example := `<headers responseToken="resp" headerToken="hdr" cookieToken="cke">
X-Fool:NotAMonkey resp/foolMeOnce
Cookie:test=true;session_id=cke/session_id
Some-Header:hdr/X-Custom-Hdr
X-Cannot-Decode: resp/json
</headers>`
out := Tokenized{}
xml.Unmarshal([]byte(example), &out)
gresp, _ := goreq.Request{Uri: ts.URL + "/test"}.Do()
resp := Response{}
resp.FromGoResp(gresp, nil, time.Now())
expectations := []string{"", "X-Fool:NotAMonkey shame on you", "Cookie:test=true;session_id=42", "Some-Header:Custom Header", "X-Cannot-Decode:", ""}
for pos, line := range strings.Split(out.Format(&resp), "\n") {
So(strings.TrimSpace(line), ShouldEqual, expectations[pos])
}
So(out.String(), ShouldEqual, "{Tokenized with cookie with header with data}")
})
})
}