Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
test upload+download after rename
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechampine committed Jan 5, 2017
1 parent 489117c commit 2f5d176
Showing 1 changed file with 40 additions and 24 deletions.
64 changes: 40 additions & 24 deletions api/renter_test.go
Expand Up @@ -7,6 +7,7 @@ import (
"strconv"
"strings"
"testing"
"time"

"github.com/NebulousLabs/Sia/build"
"github.com/NebulousLabs/Sia/crypto"
Expand Down Expand Up @@ -478,7 +479,7 @@ func TestRenterLoadNonexistent(t *testing.T) {
}

// TestRenterHandlerRename checks that valid /renter/rename calls are
// successful, and that invalid calls fail with the appropriate error.
// successful, and that invalid calls fail with the appropriate error.
func TestRenterHandlerRename(t *testing.T) {
if testing.Short() {
t.SkipNow()
Expand All @@ -501,6 +502,14 @@ func TestRenterHandlerRename(t *testing.T) {
t.Fatal(err)
}

// Try renaming a nonexistent file.
renameValues := url.Values{}
renameValues.Set("newsiapath", "newdne")
err = st.stdPostAPI("/renter/rename/dne", renameValues)
if err == nil || err.Error() != renter.ErrUnknownPath.Error() {
t.Errorf("expected error to be %v; got %v", renter.ErrUnknownPath, err)
}

// Set an allowance for the renter, allowing a contract to be formed.
allowanceValues := url.Values{}
allowanceValues.Set("funds", testFunds)
Expand All @@ -509,34 +518,18 @@ func TestRenterHandlerRename(t *testing.T) {
t.Fatal(err)
}

// Create two files.
// Create a file.
path1 := filepath.Join(st.dir, "test1.dat")
if err = createRandFile(path1, 512); err != nil {
t.Fatal(err)
}
path2 := filepath.Join(st.dir, "test2.dat")
if err = createRandFile(path2, 512); err != nil {
t.Fatal(err)
}

// Upload to host.
uploadValues := url.Values{}
uploadValues.Set("source", path1)
if err = st.stdPostAPI("/renter/upload/test1", uploadValues); err != nil {
t.Fatal(err)
}
uploadValues.Set("source", path2)
if err = st.stdPostAPI("/renter/upload/test2", uploadValues); err != nil {
t.Fatal(err)
}

// Try renaming to a name that's already taken.
renameValues := url.Values{}
renameValues.Set("newsiapath", "test1")
err = st.stdPostAPI("/renter/rename/test2", renameValues)
if err == nil || err.Error() != renter.ErrPathOverload.Error() {
t.Errorf("expected error to be %v; got %v", renter.ErrPathOverload, err)
}

// Try renaming to an empty string.
renameValues.Set("newsiapath", "")
Expand All @@ -545,17 +538,40 @@ func TestRenterHandlerRename(t *testing.T) {
t.Fatalf("expected error to be %v; got %v", renter.ErrEmptyFilename, err)
}

// Rename the first file.
// Rename the file.
renameValues.Set("newsiapath", "newtest1")
if err = st.stdPostAPI("/renter/rename/test1", renameValues); err != nil {
t.Fatal(err)
}

// Try renaming a nonexistent file.
renameValues.Set("newsiapath", "newdne")
err = st.stdPostAPI("/renter/rename/dne", renameValues)
if err == nil || err.Error() != renter.ErrUnknownPath.Error() {
t.Errorf("expected error to be %v; got %v", renter.ErrUnknownPath, err)
// Should be able to continue uploading and downloading using the new name.
var rf RenterFiles
for i := 0; i < 200 && (len(rf.Files) != 1 || rf.Files[0].UploadProgress < 10); i++ {
st.getAPI("/renter/files", &rf)
time.Sleep(100 * time.Millisecond)
}
if len(rf.Files) != 1 || rf.Files[0].UploadProgress < 10 {
t.Fatal("upload is not succeeding:", rf.Files[0])
}
err = st.stdGetAPI("/renter/download/newtest1?destination=" + filepath.Join(st.dir, "testdown2.dat"))
if err != nil {
t.Fatal(err)
}

// Create and upload another file.
path2 := filepath.Join(st.dir, "test2.dat")
if err = createRandFile(path2, 512); err != nil {
t.Fatal(err)
}
uploadValues.Set("source", path2)
if err = st.stdPostAPI("/renter/upload/test2", uploadValues); err != nil {
t.Fatal(err)
}
// Try renaming to a name that's already taken.
renameValues.Set("newsiapath", "newtest1")
err = st.stdPostAPI("/renter/rename/test2", renameValues)
if err == nil || err.Error() != renter.ErrPathOverload.Error() {
t.Errorf("expected error to be %v; got %v", renter.ErrPathOverload, err)
}
}

Expand Down

0 comments on commit 2f5d176

Please sign in to comment.