MCPcopy Create free account
hub / github.com/ProspectOne/perfops-cli / TestPrintOutput

Function TestPrintOutput

cmd/internal/runtest_test.go:76–119  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

74}
75
76func TestPrintOutput(t *testing.T) {
77 testCases := map[string]struct {
78 output func() *perfops.RunOutput
79 exp string
80 }{
81 "all": {
82 func() *perfops.RunOutput {
83 var o *perfops.RunOutput
84 json.Unmarshal([]byte(`{"id":"706fc55e3377104da01f05569e35a30b","items":[{"id":"bba072473bd034d432df03730e116686","result":{"output":"121","finished": true,"node":{"id":27,"as_number":12345,"latitude":22.28512548314,"longitude":114.17507171631,"country":{"id":195,"name":"Hong Kong","continent":{"id":2,"name":"Asia","iso":"AS"},"iso":"HK","iso_numeric":"344"},"city":"Hong Kong","sub_region":"Eastern Asia"},"time":1508061924.088372}}],"requested":"sendergram.com","finished":true,"elapsedTime":0.66500000000000004}`), &o)
85 return o
86 },
87 "\x1b[200DNode27, AS12345, Hong Kong, Hong Kong\n121\n",
88 },
89 "timeout": {
90 func() *perfops.RunOutput {
91 var o *perfops.RunOutput
92 json.Unmarshal([]byte(`{"id":"706fc55e3377104da01f05569e35a30b","items":[{"id":"bba072473bd034d432df03730e116686","result":{"output":"-2","finished": true,"node":{"id":27,"as_number":23456,"latitude":22.28512548314,"longitude":114.17507171631,"country":{"id":195,"name":"Hong Kong","continent":{"id":2,"name":"Asia","iso":"AS"},"iso":"HK","iso_numeric":"344"},"city":"Hong Kong","sub_region":"Eastern Asia"},"time":1508061924.088372}}],"requested":"sendergram.com","finished":true,"elapsedTime":0.66500000000000004}`), &o)
93 return o
94 },
95 "\x1b[200DNode27, AS23456, Hong Kong, Hong Kong\nThe command timed-out. It either took too long to execute or we could not connect to your target at all.\n",
96 },
97 "array output": {
98 func() *perfops.RunOutput {
99 var o *perfops.RunOutput
100 json.Unmarshal([]byte(`{"id":"6e0c06f7445bb8c63949f84fcdbdae55","items":[{"id":"2bff5d6b3a4df8a268afca6c60977032","result":{"dnsServer":"","node":{"as_number":197328,"id":103,"latitude":41.030549854339,"longitude":28.987083435058,"country":{"id":93,"name":"Turkey","continent":{"id":2,"name":"Asia","iso":"AS"},"iso":"TR","iso_numeric":"792","is_eu":false},"city":"Istanbul","sub_region":"Western Asia"},"finished":true,"output":["header"," 1 row", " 10 row"],"time":1539517079.937741}}],"requested":"ns2.no-ip.com","finished":true,"elapsedTime":2.21,"creditsWithdrawn":1}`), &o)
101 return o
102 },
103 "\x1b[200DNode103, AS197328, Istanbul, Turkey\nheader\n 1 row\n 10 row\n",
104 },
105 }
106
107 var b bytes.Buffer
108 f := newTestFormatter(&b, false)
109 for name, tc := range testCases {
110 t.Run(name, func(t *testing.T) {
111 b.Reset()
112 PrintOutput(f, tc.output())
113 got := b.String()
114 if got != tc.exp {
115 t.Fatalf("expected %#v; got %#v", tc.exp, got)
116 }
117 })
118 }
119}
120
121func TestOutputToFile(t *testing.T) {
122 testCases := map[string]struct {

Callers

nothing calls this directly

Calls 2

newTestFormatterFunction · 0.85
PrintOutputFunction · 0.85

Tested by

no test coverage detected