forked from cjbassi/gotop
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #49, logs filling up hard drive.
- Loading branch information
Showing
6 changed files
with
164 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package logging | ||
|
||
import ( | ||
"io/ioutil" | ||
//"log" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/xxxserxxx/gotop" | ||
) | ||
|
||
func TestLogging(t *testing.T) { | ||
tdn := "testdir" | ||
path, err := filepath.Abs(tdn) | ||
defer os.RemoveAll(path) | ||
c := gotop.Config{ | ||
MaxLogSize: 300, | ||
LogDir: path, | ||
LogFile: "errors.log", | ||
} | ||
wc, err := New(c) | ||
assert.NoError(t, err) | ||
if err != nil { | ||
return | ||
} | ||
defer wc.Close() | ||
ds := make([]byte, 100) | ||
for i, _ := range ds { | ||
ds[i] = 'x' | ||
} | ||
|
||
// Base case -- empty log file | ||
td, err := ioutil.ReadDir(path) | ||
assert.NoError(t, err) | ||
if err != nil { | ||
return | ||
} | ||
assert.Equal(t, 1, len(td)) | ||
|
||
for i := 1; i < 6; i++ { | ||
wc.Write(ds) | ||
wc.Write(ds) | ||
wc.Write(ds) | ||
wc.Write([]byte{'\n'}) // max... + 1 | ||
td, err = ioutil.ReadDir(path) | ||
assert.NoError(t, err) | ||
k := i | ||
if k > 4 { | ||
k = 4 | ||
} | ||
assert.Equal(t, k, len(td)) | ||
} | ||
} |