MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / TestJSONLogFile

Function TestJSONLogFile

pkg/userlog/json/jsonlogfile_test.go:29–76  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestJSONLogFile(t *testing.T) {
30 tmpdir, _ := ioutil.TempDir("", "jsonlog")
31 tmpfile := path.Join(tmpdir, "testlog")
32 jf, err := NewJSONLogFile(tmpfile, 200)
33 if err != nil {
34 t.Error(err)
35 return
36 }
37 l := &userlog.UserLog{
38 Created: time.Now(),
39 RequestID: "66525001-1e97-469b-a151-cd264f519711",
40 Source: "faas",
41 }
42 msg := []byte("www.baidu.com log message")
43 for i := 0; i < 5; i++ {
44 _, err = jf.Write(l, msg)
45 if err != nil {
46 t.Error(err)
47 return
48 }
49 }
50 i := 0
51 for ; i < 10; i++ {
52 _, err = jf.Write(l, msg)
53 if err != nil {
54 t.Log(err)
55 break
56 }
57 }
58 if i == 10 {
59 t.Error("capacity error")
60 return
61 }
62 jf.Close()
63 _, err = jf.Write(l, msg)
64 if err == nil {
65 t.Error("close failed")
66 return
67 }
68 t.Log(err)
69
70 data, err := ioutil.ReadFile(tmpfile)
71 if err != nil {
72 t.Error(err)
73 return
74 }
75 fmt.Print(string(data))
76}

Callers

nothing calls this directly

Calls 4

WriteMethod · 0.95
CloseMethod · 0.95
NewJSONLogFileFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected