zrhoffman commented on a change in pull request #4993:
URL: https://github.com/apache/trafficcontrol/pull/4993#discussion_r480201937
##########
File path: traffic_monitor/cache/astats_test.go
##########
@@ -20,28 +20,99 @@ package cache
*/
import (
+ "bytes"
"io/ioutil"
"math/rand"
+ "net/http"
+ "os"
"testing"
"github.com/apache/trafficcontrol/lib/go-tc"
+ "github.com/apache/trafficcontrol/traffic_monitor/poller"
"github.com/apache/trafficcontrol/traffic_monitor/todata"
-
- "github.com/json-iterator/go"
)
-func TestAstats(t *testing.T) {
- text, err := ioutil.ReadFile("astats.json")
+func TestAstatsJson(t *testing.T) {
+ file, err := os.Open("astats.json")
if err != nil {
t.Fatal(err)
}
- aStats := Astats{}
- json := jsoniter.ConfigFastest
- err = json.Unmarshal(text, &aStats)
+
+ pl := &poller.HTTPPollCtx{HTTPHeader: http.Header{}}
+ ctx := interface{}(pl)
+ ctx.(*poller.HTTPPollCtx).HTTPHeader.Set("Content-Type", "text/json")
+ _, thismap, err := astatsParse("testCache", file, ctx)
+
if err != nil {
t.Error(err)
}
- t.Logf("Found %v key/val pairs in ats\n", len(aStats.Ats))
+
+ t.Logf("Found %v key/val pairs in ats\n", len(thismap))
+
+}
+
+func TestAstatsCSV(t *testing.T) {
+ file, err := os.Open("astats.csv")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ pl := &poller.HTTPPollCtx{HTTPHeader: http.Header{}}
+ ctx := interface{}(pl)
+ ctx.(*poller.HTTPPollCtx).HTTPHeader.Set("Content-Type", "text/csv")
+ _, thismap, err := astatsParse("testCache", file, ctx)
+
+ if err != nil {
+ t.Error(err)
+ }
+
+ t.Logf("Found %v key/val pairs in ats\n", len(thismap))
Review comment:
Maybe assert the number of key/val pairs the test is supposed to find?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]