@@ -2,10 +2,12 @@ package issue
22
33import (
44 "os"
5+ "path/filepath"
56 "testing"
67 "time"
78
89 "github.com/getlantern/flashlight/v7/common"
10+ userconfig "github.com/getlantern/flashlight/v7/config/user"
911 "github.com/getlantern/flashlight/v7/geolookup"
1012)
1113
@@ -22,6 +24,10 @@ func TestSendReport(t *testing.T) {
2224 //manually set library version since its only populated when run from a binary
2325 common .LibraryVersion = "7.0.0"
2426 UserConfigData := common.UserConfigData {}
27+
28+ closeTestFiles := initTestConfig (t )
29+ defer closeTestFiles ()
30+
2531 err := sendReport (
2632 & UserConfigData ,
2733 "34qsdf-24qsadf-32542q" ,
@@ -48,3 +54,58 @@ func TestSendReport(t *testing.T) {
4854 t .Errorf ("SendReport() error = %v" , err )
4955 }
5056}
57+
58+ func initTestConfig (t * testing.T ) func () {
59+ dir := "testdata"
60+ err := os .MkdirAll (dir , 0755 )
61+ if err != nil {
62+ t .Logf ("Failed to create testdata dir: %v" , err )
63+ }
64+
65+ f , err := os .Create (filepath .Join (dir , "user.conf" ))
66+ if err != nil {
67+ t .Logf ("Failed to create temp file: %v" , err )
68+ }
69+
70+ f .Write ([]byte (`{
71+ "country": "US",
72+ "proxy": {
73+ "proxies": [
74+ {
75+ "addr": "1.1.1.1",
76+ "track": "raichu",
77+ "location": {
78+ "city": "New York",
79+ "country": "United States",
80+ "countryCode": "US",
81+ "latitude": 1.23,
82+ "longitude": 4.56
83+ },
84+ "name": "raichu-proxy",
85+ "port": 123,
86+ "protocol": "tlsmasq",
87+ "certPem": "pem",
88+ "authToken": "token",
89+ "trusted": true,
90+ "connectCfgTlsmasq": {
91+ "originAddr": "google.com",
92+ "secret": "password",
93+ "tlsMinVersion": "1"
94+ }
95+ }
96+ ]
97+ }
98+ }` ))
99+
100+ conf , err := userconfig .Init (dir , true )
101+ if err != nil {
102+ t .Logf ("Failed to initialize user config: %v" , err )
103+ }
104+ if conf != nil {
105+ t .Logf ("User config initialized successfully" )
106+ }
107+ return func () {
108+ f .Close ()
109+ os .RemoveAll (dir )
110+ }
111+ }
0 commit comments