Skip to content

Commit

Permalink
Merge pull request #3 from iproj/upgrade
Browse files Browse the repository at this point in the history
Add unit test
  • Loading branch information
needkane authored Aug 23, 2021
2 parents ee57082 + 8dd69e2 commit e8c30a0
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 13 deletions.
17 changes: 13 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
language: go
sudo: false
go:
- "1.14"
- tip
go_import_path: github.com/iproj/file-rotatelogs
os : linux
jobs:
include:
- stage: build
os: linux
go: 1.14
env: GO111MODULE=on
script:
- go test
after_success:
- bash <(curl -s https://codecov.io/bash)

18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ file-rotatelogs

Provide an `io.Writer` that periodically rotates log files from within the application. Port of [File::RotateLogs](https://metacpan.org/release/File-RotateLogs) from Perl to Go.

[![Build Status](https://travis-ci.org/lestrrat-go/file-rotatelogs.png?branch=master)](https://travis-ci.org/lestrrat-go/file-rotatelogs)

[![GoDoc](https://godoc.org/github.com/lestrrat-go/file-rotatelogs?status.svg)](https://godoc.org/github.com/lestrrat-go/file-rotatelogs)

# WARNINGS

THIS PROJECT HAS BEEN ARCHIVED. IT WILL NOT RECEIVE UPDATES, THE AUTHOR DOES NOT WISH TO MAINTAIN OR SUPPORT IT.
IN SHORT, DO NOT USE THIS PROJECT.
[![version](https://img.shields.io/github/v/tag/iproj/file-rotatelogs.svg?sort=semver)](https://github.com/iproj/file-rotatelogs/releases/latest)
[![API Reference](https://camo.githubusercontent.com/915b7be44ada53c290eb157634330494ebe3e30a/68747470733a2f2f676f646f632e6f72672f6769746875622e636f6d2f676f6c616e672f6764646f3f7374617475732e737667)](https://godoc.org/github.com/iproj/file-rotatelogs)
[![Go version](https://img.shields.io/badge/go-1.14-blue.svg)](https://github.com/moovweb/gvm)
[![Go Report Card](https://goreportcard.com/badge/github.com/iproj/file-rotatelogs)](https://goreportcard.com/report/github.com/iproj/file-rotatelogs)
[![Travis](https://travis-ci.com/iproj/file-rotatelogs.svg?branch=main)](https://travis-ci.com/iproj/file-rotatelogs)
[![license](https://img.shields.io/github/license/iproj/file-rotatelogs.svg)](https://github.com/iproj/file-rotatelogs/blob/main/LICENSE)

| Branch | Tests | Coverage |
| ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| main | [![TravisCI](https://travis-ci.com/iproj/file-rotatelogs.svg?branch=main)](https://travis-ci.com/iproj/file-rotatelogs) | [![codecov](https://codecov.io/gh/iproj/file-rotatelogs/branch/main/graph/badge.svg)](https://codecov.io/gh/iproj/file-rotatelogs) |

# SYNOPSIS

Expand Down
39 changes: 39 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ package rotatelogs_test
import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strconv"
"testing"

rotatelogs "github.com/iproj/file-rotatelogs"
"github.com/stretchr/testify/assert"
)

func ExampleForceNewFile() {
Expand Down Expand Up @@ -61,3 +66,37 @@ func ExampleForceNewFile() {
// test.log 4
// test.log.1 4
}

func TestTooMuchLog(t *testing.T) {

var (
testDir = "test_much_log"
testLogPath = filepath.Join(testDir, "access_log")
rotationCount = 3
N = 12 // N < log.Printf content size
)
err := os.Mkdir(testDir, 0777)
assert.Nil(t, err)
defer os.RemoveAll(testDir)
assert.Nil(t, err)

rl, err := rotatelogs.New(
testLogPath+".%Y%m%d%H%M",
rotatelogs.WithLinkName(testLogPath),
rotatelogs.WithRotationCount(uint(rotationCount)),
rotatelogs.WithRotationSize(12),
)
assert.Nil(t, err)

log.SetOutput(rl)
for i := 0; i < N; i++ {
log.Printf("Test content %d\n", i)
}
files, _ := ioutil.ReadDir(testDir)
fmt.Println(files)
assert.Equal(t, rotationCount+1, len(files))

bytez, err := ioutil.ReadFile(testLogPath)
assert.Nil(t, err)
assert.Equal(t, strconv.Itoa(N-1), string(bytez[len(bytez)-3:len(bytez)-1]))
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/lestrrat-go/file-rotatelogs
module github.com/iproj/file-rotatelogs

go 1.12

Expand Down

0 comments on commit e8c30a0

Please sign in to comment.