feedback_test.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2016, Psiphon Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. package psiphon
  20. import (
  21. "encoding/json"
  22. "io/ioutil"
  23. "testing"
  24. )
  25. type Diagnostics struct {
  26. Feedback struct {
  27. Message struct {
  28. Text string `json:"text"`
  29. }
  30. Email string `json:"email"`
  31. }
  32. Metadata struct {
  33. Id string `json:"id"`
  34. Platform string `json:"platform"`
  35. Version int `json:"version"`
  36. }
  37. }
  38. func TestFeedbackUpload(t *testing.T) {
  39. configFileContents, err := ioutil.ReadFile("feedback_test.config")
  40. if err != nil {
  41. // Skip, don't fail, if config file is not present
  42. t.Skipf("error loading configuration file: %s", err)
  43. }
  44. shortRevHash, err := ioutil.ReadFile("git_rev")
  45. if err != nil {
  46. // Skip, don't fail, if git rev file is not present
  47. t.Skipf("error loading git revision file: %s", err)
  48. }
  49. var config map[string]interface{}
  50. err = json.Unmarshal(configFileContents, &config)
  51. if err != nil {
  52. t.Error(err.Error())
  53. t.FailNow()
  54. }
  55. // Form dummy feedback data which can be verified later
  56. diagnostics := Diagnostics{}
  57. diagnostics.Feedback.Message.Text = "Travis test feedback. Revision " + string(shortRevHash)
  58. diagnostics.Metadata.Id = "0000000000000000"
  59. diagnostics.Metadata.Platform = "android"
  60. diagnostics.Metadata.Version = 4
  61. diagnosticData, err := json.Marshal(diagnostics)
  62. if err != nil {
  63. t.Error(err.Error())
  64. t.FailNow()
  65. }
  66. err = SendFeedback(string(configFileContents), string(diagnosticData), config["ENCRYPTION_PUBLIC_KEY"].(string), config["UPLOAD_SERVER"].(string), config["UPLOAD_PATH"].(string), config["UPLOAD_SERVER_HEADERS"].(string))
  67. if err != nil {
  68. t.Error(err.Error())
  69. t.FailNow()
  70. }
  71. }