@@ -121,11 +121,59 @@ func TestTraceWritesMeta(t *testing.T) {
121121 b , err := ioutil .ReadFile (tempdir + "/2019/04/01/20190401T034551Z_" + prefix .UnsafeString () + "_0000000000000001.jsonl" )
122122 rtx .Must (err , "Could not read file" )
123123
124- type metadata struct {
125- UUID string
126- TracerouteCallerVersion string
124+ m := Metadata {}
125+ lines := strings .Split (string (b ), "\n " )
126+ if len (lines ) < 2 {
127+ t .Error ("Not enough lines in" , lines )
128+ }
129+ rtx .Must (json .Unmarshal ([]byte (lines [0 ]), & m ), "Could not unmarshal" )
130+
131+ uuidChunks := strings .Split (m .UUID , "_" )
132+
133+ if uuidChunks [len (uuidChunks )- 1 ] != "0000000000000001" {
134+ t .Error ("Bad uuid:" , m .UUID )
135+ }
136+
137+ if m .TracerouteCallerVersion != "Fake Version" {
138+ t .Error ("Bad traceroute caller version:" , m .TracerouteCallerVersion )
127139 }
128- m := metadata {}
140+ }
141+
142+ func TestCreateCacheTest (t * testing.T ) {
143+ tempdir , err := ioutil .TempDir ("" , "TestCachedTrace" )
144+ rtx .Must (err , "Could not create tempdir" )
145+ defer os .RemoveAll (tempdir )
146+
147+ // Temporarily set the hostname to a value for testing.
148+ defer func (oldHn string ) {
149+ hostname = oldHn
150+ }(hostname )
151+ hostname = "testhostname"
152+
153+ d := Daemon {
154+ AttachBinary : "echo" ,
155+ Warts2JSONBinary : "cat" ,
156+ OutputPath : tempdir ,
157+ }
158+
159+ c := connection.Connection {
160+ Cookie : "1" ,
161+ RemoteIP : "1.2.3.4" ,
162+ }
163+
164+ faketime := time .Date (2019 , time .April , 1 , 3 , 45 , 51 , 0 , time .UTC )
165+ prometheusx .GitShortCommit = "Fake Version"
166+ cachedTest := `{"UUID": "ndt-plh7v_1566050090_000000000004D64D"}
167+ {"type":"cycle-start", "list_name":"/tmp/scamperctrl:51811", "id":1, "hostname":"ndt-plh7v", "start_time":1566691298}
168+ {"type":"tracelb", "version":"0.1", "userid":0, "method":"icmp-echo", "src":"::ffff:180.87.97.101", "dst":"::ffff:1.47.236.62", "start":{"sec":1566691298, "usec":476221, "ftime":"2019-08-25 00:01:38"}, "probe_size":60, "firsthop":1, "attempts":3, "confidence":95, "tos":0, "gaplimit":3, "wait_timeout":5, "wait_probe":250, "probec":0, "probec_max":3000, "nodec":0, "linkc":0}
169+ {"type":"cycle-stop", "list_name":"/tmp/scamperctrl:51811", "id":1, "hostname":"ndt-plh7v", "stop_time":1566691298}`
170+ d .CreateCacheTest (c , faketime , cachedTest )
171+
172+ // Unmarshal the first line of the output file.
173+ b , err := ioutil .ReadFile (tempdir + "/2019/04/01/20190401T034551Z_" + prefix .UnsafeString () + "_0000000000000001.jsonl" )
174+ rtx .Must (err , "Could not read file" )
175+
176+ m := Metadata {}
129177 lines := strings .Split (string (b ), "\n " )
130178 if len (lines ) < 2 {
131179 t .Error ("Not enough lines in" , lines )
@@ -141,6 +189,14 @@ func TestTraceWritesMeta(t *testing.T) {
141189 if m .TracerouteCallerVersion != "Fake Version" {
142190 t .Error ("Bad traceroute caller version:" , m .TracerouteCallerVersion )
143191 }
192+
193+ if m .CachedResult != true {
194+ t .Error ("Bad traceroute CachedResult value:" , m .CachedResult )
195+ }
196+
197+ if m .CachedUUID != "ndt-plh7v_1566050090_000000000004D64D" {
198+ t .Error ("Bad traceroute CachedUUID value:" , m .CachedUUID )
199+ }
144200}
145201
146202func TestRecovery (t * testing.T ) {
0 commit comments