(t *testing.T)
| 119 | } |
| 120 | |
| 121 | func TestOutputToFile(t *testing.T) { |
| 122 | testCases := map[string]struct { |
| 123 | output func() *perfops.RunOutput |
| 124 | exp []byte |
| 125 | }{ |
| 126 | "all": { |
| 127 | func() *perfops.RunOutput { |
| 128 | var o *perfops.RunOutput |
| 129 | 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) |
| 130 | return o |
| 131 | }, |
| 132 | []byte("\x1b[200DNode27, AS12345, Hong Kong, Hong Kong\n121\n"), |
| 133 | }, |
| 134 | "timeout": { |
| 135 | func() *perfops.RunOutput { |
| 136 | var o *perfops.RunOutput |
| 137 | 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) |
| 138 | return o |
| 139 | }, |
| 140 | []byte("\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"), |
| 141 | }, |
| 142 | "array output": { |
| 143 | func() *perfops.RunOutput { |
| 144 | var o *perfops.RunOutput |
| 145 | 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) |
| 146 | return o |
| 147 | }, |
| 148 | []byte("\x1b[200DNode103, AS197328, Istanbul, Turkey\nheader\n 1 row\n 10 row\n"), |
| 149 | }, |
| 150 | } |
| 151 | var b bytes.Buffer |
| 152 | f := newTestFormatter(&b, false) |
| 153 | for name, tc := range testCases { |
| 154 | t.Run(name, func(t *testing.T) { |
| 155 | OutputToFile(f, tc.output(), "test.txt") |
| 156 | if _, err := os.Stat("test.txt"); err != nil { |
| 157 | t.Error("File was not created") |
| 158 | } |
| 159 | err := os.Remove("test.txt") |
| 160 | if err != nil { |
| 161 | return |
| 162 | } |
| 163 | }) |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | type testTerminalWriter struct { |
| 168 | io.Writer |
nothing calls this directly
no test coverage detected