forked from NYANDEV/forgejo
8195ba06d5
- Add the experimental [deacode](https://pkg.go.dev/golang.org/x/tools/internal/cmd/deadcode) linter to Forgejo. - To deal with false positives that can happen due to build tags or with code that's currently only referenced by test code, the output of the tool is compared against a known-good output. - This commit doesn't make any attempt to remove any deadcode. (cherry picked from commit ac462279e9361070326d512fc209b6f148f27865) (cherry picked from commitb5ea6e85ac
) (cherry picked from commit5915f3643c
) [CLEANUP] Remove deadcode - This is deadcode since https://codeberg.org/forgejo/forgejo/pulls/1802 removed the usage of it. (cherry picked from commit d840b9923e1a7aad7306c6b4d02df771ed0f40f4) (cherry picked from commit 9442bab6266807141a14a647d3bc383233fc56e9) (cherry picked from commit 0de9d18863c6af44941c7021548cdb07173ba3c0) (cherry picked from commit 26abf783746ef29e66eea966160e2f9c139add26) (cherry picked from commit 05d3a143c3785f3cc5e7f561aa2ad2ba556b55cc) (cherry picked from commit 4b3d38d5e15b0fd02839d5687b634e7999e12666) (cherry picked from commit a726e7198613b330a58c8c6dfc8866c360fbe555) (cherry picked from commit cb62ae5b9885bcd5c2b6cb60f0e9cce6a991cc3c)
37 lines
812 B
Go
37 lines
812 B
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package util
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCopyFile(t *testing.T) {
|
|
testContent := []byte("hello")
|
|
|
|
tmpDir := os.TempDir()
|
|
now := time.Now()
|
|
srcFile := fmt.Sprintf("%s/copy-test-%d-src.txt", tmpDir, now.UnixMicro())
|
|
dstFile := fmt.Sprintf("%s/copy-test-%d-dst.txt", tmpDir, now.UnixMicro())
|
|
|
|
_ = os.Remove(srcFile)
|
|
_ = os.Remove(dstFile)
|
|
defer func() {
|
|
_ = os.Remove(srcFile)
|
|
_ = os.Remove(dstFile)
|
|
}()
|
|
|
|
err := os.WriteFile(srcFile, testContent, 0o777)
|
|
assert.NoError(t, err)
|
|
err = CopyFile(srcFile, dstFile)
|
|
assert.NoError(t, err)
|
|
dstContent, err := os.ReadFile(dstFile)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, testContent, dstContent)
|
|
}
|