Skip to content

Commit

Permalink
test for small offset + build fix
Browse files Browse the repository at this point in the history
  • Loading branch information
svetlyi committed Apr 11, 2021
1 parent 10a40f0 commit a4f8d44
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ test_data/*.log
.idea
.swo
.swp
.code
.code
release
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
rectail : cmd/rectail/args.go cmd/rectail/rectail.go
go test -v && go install ./cmd/rectail && echo 'installed to $$GOPATH/bin/rectail' && \
echo "to use, run 'rectail --help'"
echo "to use, run 'rectail --help'"

test :
go test -v
63 changes: 63 additions & 0 deletions rectail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,66 @@ func TestFirstRead(t *testing.T) {
}
}
}

func TestFirstReadForSmallOffset(t *testing.T) {
logger := log.New(logOutput, "", 0)

var (
fileUpdate rectail.FileUpdate
expectedLines = []string{
"џѕѓ2 bar2 foo2 bar2 foo2 bar2 foo2 bar2 foo2 bar2 foo2 bar2 foo2 bar2 foo2 bar2 foo2 bar2 џѕѓ2 bar2",
"џѕѓ3 bar3 foo3 bar3 foo3 bar3 foo3 bar3 foo3 bar3 foo3 bar3 foo3 bar3 foo3 bar3 foo3 bar3 џѕѓ3 bar3",
"џѕѓ4 bar4 foo4 bar4 foo4 bar4 foo4 bar4 foo4 bar4 foo4 bar4 foo4 bar4 foo4 bar4 foo4 bar4 џѕѓ4 bar4",
}
textToWrite = `џѕѓ bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar џѕѓ bar
џѕѓ1 bar1 foo1 bar1 foo1 bar1 foo1 bar1 foo1 bar1 foo1 bar1 foo1 bar1 foo1 bar1 foo1 bar1 џѕѓ1 bar1
џѕѓ2 bar2 foo2 bar2 foo2 bar2 foo2 bar2 foo2 bar2 foo2 bar2 foo2 bar2 foo2 bar2 foo2 bar2 џѕѓ2 bar2
џѕѓ3 bar3 foo3 bar3 foo3 bar3 foo3 bar3 foo3 bar3 foo3 bar3 foo3 bar3 foo3 bar3 foo3 bar3 џѕѓ3 bar3
џѕѓ4 bar4 foo4 bar4 foo4 bar4 foo4 bar4 foo4 bar4 foo4 bar4 foo4 bar4 foo4 bar4 foo4 bar4 џѕѓ4 bar4`
fileUpdates = make(chan rectail.FileUpdate)
updates = make(chan string)
err error
f *os.File
)
f, err = os.Create("test_data/test.log")
if err != nil {
t.Fatal(err)
}
if _, err = f.WriteString(textToWrite); err != nil {
t.Fatal(err)
}

rt, err := rectail.NewRecTail(
[]string{"test_data"},
[]string{"\\.log"},
updates,
600,
400,
logger,
)
if err != nil {
t.Fatalf("could not initialize rectail: %v", err)
}
rectailCtx, rectailCtxCancel := context.WithCancel(context.Background())
defer rectailCtxCancel()

go func() {
if err = rt.Watch(rectailCtx, fileUpdates); err != nil {
logger.Fatalln(err)
}
}()
go func() {
for update := range updates {
logger.Println(update)
}
}()
fileUpdate = <-fileUpdates
if len(fileUpdate.Lines) != len(expectedLines) {
t.Errorf("expected %d lines with update; got: %d", len(expectedLines), len(fileUpdate.Lines))
}
for lineIndex := range fileUpdate.Lines {
if fileUpdate.Lines[lineIndex] != expectedLines[lineIndex] {
t.Errorf("expected: %s; got: %s", expectedLines[lineIndex], fileUpdate.Lines[lineIndex])
}
}
}
15 changes: 8 additions & 7 deletions release.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/bin/bash

tag=$(git describe --tags)
releasePath="release"
mkdir -p releasePath

mkdir -p release/$tag
GOOS=windows GOARCH=386 go build -o $releasePath/rectail.exe ./cmd/rectail
GOOS=windows GOARCH=amd64 go build -o $releasePath/rectail64.exe ./cmd/rectail

GOOS=windows GOARCH=386 go build -o release/$tag/rectail.exe ./cmd/rectail
GOOS=windows GOARCH=amd64 go build -o release/$tag/rectail64.exe ./cmd/rectail
GOOS=linux GOARCH=386 go build -o $releasePath/rectail_linux ./cmd/rectail
GOOS=linux GOARCH=amd64 go build -o $releasePath/rectail64_linux ./cmd/rectail

GOOS=linux GOARCH=386 go build -o release/$tag/rectail_linux ./cmd/rectail
GOOS=linux GOARCH=amd64 go build -o release/$tag/rectail64_linux ./cmd/rectail
GOOS=darwin GOARCH=amd64 go build -o $releasePath/rectail_osx ./cmd/rectail

GOOS=darwin GOARCH=amd64 go build -o release/$tag/rectail_osx ./cmd/rectail
echo "generated"

0 comments on commit a4f8d44

Please sign in to comment.