fileutil.go 517 B

123456789101112131415161718192021222324252627282930
  1. // Copyright (c) 2015 Arista Networks, Inc.
  2. // Use of this source code is governed by the Apache License 2.0
  3. // that can be found in the COPYING file.
  4. package test
  5. import (
  6. "io"
  7. "os"
  8. "testing"
  9. )
  10. // CopyFile copies a file
  11. func CopyFile(t *testing.T, srcPath, dstPath string) {
  12. src, err := os.Open(srcPath)
  13. if err != nil {
  14. t.Fatal(err)
  15. }
  16. defer src.Close()
  17. dst, err := os.Create(dstPath)
  18. if err != nil {
  19. t.Fatal(err)
  20. }
  21. defer dst.Close()
  22. _, err = io.Copy(dst, src)
  23. if err != nil {
  24. t.Fatal(err)
  25. }
  26. }