fix webdav tests

This commit is contained in:
adphi 2019-07-20 23:37:16 +02:00
parent 535664608a
commit f3a7e601b4
2 changed files with 42 additions and 9 deletions

3
go.sum
View File

@ -39,9 +39,11 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGi
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/koron/iferr v0.0.0-20180615142939-bb332a3b1d91 h1:hunjgdb3b21ZdRmzDPXii0EcnHpjH7uCP+kODoE1JH0=
github.com/koron/iferr v0.0.0-20180615142939-bb332a3b1d91/go.mod h1:C2tFh8w3I6i4lnUJfoBx2Hwku3mgu4wPNTtUNp1i5KI=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/levigross/grequests v0.0.0-20171009010347-bf9788368aa0 h1:QpdhtrR7SX3R7OlEv9dZarsXogM3PM/tl1ibRH/eHbQ=
github.com/levigross/grequests v0.0.0-20171009010347-bf9788368aa0/go.mod h1:uCZIhROSrVmuF/BPYFPwDeiiQ6juSLp0kikFoEcNcEs=
@ -99,6 +101,7 @@ gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c h1:vT
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c/go.mod h1:3HH7i1SgMqlzxCcBmUHW657sD4Kvv9sC3HpL3YukzwA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=

View File

@ -2,6 +2,7 @@ package gonextcloud
import (
"os"
"sort"
"strings"
"testing"
@ -12,9 +13,21 @@ import (
)
var (
dir string
wd types.WebDav
dir string
wd types.WebDav
folders = []string{
"folder1",
"folder1/sub1",
"folder1/sub1/ssub1",
"folder1/sub2",
"folder1/sub2/ssub1",
"folder1/sub2/ssub2",
"folder2",
"folder2/sub2",
"folder2/sub3",
"folder2/sub3/ssub1",
"folder2/sub4",
}
wtests = []struct {
name string
test test
@ -23,6 +36,10 @@ var (
name: "CreateFolder",
test: testCreateFolder,
},
{
name: "TestCreateSubFolders",
test: testCreateSubFolders,
},
{
name: "TestStat",
test: testStat,
@ -52,7 +69,7 @@ func TestWebDav(t *testing.T) {
}
}
func testCreateFolder(t *testing.T){
func testCreateFolder(t *testing.T) {
err := wd.Mkdir(dir, 0777)
require.NoError(t, err)
}
@ -65,24 +82,37 @@ func testStat(t *testing.T) {
assert.True(t, i.IsDir())
}
func testCreateSubFolders(t *testing.T) {
sort.Strings(folders)
d := strings.TrimRight(dir, "/")
var ds []string
ds = append(ds, d)
for _, f := range folders {
p := d + "/" + f
err := wd.MkdirAll(p, 0777)
assert.NoError(t, err)
ds = append(ds, p)
}
folders = ds
}
func testWalk(t *testing.T) {
found := false
err := wd.Walk("/", func(path string, info os.FileInfo, err error) error {
err := wd.Walk(dir, func(path string, info os.FileInfo, err error) error {
path = strings.Trim(path, "/")
assert.NoError(t, err)
// TODO : find a solution for info.Name() on directories
if path == dir {
found = true
return nil
}
p := strings.Split(path, "/")
assert.Equal(t, p[len(p)-1], info.Name())
assert.Contains(t, folders, path)
return nil
})
assert.NoError(t, err)
assert.True(t, found)
}
func testDelete(t *testing.T) {
err := wd.Remove(dir)
require.NoError(t, err)
}