github.com/Psiphon-Labs/psiphon-tunnel-core@v2.0.28+incompatible/psiphon/common/profiles_test.go (about) 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 20 package common 21 22 import ( 23 "fmt" 24 "io/ioutil" 25 "os" 26 "testing" 27 ) 28 29 func TestWriteRuntimeProfiles(t *testing.T) { 30 31 testDirName, err := ioutil.TempDir("", "psiphon-profiles-test") 32 if err != nil { 33 fmt.Printf("TempDir failed: %s\n", err) 34 os.Exit(1) 35 } 36 defer os.RemoveAll(testDirName) 37 38 WriteRuntimeProfiles(&testLogger{}, testDirName, "suffix", 1, 1) 39 } 40 41 type testLogger struct { 42 } 43 44 func (logger *testLogger) WithTrace() LogTrace { 45 return &testLoggerTrace{} 46 } 47 48 func (logger *testLogger) WithTraceFields(fields LogFields) LogTrace { 49 return &testLoggerTrace{} 50 } 51 52 func (logger *testLogger) LogMetric(metric string, fields LogFields) { 53 panic("unexpected log call") 54 } 55 56 type testLoggerTrace struct { 57 } 58 59 func (logger *testLoggerTrace) Debug(args ...interface{}) { 60 } 61 62 func (logger *testLoggerTrace) Info(args ...interface{}) { 63 } 64 65 func (logger *testLoggerTrace) Warning(args ...interface{}) { 66 panic("unexpected log call") 67 } 68 69 func (logger *testLoggerTrace) Error(args ...interface{}) { 70 panic("unexpected log call") 71 }