Skip to content

Commit fd1664b

Browse files
authored
Merge pull request #41 from zarianec/POD-330
POD-330: Fix error with a new API response format
2 parents 6034fa9 + 35c63cb commit fd1664b

4 files changed

Lines changed: 14 additions & 13 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.local
22
release
33
.vscode
4+
.idea
45

56
# Created by https://www.gitignore.io
67

cmd/internal/runtest_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestRunTest(t *testing.T) {
5454
},
5555
func(ctx context.Context, pingID perfops.TestID) (*perfops.RunOutput, error) {
5656
var output *perfops.RunOutput
57-
err := json.Unmarshal([]byte(`{"id": "9072a72f762b876525ca4c9153af9983","items": [{"id": "edca088e43bde5453b961f6210723157","result": {"output": "Start: Thu Jul 27 15:59:05 2017 Loss% Snt Last Avg Best Wrst StDev\n 1.|-- 172.18.0.1 0.0% 2 0.0 0.1 0.0 0.1 0.0\n 2.|-- 10.0.2.2 0.0% 2 0.2 0.2 0.2 0.2 0.0\n 3.|-- 192.168.0.1 0.0% 2 1.3 1.5 1.3 1.6 0.0\n 4.|-- ??? 100.0 2 0.0 0.0 0.0 0.0 0.0\n 5.|-- 80.81.194.168 0.0% 2 25.0 23.4 21.8 25.0 2.0\n 6.|-- 80.81.194.52 0.0% 2 41.4 41.4 41.4 41.4 0.0\n 7.|-- 104.44.80.143 0.0% 2 40.9 40.5 40.0 40.9 0.0\n 8.|-- ??? 100.0 2 0.0 0.0 0.0 0.0 0.0\n 9.|-- ??? 100.0 2 0.0 0.0 0.0 0.0 0.0\n 10.|-- ??? 100.0 2 0.0 0.0 0.0 0.0 0.0\n 11.|-- 13.107.21.200 0.0% 2 39.8 40.1 39.8 40.3 0.0\n","node": {"id": 5,"as_number":12345,"latitude": 50.110781326572834,"longitude": 8.68984222412098,"country": {"id": 116,"name": "Germany","continent": {"id": 3,"name": "Europe","iso": "EU"},"iso": "DE","iso_numeric": "276"},"city": "Frankfurt","sub_region": "Western Europe"}}}],"requested": "bing.com","finished": "true"}`), &output)
57+
err := json.Unmarshal([]byte(`{"id": "9072a72f762b876525ca4c9153af9983","items": [{"id": "edca088e43bde5453b961f6210723157","result": {"output": "Start: Thu Jul 27 15:59:05 2017 Loss% Snt Last Avg Best Wrst StDev\n 1.|-- 172.18.0.1 0.0% 2 0.0 0.1 0.0 0.1 0.0\n 2.|-- 10.0.2.2 0.0% 2 0.2 0.2 0.2 0.2 0.0\n 3.|-- 192.168.0.1 0.0% 2 1.3 1.5 1.3 1.6 0.0\n 4.|-- ??? 100.0 2 0.0 0.0 0.0 0.0 0.0\n 5.|-- 80.81.194.168 0.0% 2 25.0 23.4 21.8 25.0 2.0\n 6.|-- 80.81.194.52 0.0% 2 41.4 41.4 41.4 41.4 0.0\n 7.|-- 104.44.80.143 0.0% 2 40.9 40.5 40.0 40.9 0.0\n 8.|-- ??? 100.0 2 0.0 0.0 0.0 0.0 0.0\n 9.|-- ??? 100.0 2 0.0 0.0 0.0 0.0 0.0\n 10.|-- ??? 100.0 2 0.0 0.0 0.0 0.0 0.0\n 11.|-- 13.107.21.200 0.0% 2 39.8 40.1 39.8 40.3 0.0\n","node": {"id": 5,"as_number":12345,"latitude": 50.110781326572834,"longitude": 8.68984222412098,"country": {"id": 116,"name": "Germany","continent": {"id": 3,"name": "Europe","iso": "EU"},"iso": "DE","iso_numeric": "276"},"city": "Frankfurt","sub_region": "Western Europe"}}}],"requested": "bing.com","finished": true}`), &output)
5858
return output, err
5959
},
6060
nil,
@@ -79,23 +79,23 @@ func TestPrintOutput(t *testing.T) {
7979
"all": {
8080
func() *perfops.RunOutput {
8181
var o *perfops.RunOutput
82-
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)
82+
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)
8383
return o
8484
},
8585
"\x1b[200DNode27, AS12345, Hong Kong, Hong Kong\n121\n",
8686
},
8787
"timeout": {
8888
func() *perfops.RunOutput {
8989
var o *perfops.RunOutput
90-
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)
90+
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)
9191
return o
9292
},
9393
"\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",
9494
},
9595
"array output": {
9696
func() *perfops.RunOutput {
9797
var o *perfops.RunOutput
98-
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)
98+
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)
9999
return o
100100
},
101101
"\x1b[200DNode103, AS197328, Istanbul, Turkey\nheader\n 1 row\n 10 row\n",

perfops/run.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type (
6969
RunOutput struct {
7070
ID string `json:"id,omitempty"`
7171
Requested string `json:"requested,omitempty"`
72-
Finished string `json:"finished"`
72+
Finished bool `json:"finished"`
7373
Items []*RunItem `json:"items,omitempty"`
7474
}
7575

@@ -118,7 +118,7 @@ type (
118118
DNSTestOutput struct {
119119
ID string `json:"id,omitempty"`
120120
Requested string `json:"requested,omitempty"`
121-
Finished string `json:"finished"`
121+
Finished bool `json:"finished"`
122122
Items []*DNSTestItem `json:"items,omitempty"`
123123
}
124124

@@ -370,13 +370,13 @@ func (r *RunResult) IsFinished() bool {
370370
// IsFinished returns a value indicating whether the whole output is
371371
// complete or not.
372372
func (o *RunOutput) IsFinished() bool {
373-
return o.Finished == "true"
373+
return o.Finished == true
374374
}
375375

376376
// IsFinished returns a value indicating whether the whole output is
377377
// complete or not.
378378
func (o *DNSTestOutput) IsFinished() bool {
379-
return o.Finished == "true"
379+
return o.Finished == true
380380
}
381381

382382
// PerfOutput returns the unmarshalled output for DNS perf requests.

perfops/run_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func TestLatencyOutput(t *testing.T) {
110110
t.Fatalf("expected path %v; got %v", exp, got)
111111
}
112112

113-
const body = `{"id": "2e9fd0e3a444adddb9b8168e6e0f856c","items": [{"id": "186b4c4c77985f75e7cefc48289e79ff","result": {"ip": "74.125.200.113","output": "35.223","node": {"id": 58,"as_number": 12345,"latitude": 22.280042521009999,"longitude": 114.1915512085,"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"}}}, {"id": "34ae843cf4d341b252a14e3d6b39281f","result": {"output": -1,"message": "100% packet loss","node": {"id": 208,"as_number": 23456,"latitude": 30.255360295637001,"longitude": 120.15712738037,"country": {"id": 62,"name": "China","continent": {"id": 2,"name": "Asia","iso": "AS"},"iso": "CN","iso_numeric": "156"},"city": "Hangzhou","sub_region": "Eastern Asia"}}}],"requested": "google.com","finished": "true"}`
113+
const body = `{"id": "2e9fd0e3a444adddb9b8168e6e0f856c","items": [{"id": "186b4c4c77985f75e7cefc48289e79ff","result": {"ip": "74.125.200.113","output": "35.223","node": {"id": 58,"as_number": 12345,"latitude": 22.280042521009999,"longitude": 114.1915512085,"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"}}}, {"id": "34ae843cf4d341b252a14e3d6b39281f","result": {"output": -1,"message": "100% packet loss","node": {"id": 208,"as_number": 23456,"latitude": 30.255360295637001,"longitude": 120.15712738037,"country": {"id": 62,"name": "China","continent": {"id": 2,"name": "Asia","iso": "AS"},"iso": "CN","iso_numeric": "156"},"city": "Hangzhou","sub_region": "Eastern Asia"}}}],"requested": "google.com","finished": true}`
114114
tr2 := &respondingTransport{resp: dummyResp(201, "GET", body)}
115115
c, err = newTestClient(tr2)
116116
if err != nil {
@@ -281,7 +281,7 @@ func TestDNSPerfOutput(t *testing.T) {
281281
finished bool
282282
}{
283283
"Incomplete": {&respondingTransport{resp: dummyResp(200, "GET", `{"id":"d1f2408ff","items":[{"id":"734df82","result":{"id":123,"message":"NO DATA"}}]}`)}, nil, false},
284-
"Complete": {&respondingTransport{resp: dummyResp(200, "GET", `{"id": "6938330049d86df74bb2d0c76f3479de","items": [{"id": "68d10bfb6a9c7f9c519d17df83bc389e","result": {"dnsServer": "8.8.8.8","output": "35","node": {"id": 5,"as_number": 23456,"latitude": 50.110781326572834,"longitude": 8.68984222412098,"country": {"id": 116,"name": "Germany","continent": {"id": 3,"name": "Europe","iso": "EU"},"iso": "DE","iso_numeric": "276"},"city": "Frankfurt","sub_region": "Western Europe"}}}],"requested": "google.com","finished": "true"}`)}, nil, true},
284+
"Complete": {&respondingTransport{resp: dummyResp(200, "GET", `{"id": "6938330049d86df74bb2d0c76f3479de","items": [{"id": "68d10bfb6a9c7f9c519d17df83bc389e","result": {"dnsServer": "8.8.8.8","output": "35","node": {"id": 5,"as_number": 23456,"latitude": 50.110781326572834,"longitude": 8.68984222412098,"country": {"id": 116,"name": "Germany","continent": {"id": 3,"name": "Europe","iso": "EU"},"iso": "DE","iso_numeric": "276"},"city": "Frankfurt","sub_region": "Western Europe"}}}],"requested": "google.com","finished": true}`)}, nil, true},
285285
}
286286
ctx := context.Background()
287287
for name, tc := range testCases {
@@ -366,7 +366,7 @@ func TestDNSResolveOutput(t *testing.T) {
366366
finished bool
367367
}{
368368
"Incomplete": {&respondingTransport{resp: dummyResp(200, "GET", `{"id":"d1f2408ff","items":[{"id":"734df82","result":{"id":123,"message":"NO DATA"}}]}`)}, nil, false},
369-
"Complete": {&respondingTransport{resp: dummyResp(200, "GET", `{"id": "66b78cfc643ea238e0fd8ab44f512657","items": [{"id": "ae3e8bcd0fbe77d6322b89371d87d96d","result": {"dnsServer": "8.8.8.8","output": "204.79.197.200\n13.107.21.200","node": {"id": 5,"as_number": 23456,"latitude": 50.110781326572834,"longitude": 8.68984222412098,"country": {"id": 116,"name": "Germany","continent": {"id": 3,"name": "Europe","iso": "EU"},"iso": "DE","iso_numeric": "276"},"city": "Frankfurt","sub_region": "Western Europe"}}}],"requested": "bing.com","finished": "true"}`)}, nil, true},
369+
"Complete": {&respondingTransport{resp: dummyResp(200, "GET", `{"id": "66b78cfc643ea238e0fd8ab44f512657","items": [{"id": "ae3e8bcd0fbe77d6322b89371d87d96d","result": {"dnsServer": "8.8.8.8","output": "204.79.197.200\n13.107.21.200","node": {"id": 5,"as_number": 23456,"latitude": 50.110781326572834,"longitude": 8.68984222412098,"country": {"id": 116,"name": "Germany","continent": {"id": 3,"name": "Europe","iso": "EU"},"iso": "DE","iso_numeric": "276"},"city": "Frankfurt","sub_region": "Western Europe"}}}],"requested": "bing.com","finished": true}`)}, nil, true},
370370
}
371371
ctx := context.Background()
372372
for name, tc := range testCases {
@@ -485,7 +485,7 @@ func TestCurlOutput(t *testing.T) {
485485
finished bool
486486
}{
487487
"Incomplete": {&respondingTransport{resp: dummyResp(200, "GET", `{"id":"d1f2408ff","items":[{"id":"734df82","result":{"id":123,"message":"NO DATA"}}]}`)}, nil, false},
488-
"Complete": {&respondingTransport{resp: dummyResp(200, "GET", `{"id": "9b8253c07b53b2db82b05475f9895f4e","items": [{"id": "99e4a2c3d6c8c7e36681515a2d2978e5","result": {"output": "HTTP/1.1 301 Moved Permanently\nContent-length: 0\nLocation: https://github.com/\n\n","node": {"id": 218,"as_number": 23456,"latitude": 49.09803738740174,"longitude": 12.484245300292855,"country": {"id": 116,"name": "Germany","continent": {"id": 3,"name": "Europe","iso": "EU"},"iso": "DE","iso_numeric": "276"},"city": "Falkenstein","sub_region": "Western Europe"}}}],"requested": "github.com","finished": "true"}`)}, nil, true},
488+
"Complete": {&respondingTransport{resp: dummyResp(200, "GET", `{"id": "9b8253c07b53b2db82b05475f9895f4e","items": [{"id": "99e4a2c3d6c8c7e36681515a2d2978e5","result": {"output": "HTTP/1.1 301 Moved Permanently\nContent-length: 0\nLocation: https://github.com/\n\n","node": {"id": 218,"as_number": 23456,"latitude": 49.09803738740174,"longitude": 12.484245300292855,"country": {"id": 116,"name": "Germany","continent": {"id": 3,"name": "Europe","iso": "EU"},"iso": "DE","iso_numeric": "276"},"city": "Falkenstein","sub_region": "Western Europe"}}}],"requested": "github.com","finished": true}`)}, nil, true},
489489
}
490490
ctx := context.Background()
491491
for name, tc := range testCases {
@@ -679,7 +679,7 @@ func TestDoGetRunOutput(t *testing.T) {
679679
finished bool
680680
}{
681681
"Incomplete": {&respondingTransport{resp: dummyResp(200, "GET", `{"id":"d1f2408ff","items":[{"id":"734df82","result":{"id":123,"message":"NO DATA"}}]}`)}, nil, false},
682-
"Complete": {&respondingTransport{resp: dummyResp(200, "GET", `{"id": "65d2bb722be16277e3fa8e8c86d3afb7","items": [{"id": "0981fcaf99f2c1b4a46a22cedb417347","result": {"output": "PING bing.com (204.79.197.200): 56 data bytes\n64 bytes from 204.79.197.200: icmp_seq=0 ttl=119 time=40.348 ms\n64 bytes from 204.79.197.200: icmp_seq=1 ttl=119 time=40.198 ms\n64 bytes from 204.79.197.200: icmp_seq=2 ttl=119 time=40.241 ms\n--- bing.com ping statistics ---\n3 packets transmitted, 3 packets received, 0% packet loss\nround-trip min/avg/max/stddev = 40.198/40.262/40.348/0.063 ms\n","node": {"id": 5,"as_number": 23456,"latitude": 50.110781326572834,"longitude": 8.68984222412098,"country": {"id": 116,"name": "Germany","continent": {"id": 3,"name": "Europe","iso": "EU"},"iso": "DE","iso_numeric": "276"},"city": "Frankfurt","sub_region": "Western Europe"}}}],"requested": "bing.com","finished": "true"}`)}, nil, true},
682+
"Complete": {&respondingTransport{resp: dummyResp(200, "GET", `{"id": "65d2bb722be16277e3fa8e8c86d3afb7","items": [{"id": "0981fcaf99f2c1b4a46a22cedb417347","result": {"output": "PING bing.com (204.79.197.200): 56 data bytes\n64 bytes from 204.79.197.200: icmp_seq=0 ttl=119 time=40.348 ms\n64 bytes from 204.79.197.200: icmp_seq=1 ttl=119 time=40.198 ms\n64 bytes from 204.79.197.200: icmp_seq=2 ttl=119 time=40.241 ms\n--- bing.com ping statistics ---\n3 packets transmitted, 3 packets received, 0% packet loss\nround-trip min/avg/max/stddev = 40.198/40.262/40.348/0.063 ms\n","node": {"id": 5,"as_number": 23456,"latitude": 50.110781326572834,"longitude": 8.68984222412098,"country": {"id": 116,"name": "Germany","continent": {"id": 3,"name": "Europe","iso": "EU"},"iso": "DE","iso_numeric": "276"},"city": "Frankfurt","sub_region": "Western Europe"}}}],"requested": "bing.com","finished": true}`)}, nil, true},
683683
}
684684
ctx := context.Background()
685685
for name, tc := range testCases {

0 commit comments

Comments
 (0)