Skip to content

Commit a7b54a5

Browse files
committed
add test for CopyFile, fix lint
1 parent 37d517a commit a7b54a5

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

models/unittest/fscopy.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
15
package unittest
26

37
import (

modules/cache/cache_redis.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ func asString(v interface{}) string {
3939
default:
4040
panic("current redis cache doesn't support non-string data type")
4141
}
42-
return ""
4342
}
4443

4544
// Put puts value (string type) into cache with key and expire time.

modules/util/legacy_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,38 @@ package util
77
import (
88
"crypto/aes"
99
"crypto/rand"
10+
"fmt"
11+
"os"
1012
"testing"
13+
"time"
1114

1215
"github.com/stretchr/testify/assert"
1316
)
1417

18+
func TestCopyFile(t *testing.T) {
19+
testContent := []byte("hello")
20+
21+
tmpDir := os.TempDir()
22+
now := time.Now()
23+
srcFile := fmt.Sprintf("%s/copy-test-%d-src.txt", tmpDir, now.UnixMicro())
24+
dstFile := fmt.Sprintf("%s/copy-test-%d-dst.txt", tmpDir, now.UnixMicro())
25+
26+
_ = os.Remove(srcFile)
27+
_ = os.Remove(dstFile)
28+
defer func() {
29+
_ = os.Remove(srcFile)
30+
_ = os.Remove(dstFile)
31+
}()
32+
33+
err := os.WriteFile(srcFile, testContent, 0o777)
34+
assert.NoError(t, err)
35+
err = CopyFile(srcFile, dstFile)
36+
assert.NoError(t, err)
37+
dstContent, err := os.ReadFile(dstFile)
38+
assert.NoError(t, err)
39+
assert.Equal(t, testContent, dstContent)
40+
}
41+
1542
func TestAESGCM(t *testing.T) {
1643
t.Parallel()
1744

modules/util/string.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
15
package util
26

37
import "github.com/yuin/goldmark/util"

modules/util/string_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
15
package util
26

37
import (

0 commit comments

Comments
 (0)