profiles_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 2018, 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 common
  20. import (
  21. "fmt"
  22. "io/ioutil"
  23. "os"
  24. "testing"
  25. )
  26. func TestWriteRuntimeProfiles(t *testing.T) {
  27. testDirName, err := ioutil.TempDir("", "psiphon-profiles-test")
  28. if err != nil {
  29. fmt.Printf("TempDir failed: %s\n", err)
  30. os.Exit(1)
  31. }
  32. defer os.RemoveAll(testDirName)
  33. WriteRuntimeProfiles(&testLogger{}, testDirName, "suffix", 1, 1)
  34. }
  35. type testLogger struct {
  36. }
  37. func (logger *testLogger) WithTrace() LogTrace {
  38. return &testLoggerTrace{}
  39. }
  40. func (logger *testLogger) WithTraceFields(fields LogFields) LogTrace {
  41. return &testLoggerTrace{}
  42. }
  43. func (logger *testLogger) LogMetric(metric string, fields LogFields) {
  44. panic("unexpected log call")
  45. }
  46. func (logger *testLogger) IsLogLevelDebug() bool {
  47. return true
  48. }
  49. type testLoggerTrace struct {
  50. }
  51. func (logger *testLoggerTrace) Debug(args ...interface{}) {
  52. }
  53. func (logger *testLoggerTrace) Info(args ...interface{}) {
  54. }
  55. func (logger *testLoggerTrace) Warning(args ...interface{}) {
  56. panic("unexpected log call")
  57. }
  58. func (logger *testLoggerTrace) Error(args ...interface{}) {
  59. panic("unexpected log call")
  60. }