Skip to content

Commit

Permalink
add test for CopyFile, fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Apr 1, 2022
1 parent 37d517a commit a7b54a5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
4 changes: 4 additions & 0 deletions models/unittest/fscopy.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package unittest

import (
Expand Down
1 change: 0 additions & 1 deletion modules/cache/cache_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func asString(v interface{}) string {
default:
panic("current redis cache doesn't support non-string data type")
}
return ""
}

// Put puts value (string type) into cache with key and expire time.
Expand Down
27 changes: 27 additions & 0 deletions modules/util/legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,38 @@ package util
import (
"crypto/aes"
"crypto/rand"
"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)
}

func TestAESGCM(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 4 additions & 0 deletions modules/util/string.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package util

import "github.com/yuin/goldmark/util"
Expand Down
4 changes: 4 additions & 0 deletions modules/util/string_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package util

import (
Expand Down

0 comments on commit a7b54a5

Please sign in to comment.