upload_test.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/main/apm/model/ut"
  5. "io/ioutil"
  6. "testing"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. // import (
  10. // "context"
  11. // "testing"
  12. // "time"
  13. // "github.com/smartystreets/goconvey/convey"
  14. // )
  15. // const content = `panic: runtime error: invalid memory address or nil pointer dereference
  16. // [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1565c97]
  17. // goroutine 1 [running]:
  18. // go-common/app/interface/main/answer/dao/account.New(0x1a972e0, 0xc42017f4d0)
  19. // /Users/bilibili/go/src/go-common/app/interface/main/answer/dao/account/pendant.go:36 +0x37
  20. // go-common/app/interface/main/answer/dao/account.init.0()
  21. // /Users/bilibili/go/src/go-common/app/interface/main/answer/dao/account/pendant_test.go:21 +0x68
  22. // FAIL go-common/app/interface/main/answer/dao/account 0.031s
  23. // panic: runtime error: invalid memory address or nil pointer dereference
  24. // [signal SIGSEGV: segmentation violation code=0x1 addr=0x50 pc=0x1439ed6]
  25. // === RUN TestDao_MoralLog
  26. // >->->OPEN-JSON->->->
  27. // {
  28. // "Title": "MoralLog",
  29. // "File": "/Users/bilibili/go/src/go-common/app/service/main/member/dao/hbase_test.go",
  30. // "Line": 11,
  31. // "Depth": 1,
  32. // "Assertions": [
  33. // {
  34. // "File": "/Users/bilibili/go/src/go-common/app/service/main/member/dao/hbase_test.go",
  35. // "Line": 12,
  36. // "Expected": "",
  37. // "Actual": "",
  38. // "Failure": "",
  39. // "Error": "runtime error: invalid memory address or nil pointer dereference",",
  40. // "Skipped": false
  41. // }
  42. // ],
  43. // "Output": ""
  44. // },
  45. // <-<-<-CLOSE-JSON<-<-<
  46. // --- FAIL: TestDao_MoralLog (0.00s)
  47. // `
  48. // func TestService_Upload(t *testing.T) {
  49. // convey.Convey("ParserContent", t, func() {
  50. // data, err := svr.ParseContent(context.Background(), []byte(content))
  51. // convey.So(err, convey.ShouldBeNil)
  52. // convey.So(data, convey.ShouldNotBeNil)
  53. // t.Logf("after parsercontent: %s", string(data))
  54. // convey.So(err, convey.ShouldBeNil)
  55. // info, err := svr.CalcCount(context.Background(), data)
  56. // convey.So(err, convey.ShouldBeNil)
  57. // t.Logf("pass: %d", info.Passed)
  58. // t.Logf("fail: %d", info.Failures)
  59. // t.Logf("skip: %d", info.Skipped)
  60. // t.Logf("panics: %d", info.Panics)
  61. // t.Logf("total: %d", info.Assertions)
  62. // t.Logf("coverage: %s", info.Coverage)
  63. // convey.Convey("Upload", func() {
  64. // var (
  65. // body = data
  66. // )
  67. // url, err := svr.Upload(context.Background(), "json", time.Now().Unix(), body)
  68. // convey.So(err, convey.ShouldBeNil)
  69. // convey.So(url, convey.ShouldNotBeNil)
  70. // t.Logf("Location: %s", url)
  71. // })
  72. // })
  73. // }
  74. func TestServiceCalcCountFiles(t *testing.T) {
  75. convey.Convey("CalcCountFiles", t, func(ctx convey.C) {
  76. var (
  77. c = context.Background()
  78. res = &ut.UploadRes{
  79. CommitID: "somestringhasnothingtodo",
  80. PKG: "go-common/app/admin/main/apm/dao",
  81. }
  82. filename = "/data/ut1/cover.out"
  83. )
  84. body, _ := ioutil.ReadFile(filename)
  85. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  86. utfiles, err := svr.CalcCountFiles(c, res, body)
  87. t.Logf("\nutfiles:%#v\n", utfiles)
  88. for i, utfile := range utfiles {
  89. t.Logf("\nutfiles[%d]:%#v\n", i, utfile)
  90. }
  91. ctx.So(err, convey.ShouldBeNil)
  92. })
  93. })
  94. }