From 34daf0559dc5059ce0af443e3f22b77ec02b4c2b Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Wed, 28 Mar 2018 13:51:16 +0200 Subject: [PATCH 1/2] cmd/swarm: enable testcliswarmup --- cmd/swarm/upload_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmd/swarm/upload_test.go b/cmd/swarm/upload_test.go index c450752f2a..df7fc216af 100644 --- a/cmd/swarm/upload_test.go +++ b/cmd/swarm/upload_test.go @@ -27,8 +27,6 @@ import ( // TestCLISwarmUp tests that running 'swarm up' makes the resulting file // available from all nodes via the HTTP API func TestCLISwarmUp(t *testing.T) { - // temporarily disable to make travis green - t.Skip() // start 3 node cluster t.Log("starting 3 node cluster") cluster := newTestCluster(t, 3) From c59b61824e9df6dc5bfd526e2c8b8327f348ed04 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Thu, 29 Mar 2018 20:46:42 +0200 Subject: [PATCH 2/2] cmd/swarm: get rid of assertNil and only once used method --- cmd/swarm/upload_test.go | 57 ++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/cmd/swarm/upload_test.go b/cmd/swarm/upload_test.go index df7fc216af..2bb601bdcb 100644 --- a/cmd/swarm/upload_test.go +++ b/cmd/swarm/upload_test.go @@ -22,55 +22,60 @@ import ( "net/http" "os" "testing" + + "github.com/ethereum/go-ethereum/log" ) // TestCLISwarmUp tests that running 'swarm up' makes the resulting file // available from all nodes via the HTTP API func TestCLISwarmUp(t *testing.T) { - // start 3 node cluster - t.Log("starting 3 node cluster") + log.Info("starting 3 node cluster") cluster := newTestCluster(t, 3) defer cluster.Shutdown() // create a tmp file tmp, err := ioutil.TempFile("", "swarm-test") - assertNil(t, err) + if err != nil { + t.Fatal(err) + } defer tmp.Close() defer os.Remove(tmp.Name()) - _, err = io.WriteString(tmp, "data") - assertNil(t, err) + + // write data to file + data := "randomdata" + _, err = io.WriteString(tmp, data) + if err != nil { + t.Fatal(err) + } // upload the file with 'swarm up' and expect a hash - t.Log("uploading file with 'swarm up'") + log.Info("uploading file with 'swarm up'") up := runSwarm(t, "--bzzapi", cluster.Nodes[0].URL, "up", tmp.Name()) _, matches := up.ExpectRegexp(`[a-f\d]{64}`) up.ExpectExit() hash := matches[0] - t.Logf("file uploaded with hash %s", hash) + log.Info("file uploaded", "hash", hash) // get the file from the HTTP API of each node for _, node := range cluster.Nodes { - t.Logf("getting file from %s", node.Name) + log.Info("getting file from node", "node", node.Name) + res, err := http.Get(node.URL + "/bzz:/" + hash) - assertNil(t, err) - assertHTTPResponse(t, res, http.StatusOK, "data") - } -} + if err != nil { + t.Fatal(err) + } -func assertNil(t *testing.T, err error) { - if err != nil { - t.Fatal(err) - } -} + if res.StatusCode != 200 { + t.Fatalf("expected HTTP status %d, got %s", 200, res.Status) + } -func assertHTTPResponse(t *testing.T, res *http.Response, expectedStatus int, expectedBody string) { - defer res.Body.Close() - if res.StatusCode != expectedStatus { - t.Fatalf("expected HTTP status %d, got %s", expectedStatus, res.Status) - } - data, err := ioutil.ReadAll(res.Body) - assertNil(t, err) - if string(data) != expectedBody { - t.Fatalf("expected HTTP body %q, got %q", expectedBody, data) + reply, err := ioutil.ReadAll(res.Body) + defer res.Body.Close() + if err != nil { + t.Fatal(err) + } + if string(reply) != data { + t.Fatalf("expected HTTP body %q, got %q", data, reply) + } } }