Skip to content

Commit

Permalink
Merge pull request #5 from ajainc/feature/cleanup_test_file
Browse files Browse the repository at this point in the history
cleanup test file when test finished
  • Loading branch information
KoteiIto authored Jul 24, 2018
2 parents 4cf391c + 14295aa commit f40d7dd
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions appender_file_rotatable_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
package golog

import (
"testing"
"github.com/stretchr/testify/assert"
"syscall"
"os"
"io/ioutil"
"os"
"syscall"
"testing"
"time"

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

func TestRotatableFileAppender_Write(t *testing.T) {

var setup = func () {
var setup = func() {
file1, _ := os.OpenFile("appender_file_rotatable", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
file1.Close()
file2, _ := os.OpenFile("appender_file_rotatable_bk", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
file2.Close()
}

var cleanup = func() {
os.Remove("appender_file_rotatable")
os.Remove("appender_file_rotatable_bk")
}

t.Run("", func(t *testing.T) {
setup()

Expand All @@ -32,19 +38,19 @@ func TestRotatableFileAppender_Write(t *testing.T) {
appender.Write([]byte("test2"))
appender.Close()


file1, err := os.OpenFile("appender_file_rotatable", os.O_RDONLY, 0666)
assert.Nil(t, err)
actual, err := ioutil.ReadAll(file1)
expected := "test2\n"
assert.Equal(t, expected, string(actual))


file2, err := os.OpenFile("appender_file_rotatable_bk", os.O_RDONLY, 0666)
assert.Nil(t, err)
actual, err = ioutil.ReadAll(file2)
assert.Nil(t, err)
expected = "test1\n"
assert.Equal(t, expected, string(actual))

cleanup()
})
}

0 comments on commit f40d7dd

Please sign in to comment.