This repository has been archived by the owner on Jun 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/util/walkers: refactor CopyWalker and add some tests
So at least some changes to this function can be easily tested. Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
- Loading branch information
Showing
2 changed files
with
55 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package walkers | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"reflect" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
const ( | ||
tmpPattern = "lokomotive-test" | ||
testData = "222" | ||
) | ||
|
||
func TestWriteFile(t *testing.T) { | ||
f, err := ioutil.TempFile("", tmpPattern) | ||
if err != nil { | ||
t.Fatalf("Creating temp file should succeed, got: %v", err) | ||
} | ||
|
||
defer os.Remove(f.Name()) | ||
|
||
if err := writeFile(f.Name(), strings.NewReader(testData)); err != nil { | ||
t.Fatalf("Writing to file should succeed, got: %v", err) | ||
} | ||
|
||
d, err := ioutil.ReadFile(f.Name()) | ||
if err != nil { | ||
t.Fatalf("Reading tmp file should succeed, got: %v", err) | ||
} | ||
|
||
if !reflect.DeepEqual(testData, string(d)) { | ||
t.Fatalf("expected: '%s', got '%s'", testData, string(d)) | ||
} | ||
} |