diff options
author | Janoš Guljaš <janos@users.noreply.github.com> | 2018-08-10 22:12:55 +0800 |
---|---|---|
committer | Balint Gabor <balint.g@gmail.com> | 2018-08-10 22:12:55 +0800 |
commit | 6d1e292eefa70b5cb76cd03ff61fc6c4550d7c36 (patch) | |
tree | 3bcd5ab444bd7486a9011656c85baeee00216286 /cmd/swarm/upload_test.go | |
parent | 3ec5dda4d2dd0dec6d5bd465752f30e8f6ce208c (diff) | |
download | dexon-6d1e292eefa70b5cb76cd03ff61fc6c4550d7c36.tar.gz dexon-6d1e292eefa70b5cb76cd03ff61fc6c4550d7c36.tar.zst dexon-6d1e292eefa70b5cb76cd03ff61fc6c4550d7c36.zip |
Manifest cli fix and upload defaultpath only once (#17375)
* cmd/swarm: fix manifest subcommands and add tests
* cmd/swarm: manifest update: update default entry for non-encrypted uploads
* swarm/api: upload defaultpath file only once
* swarm/api/client: improve UploadDirectory default path handling
* cmd/swarm: support absolute and relative default path values
* cmd/swarm: fix a typo in test
* cmd/swarm: check encrypted uploads in manifest update tests
Diffstat (limited to 'cmd/swarm/upload_test.go')
-rw-r--r-- | cmd/swarm/upload_test.go | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/cmd/swarm/upload_test.go b/cmd/swarm/upload_test.go index 2afc9b3a1..c3199dadc 100644 --- a/cmd/swarm/upload_test.go +++ b/cmd/swarm/upload_test.go @@ -273,3 +273,84 @@ func testCLISwarmUpRecursive(toEncrypt bool, t *testing.T) { } } } + +// TestCLISwarmUpDefaultPath tests swarm recursive upload with relative and absolute +// default paths and with encryption. +func TestCLISwarmUpDefaultPath(t *testing.T) { + testCLISwarmUpDefaultPath(false, false, t) + testCLISwarmUpDefaultPath(false, true, t) + testCLISwarmUpDefaultPath(true, false, t) + testCLISwarmUpDefaultPath(true, true, t) +} + +func testCLISwarmUpDefaultPath(toEncrypt bool, absDefaultPath bool, t *testing.T) { + cluster := newTestCluster(t, 1) + defer cluster.Shutdown() + + tmp, err := ioutil.TempDir("", "swarm-defaultpath-test") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmp) + + err = ioutil.WriteFile(filepath.Join(tmp, "index.html"), []byte("<h1>Test</h1>"), 0666) + if err != nil { + t.Fatal(err) + } + err = ioutil.WriteFile(filepath.Join(tmp, "robots.txt"), []byte("Disallow: /"), 0666) + if err != nil { + t.Fatal(err) + } + + defaultPath := "index.html" + if absDefaultPath { + defaultPath = filepath.Join(tmp, defaultPath) + } + + args := []string{ + "--bzzapi", + cluster.Nodes[0].URL, + "--recursive", + "--defaultpath", + defaultPath, + "up", + tmp, + } + if toEncrypt { + args = append(args, "--encrypt") + } + + up := runSwarm(t, args...) + hashRegexp := `[a-f\d]{64,128}` + _, matches := up.ExpectRegexp(hashRegexp) + up.ExpectExit() + hash := matches[0] + + client := swarm.NewClient(cluster.Nodes[0].URL) + + m, isEncrypted, err := client.DownloadManifest(hash) + if err != nil { + t.Fatal(err) + } + + if toEncrypt != isEncrypted { + t.Error("downloaded manifest is not encrypted") + } + + var found bool + var entriesCount int + for _, e := range m.Entries { + entriesCount++ + if e.Path == "" { + found = true + } + } + + if !found { + t.Error("manifest default entry was not found") + } + + if entriesCount != 3 { + t.Errorf("manifest contains %v entries, expected %v", entriesCount, 3) + } +} |