| 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 TestFakeFile(t *testing.T) { |
| 25 |
f := &FakeFile{} |
| 26 |
|
| 27 |
n, err := io.WriteString(f, "Bonjour!") |
| 28 |
if n != 8 || err != nil { |
| 29 |
t.Fatalf( |
| 30 |
`WriteString(f, "Bonjour!") = (%v, %v), expected (%v, %v)`, |
| 31 |
n, err, |
| 32 |
8, nil, |
| 33 |
) |
| 34 |
} |
| 35 |
|
| 36 |
err = f.Close() |
| 37 |
if err != nil { |
| 38 |
t.Fatal(err) |
| 39 |
} |
| 40 |
|
| 41 |
// File can't be closed twice. |
| 42 |
err = f.Close() |
| 43 |
if err == nil { |
| 44 |
t.Fatal("FakeFile could be closed twice") |
| 45 |
} |
| 46 |
|
| 47 |
// File is not writable after close. |
| 48 |
n, err = io.WriteString(f, "Bonjour!") |
| 49 |
if n != 0 || err == nil { |
| 50 |
t.Fatalf( |
| 51 |
`WriteString(f, "Bonjour!") = (%v, %v), expected (%v, %v)`, |
| 52 |
n, err, |
| 53 |
0, "non-nil", |
| 54 |
) |
| 55 |
} |
| 56 |
} |