Skip to content

Commit

Permalink
go/oasis-test-runner/scenario/e2e: Update parsing in listRuntimes()
Browse files Browse the repository at this point in the history
Use json.Decoder to be able to parse Concatenated JSON streams rather
than just Line-delimited JSON streams.
  • Loading branch information
tjanez committed Sep 22, 2021
1 parent 84712b1 commit 2133944
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions go/oasis-test-runner/scenario/e2e/registry_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"os"
Expand Down Expand Up @@ -751,17 +752,14 @@ func (sc *registryCLIImpl) listRuntimes(childEnv *env.Env, includeSuspended bool
if err != nil {
return nil, fmt.Errorf("failed to list runtimes: error: %w output: %s", err, out.String())
}
runtimesStr := strings.Split(out.String(), "\n")

dec := json.NewDecoder(bytes.NewReader(out.Bytes()))
runtimes := map[common.Namespace]registry.Runtime{}
for _, rtStr := range runtimesStr {
// Ignore last newline.
if rtStr == "" {
continue
}

for {
var rt registry.Runtime
if err = json.Unmarshal([]byte(rtStr), &rt); err != nil {
if err = dec.Decode(&rt); err == io.EOF {
break
} else if err != nil {
return nil, err
}
runtimes[rt.ID] = rt
Expand Down

0 comments on commit 2133944

Please sign in to comment.