| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package local | 5 package local |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "io/ioutil" | 8 "io/ioutil" |
| 9 "os" | 9 "os" |
| 10 "path/filepath" | 10 "path/filepath" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 fs := tempFileSystem() | 115 fs := tempFileSystem() |
| 116 fs.write("a/b/c", "something") | 116 fs.write("a/b/c", "something") |
| 117 So(fs.EnsureSymlink(fs.join("a"), "target"), ShouldBeNil) | 117 So(fs.EnsureSymlink(fs.join("a"), "target"), ShouldBeNil) |
| 118 So(fs.readLink("a"), ShouldEqual, "target") | 118 So(fs.readLink("a"), ShouldEqual, "target") |
| 119 }) | 119 }) |
| 120 } | 120 } |
| 121 | 121 |
| 122 func TestEnsureFile(t *testing.T) { | 122 func TestEnsureFile(t *testing.T) { |
| 123 Convey("EnsureFile checks root", t, func() { | 123 Convey("EnsureFile checks root", t, func() { |
| 124 fs := tempFileSystem() | 124 fs := tempFileSystem() |
| 125 » » So(fs.EnsureFile(fs.join(".."), strings.NewReader("blah")), Shou
ldNotBeNil) | 125 » » So(EnsureFile(fs, fs.join(".."), strings.NewReader("blah")), Sho
uldNotBeNil) |
| 126 }) | 126 }) |
| 127 | 127 |
| 128 Convey("EnsureFile creates new file", t, func() { | 128 Convey("EnsureFile creates new file", t, func() { |
| 129 fs := tempFileSystem() | 129 fs := tempFileSystem() |
| 130 » » So(fs.EnsureFile(fs.join("name"), strings.NewReader("blah")), Sh
ouldBeNil) | 130 » » So(EnsureFile(fs, fs.join("name"), strings.NewReader("blah")), S
houldBeNil) |
| 131 So(fs.read("name"), ShouldEqual, "blah") | 131 So(fs.read("name"), ShouldEqual, "blah") |
| 132 }) | 132 }) |
| 133 | 133 |
| 134 Convey("EnsureFile builds full path", t, func() { | 134 Convey("EnsureFile builds full path", t, func() { |
| 135 fs := tempFileSystem() | 135 fs := tempFileSystem() |
| 136 » » So(fs.EnsureFile(fs.join("a/b/c"), strings.NewReader("blah")), S
houldBeNil) | 136 » » So(EnsureFile(fs, fs.join("a/b/c"), strings.NewReader("blah")),
ShouldBeNil) |
| 137 So(fs.read("a/b/c"), ShouldEqual, "blah") | 137 So(fs.read("a/b/c"), ShouldEqual, "blah") |
| 138 }) | 138 }) |
| 139 | 139 |
| 140 if runtime.GOOS != "windows" { | 140 if runtime.GOOS != "windows" { |
| 141 Convey("EnsureFile replaces existing symlink", t, func() { | 141 Convey("EnsureFile replaces existing symlink", t, func() { |
| 142 fs := tempFileSystem() | 142 fs := tempFileSystem() |
| 143 So(fs.EnsureSymlink(fs.join("path"), "target"), ShouldBe
Nil) | 143 So(fs.EnsureSymlink(fs.join("path"), "target"), ShouldBe
Nil) |
| 144 » » » So(fs.EnsureFile(fs.join("path"), strings.NewReader("bla
h")), ShouldBeNil) | 144 » » » So(EnsureFile(fs, fs.join("path"), strings.NewReader("bl
ah")), ShouldBeNil) |
| 145 So(fs.read("path"), ShouldEqual, "blah") | 145 So(fs.read("path"), ShouldEqual, "blah") |
| 146 }) | 146 }) |
| 147 } | 147 } |
| 148 | 148 |
| 149 Convey("EnsureFile replaces existing file", t, func() { | 149 Convey("EnsureFile replaces existing file", t, func() { |
| 150 fs := tempFileSystem() | 150 fs := tempFileSystem() |
| 151 » » So(fs.EnsureFile(fs.join("path"), strings.NewReader("huh")), Sho
uldBeNil) | 151 » » So(EnsureFile(fs, fs.join("path"), strings.NewReader("huh")), Sh
ouldBeNil) |
| 152 » » So(fs.EnsureFile(fs.join("path"), strings.NewReader("blah")), Sh
ouldBeNil) | 152 » » So(EnsureFile(fs, fs.join("path"), strings.NewReader("blah")), S
houldBeNil) |
| 153 So(fs.read("path"), ShouldEqual, "blah") | 153 So(fs.read("path"), ShouldEqual, "blah") |
| 154 }) | 154 }) |
| 155 | 155 |
| 156 Convey("EnsureFile replaces existing directory", t, func() { | 156 Convey("EnsureFile replaces existing directory", t, func() { |
| 157 fs := tempFileSystem() | 157 fs := tempFileSystem() |
| 158 fs.write("a/b/c", "something") | 158 fs.write("a/b/c", "something") |
| 159 » » So(fs.EnsureFile(fs.join("a"), strings.NewReader("blah")), Shoul
dBeNil) | 159 » » So(EnsureFile(fs, fs.join("a"), strings.NewReader("blah")), Shou
ldBeNil) |
| 160 So(fs.read("a"), ShouldEqual, "blah") | 160 So(fs.read("a"), ShouldEqual, "blah") |
| 161 }) | 161 }) |
| 162 } | 162 } |
| 163 | 163 |
| 164 func TestEnsureFileGone(t *testing.T) { | 164 func TestEnsureFileGone(t *testing.T) { |
| 165 Convey("EnsureFileGone checks root", t, func() { | 165 Convey("EnsureFileGone checks root", t, func() { |
| 166 fs := tempFileSystem() | 166 fs := tempFileSystem() |
| 167 So(fs.EnsureFileGone(fs.join("../abc")), ShouldNotBeNil) | 167 So(fs.EnsureFileGone(fs.join("../abc")), ShouldNotBeNil) |
| 168 }) | 168 }) |
| 169 | 169 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 357 |
| 358 // isFile returns true if a file at a given slash separated path relative to | 358 // isFile returns true if a file at a given slash separated path relative to |
| 359 // Root() is a file (not a directory). | 359 // Root() is a file (not a directory). |
| 360 func (f *tempFileSystemImpl) isFile(rel string) bool { | 360 func (f *tempFileSystemImpl) isFile(rel string) bool { |
| 361 stat, err := os.Stat(f.join(rel)) | 361 stat, err := os.Stat(f.join(rel)) |
| 362 if err != nil { | 362 if err != nil { |
| 363 return false | 363 return false |
| 364 } | 364 } |
| 365 return !stat.IsDir() | 365 return !stat.IsDir() |
| 366 } | 366 } |
| OLD | NEW |