-
Notifications
You must be signed in to change notification settings - Fork 6
/
execChangeContains_test.go
64 lines (49 loc) · 1.63 KB
/
execChangeContains_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestExecChangeContains(t *testing.T) {
file, err := createFile("asdf")
require.NoError(t, err)
require.NoError(t, execChangeContains(file.Name(), "sd", "ds"))
require.NoError(t, checkFileAndRemove("adsf"))
}
func TestExecChangeContainsRecursive(t *testing.T) {
fn, err := createNestedFoldersWithFiles("TestExecChangeContainsRecursive", "foo.txt", 5)
require.NoError(t, err)
defer removeNestedFolder("TestExecChangeContainsRecursive")
require.NoError(t, execChangeContains(fn, "oo", "xx"))
require.NoError(t, checkFileInNestedFolder("TestExecChangeContainsRecursive", "fxx.txt"))
}
func TestExecChangeContainsError(t *testing.T) {
require.Error(t, execChangeContains("", ".txt", ".ttt"))
}
func BenchmarkExecChangeContainsOneFile(b *testing.B) {
for i := 0; i < b.N; i++ {
file, _ := createFile("asdf")
_ = execChangeContains(file.Name(), "sd", "ds")
_ = checkFileAndRemove("adsf")
}
}
func BenchmarkExecChangeContainsDir(b *testing.B) {
for i := 0; i < b.N; i++ {
fn, _ := createNestedFoldersWithFiles("folder", "foo.txt", 10)
_ = execChangeContains(fn, "oo", "xx")
removeNestedFolder("folder")
}
}
func BenchmarkExecChangeContainsLotDir(b *testing.B) {
for i := 0; i < b.N; i++ {
fn, _ := createNestedFoldersWithFiles("folder", "foo.txt", 100)
_ = execChangeContains(fn, "oo", "xx")
removeNestedFolder("folder")
}
}
func BenchmarkExecChangeContainsManyDir(b *testing.B) {
for i := 0; i < b.N; i++ {
fn, _ := createNestedFoldersWithFiles("folder", "foo.txt", 1000)
_ = execChangeContains(fn, "oo", "xx")
removeNestedFolder("folder")
}
}