sentry_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. for _, tc := range cases {
  32. v, err := parseVersion(tc.longVersion)
  33. if err != nil {
  34. t.Error(err)
  35. continue
  36. }
  37. if v != tc.parsed {
  38. t.Error(v)
  39. }
  40. }
  41. }
  42. func TestParseReport(t *testing.T) {
  43. bs, err := ioutil.ReadFile("_testdata/panic.log")
  44. if err != nil {
  45. t.Fatal(err)
  46. }
  47. pkt, err := parseReport("1/2/345", bs)
  48. if err != nil {
  49. t.Fatal(err)
  50. }
  51. bs, err = pkt.JSON()
  52. if err != nil {
  53. t.Fatal(err)
  54. }
  55. fmt.Printf("%s\n", bs)
  56. }