Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions acceptance.tests
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,17 @@ RUN -v
END

NAME walk
GOOS linux
RUN walk -R --include *.sh docs/
docs/install.sh
STDERR
Found 1 path(s), 30 excluded
END

NAME walk windows
GOOS windows
RUN walk -R --include *.sh docs/
docs\install.sh
STDERR
Found 1 path(s), 30 excluded
END
3 changes: 2 additions & 1 deletion cmd/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"os"
"path/filepath"
"testing"

"github.com/zix99/rare/cmd/helpers"
Expand All @@ -28,7 +29,7 @@ func TestSarch(t *testing.T) {
func TestSearchOutput(t *testing.T) {
out, eout, err := testCommandCapture(searchCommand(), `last testdata/*.txt`)
assert.NoError(t, err)
assert.Equal(t, "testdata/log.txt 3: 5 is the last\n", out)
assert.Equal(t, filepath.Join("testdata", "log.txt")+" 3: 5 is the last\n", out)
assert.Equal(t, "Read : 5 file(s) (9.41 KB)\nMatched: 1 / 76\n", eout)
}

Expand Down
1 change: 1 addition & 0 deletions cmd/testdata/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.txt text eol=lf
5 changes: 3 additions & 2 deletions cmd/walk_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -16,13 +17,13 @@ func TestEmptyWalkCommand(t *testing.T) {
func TestWalkTestDataGlob(t *testing.T) {
o, e, err := testCommandCapture(walkCommand(), "testdata/*.gz")
assert.NoError(t, err)
assert.Equal(t, "testdata/log.txt.gz\n", o)
assert.Equal(t, filepath.Join("testdata", "log.txt.gz")+"\n", o)
assert.Equal(t, "Found 1 path(s)\n", e)
}

func TestWalkTestDataRecursive(t *testing.T) {
o, e, err := testCommandCapture(walkCommand(), "-R testdata/")
assert.NoError(t, err)
assert.Contains(t, o, "log.txt")
assert.Equal(t, "Found 6 path(s)\n", e)
assert.Equal(t, "Found 7 path(s)\n", e)
}
3 changes: 3 additions & 0 deletions pkg/extractor/batchers/tailBatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/zix99/rare/pkg/testutil"
)

func TestBatchFollowFile(t *testing.T) {
Expand All @@ -21,6 +22,8 @@ func TestBatchFollowFile(t *testing.T) {
}

func TestBatchFollowTailFile(t *testing.T) {
testutil.SkipWindows(t) // Not working right now

tmp, err := os.CreateTemp("", "followtest-")
if err != nil {
panic(err)
Expand Down
11 changes: 11 additions & 0 deletions pkg/extractor/dirwalk/globExpand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/zix99/rare/pkg/extractor/dirwalk/pathmatch"
"github.com/zix99/rare/pkg/testutil"
)

/*
Expand Down Expand Up @@ -165,6 +166,8 @@ func TestRecurseExcludeDir(t *testing.T) {
}

func TestRecurseWithSymFile(t *testing.T) {
testutil.SkipWindows(t) // git symlinks don't work quite right on windows

walk := Walker{
Recursive: true,
ListSymLinks: true,
Expand All @@ -191,6 +194,8 @@ func TestRecursiveWithSymFileIgnore(t *testing.T) {
}

func TestRecurseWithSymDir(t *testing.T) {
testutil.SkipWindows(t) // git symlinks don't work quite right on windows

p := setupTestDir(t)

walk := Walker{
Expand Down Expand Up @@ -220,6 +225,8 @@ func TestRecurseDoesntIdentifyDirAsFile(t *testing.T) {
}

func TestNoInfiniteRecursion(t *testing.T) {
testutil.SkipWindows(t)

p := setupTestDir(t)
os.Symlink("./", p+"/recursive")
os.Symlink(p, p+"/recursive2")
Expand Down Expand Up @@ -257,6 +264,8 @@ func TestNoMountTraverseWithSymlink(t *testing.T) {
}

func TestExcludeSymDir(t *testing.T) {
testutil.SkipWindows(t)

p := setupTestDir(t)

hadError := false
Expand All @@ -274,6 +283,8 @@ func TestExcludeSymDir(t *testing.T) {
}

func TestNoDoubleTraverseSymlink(t *testing.T) {
testutil.SkipWindows(t)

p := setupTestDir(t)
op := t.TempDir()
os.WriteFile(op+"/opfile", []byte("hello"), 0644)
Expand Down
17 changes: 12 additions & 5 deletions pkg/followreader/followreader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/zix99/rare/pkg/testutil"
)

// reads data and asserts all reads successful
Expand Down Expand Up @@ -87,21 +88,27 @@ func (s *testAppendingFile) Stop() {
}
}

// Close and stop writing to the file
func (s *testAppendingFile) Close() {
// Stop writing and close f
func (s *testAppendingFile) CloseFile() {
s.Stop()
err := s.f.Close()
if err != nil {
if err := s.f.Close(); err != nil {
panic(err)
}
}

err = os.Remove(s.f.Name())
// Close and stop writing to the file and cleanup
func (s *testAppendingFile) Close() {
s.CloseFile()

err := os.Remove(s.f.Name())
if err != nil {
panic(err)
}
}

func TestFollowReaderNew(t *testing.T) {
testutil.SkipWindows(t)

af := CreateAppendingTempFile()
defer af.Close()

Expand Down
15 changes: 15 additions & 0 deletions pkg/followreader/notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/zix99/rare/pkg/testutil"
)

func TestSimpleFileNotifyTail(t *testing.T) {
testutil.SkipWindows(t) // fsnotify not working, separate issue

af := CreateAppendingTempFile()
defer af.Close()

Expand All @@ -25,6 +28,8 @@ func TestSimpleFileNotifyTail(t *testing.T) {
}

func TestTailNotifyFileAppendingExisting(t *testing.T) {
testutil.SkipWindows(t) // fsnotify not working, separate issue

af := CreateAppendingTempFile()

tail, err := NewNotify(af.Name(), false)
Expand All @@ -44,6 +49,8 @@ func TestTailNotifyFileAppendingExisting(t *testing.T) {
}

func TestTailNotifyFileRecreatedReopen(t *testing.T) {
testutil.SkipWindows(t) // fsnotify not working, separate issue

af := CreateAppendingTempFile()

tail, err := NewNotify(af.Name(), true)
Expand All @@ -66,6 +73,8 @@ func TestTailNotifyFileRecreatedReopen(t *testing.T) {
}

func TestTailNotifyFileDeletedCloses(t *testing.T) {
testutil.SkipWindows(t) // fsnotify not working, separate issue

af := CreateAppendingTempFile()

tail, err := NewNotify(af.Name(), false)
Expand Down Expand Up @@ -96,6 +105,8 @@ func TestTailNotifyFileDeletedCloses(t *testing.T) {
}

func TestWatchingNonExistantFile(t *testing.T) {
testutil.SkipWindows(t) // fsnotify not working, separate issue

tp := path.Join(os.TempDir(), fmt.Sprintf("go-test-%d", rand.Int()))

tail, err := NewNotify(tp, true)
Expand All @@ -110,6 +121,8 @@ func TestWatchingNonExistantFile(t *testing.T) {
}

func TestWatchingNonExistingFileFails(t *testing.T) {
testutil.SkipWindows(t) // fsnotify not working, separate issue

tp := path.Join(os.TempDir(), fmt.Sprintf("go-test-%d", rand.Int()))
tail, err := NewNotify(tp, false)

Expand All @@ -127,6 +140,8 @@ func TestNonBlockingSignal(t *testing.T) {
}

func TestNotifyClosedReaderReturnsEOF(t *testing.T) {
testutil.SkipWindows(t) // fsnotify not working, separate issue

af := CreateAppendingTempFile()
defer af.Close()

Expand Down
7 changes: 5 additions & 2 deletions pkg/followreader/poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/zix99/rare/pkg/testutil"
)

func TestSimpleFilePollingTail(t *testing.T) {
Expand Down Expand Up @@ -35,16 +36,17 @@ func TestTailFileAppendingExisting(t *testing.T) {
assertSequentialReads(t, tail, 10)

// Re-open process
af.Stop()
af.CloseFile()
af = CreateAppendingFromFile(af.Name())

assertSequentialReads(t, tail, 10)

af.Close()
assert.NoError(t, tail.Close())
af.Close()
}

func TestTailFileRecreatedReopen(t *testing.T) {
testutil.SkipWindows(t) // Not able to delete-while-open, so not a use-case
if testing.Short() {
t.SkipNow()
}
Expand All @@ -71,6 +73,7 @@ func TestTailFileRecreatedReopen(t *testing.T) {
}

func TestTailFileDeletedCloses(t *testing.T) {
testutil.SkipWindows(t) // Not able to delete-while-open, so not a use-case
if testing.Short() {
t.SkipNow()
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/testutil/acceptance/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var stringMatchers = map[string]stringComparer{
type testConfig struct {
name string
cmd string
goos string
stdout strings.Builder
stderr strings.Builder
stdin strings.Builder
Expand Down Expand Up @@ -68,6 +69,8 @@ func iterateTestDefinitions(t *testing.T, r io.Reader) func(func(yield testConfi
cfg.errComp = matcher
cfg.linenum = linenum
writeTarget = &cfg.stdout
case strings.HasPrefix(line, "GOOS "):
cfg.goos = line[5:]
case strings.HasPrefix(line, "STDOUT"):
writeTarget = &cfg.stdout
cfg.outComp = matcher
Expand Down
6 changes: 6 additions & 0 deletions pkg/testutil/acceptance/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"io"
"os"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -31,6 +32,11 @@ func RunTestSuiteFile(t *testing.T, filename string, runner Runner) {
}

func runTestConfig(t *testing.T, cfg *testConfig, runner Runner) {
if cfg.goos != "" && cfg.goos != runtime.GOOS {
t.Logf("SKIP (line %d): %s", cfg.linenum, cfg.name)
t.Skipf("goos %s != %s", cfg.goos, runtime.GOOS)
}

t.Logf("RUN (line %d): %s", cfg.linenum, cfg.cmd)

args := append([]string{"app"}, testutil.SplitQuotedString(cfg.cmd)...)
Expand Down
16 changes: 16 additions & 0 deletions pkg/testutil/os.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package testutil

import (
"runtime"
"testing"
)

func IsWindows() bool {
return runtime.GOOS == "windows"
}

func SkipWindows(t *testing.T) {
if IsWindows() {
t.Skip("skip windows")
}
}
12 changes: 12 additions & 0 deletions pkg/testutil/os_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package testutil

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestIsWindows(t *testing.T) {
SkipWindows(t)
assert.False(t, IsWindows())
}
Loading