sentry_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (C) 2019 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package main
  7. import (
  8. "fmt"
  9. "io/ioutil"
  10. "testing"
  11. )
  12. func TestParseVersion(t *testing.T) {
  13. cases := []struct {
  14. longVersion string
  15. parsed version
  16. }{
  17. {
  18. longVersion: `syncthing v1.1.4-rc.1+30-g6aaae618-dirty-crashrep "Erbium Earthworm" (go1.12.5 darwin-amd64) [email protected] 2019-05-23 16:08:14 UTC`,
  19. parsed: version{
  20. version: "v1.1.4-rc.1+30-g6aaae618-dirty-crashrep",
  21. tag: "v1.1.4-rc.1",
  22. commit: "6aaae618",
  23. codename: "Erbium Earthworm",
  24. runtime: "go1.12.5",
  25. goos: "darwin",
  26. goarch: "amd64",
  27. builder: "[email protected]",
  28. },
  29. },
  30. {
  31. longVersion: `syncthing v1.1.4-rc.1+30-g6aaae618-dirty-crashrep "Erbium Earthworm" (go1.12.5 darwin-amd64) [email protected] 2019-05-23 16:08:14 UTC [foo, bar]`,
  32. parsed: version{
  33. version: "v1.1.4-rc.1+30-g6aaae618-dirty-crashrep",
  34. tag: "v1.1.4-rc.1",
  35. commit: "6aaae618",
  36. codename: "Erbium Earthworm",
  37. runtime: "go1.12.5",
  38. goos: "darwin",
  39. goarch: "amd64",
  40. builder: "[email protected]",
  41. extra: []string{"foo", "bar"},
  42. },
  43. },
  44. }
  45. for _, tc := range cases {
  46. v, err := parseVersion(tc.longVersion)
  47. if err != nil {
  48. t.Errorf("%s\nerror: %v\n", tc.longVersion, err)
  49. continue
  50. }
  51. if fmt.Sprint(v) != fmt.Sprint(tc.parsed) {
  52. t.Errorf("%s\nA: %v\nE: %v\n", tc.longVersion, v, tc.parsed)
  53. }
  54. }
  55. }
  56. func TestParseReport(t *testing.T) {
  57. bs, err := ioutil.ReadFile("_testdata/panic.log")
  58. if err != nil {
  59. t.Fatal(err)
  60. }
  61. pkt, err := parseCrashReport("1/2/345", bs)
  62. if err != nil {
  63. t.Fatal(err)
  64. }
  65. bs, err = pkt.JSON()
  66. if err != nil {
  67. t.Fatal(err)
  68. }
  69. fmt.Printf("%s\n", bs)
  70. }