| 1 |
/* |
| 2 |
Copyright 2017 The Kubernetes Authors. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package temptest |
| 18 |
|
| 19 |
import ( |
| 20 |
"io" |
| 21 |
"testing" |
| 22 |
) |
| 23 |
|
| 24 |
func TestFakeDir(t *testing.T) { |
| 25 |
d := &FakeDir{} |
| 26 |
|
| 27 |
f, err := d.NewFile("ONE") |
| 28 |
if err != nil { |
| 29 |
t.Fatal(err) |
| 30 |
} |
| 31 |
|
| 32 |
n, err := io.WriteString(f, "Bonjour!") |
| 33 |
if n != 8 || err != nil { |
| 34 |
t.Fatalf( |
| 35 |
`WriteString(f, "Bonjour!") = (%v, %v), expected (%v, %v)`, |
| 36 |
n, err, |
| 37 |
0, nil, |
| 38 |
) |
| 39 |
} |
| 40 |
if got := d.Files["ONE"].Buffer.String(); got != "Bonjour!" { |
| 41 |
t.Fatalf(`file content is %q, expected "Bonjour!"`, got) |
| 42 |
} |
| 43 |
|
| 44 |
_, err = d.NewFile("ONE") |
| 45 |
if err == nil { |
| 46 |
t.Fatal("Same file could be created twice.") |
| 47 |
} |
| 48 |
|
| 49 |
err = d.Delete() |
| 50 |
if err != nil { |
| 51 |
t.Fatal(err) |
| 52 |
} |
| 53 |
|
| 54 |
err = d.Delete() |
| 55 |
if err == nil { |
| 56 |
t.Fatal("FakeDir could be deleted twice.") |
| 57 |
} |
| 58 |
|
| 59 |
_, err = d.NewFile("TWO") |
| 60 |
if err == nil { |
| 61 |
t.Fatal("NewFile could be created in deleted dir") |
| 62 |
} |
| 63 |
|
| 64 |
if !d.Deleted { |
| 65 |
t.Fatal("FakeDir should be deleted.") |
| 66 |
} |
| 67 |
} |