Skip to content

Commit

Permalink
Fix that decimal sleep does not works properly
Browse files Browse the repository at this point in the history
  • Loading branch information
mingrammer committed Aug 25, 2018
1 parent 17a3705 commit 92c2507
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ vendor/

# Build & binary
dist/
flog

# Jetbrains IDE
.idea/
4 changes: 2 additions & 2 deletions flog.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Generate(option *Option) error {
splitCount++
}

delta += time.Duration(option.Sleep) * time.Second
delta += time.Duration(option.Sleep*float64(time.Second/time.Millisecond)) * time.Millisecond
}
} else {
// Generate the logs up to maximum size in byte
Expand All @@ -58,7 +58,7 @@ func Generate(option *Option) error {
splitCount++
}

delta += time.Duration(option.Sleep) * time.Second
delta += time.Duration(option.Sleep*float64(time.Second/time.Millisecond)) * time.Millisecond
}
}

Expand Down
5 changes: 3 additions & 2 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package main
import (
"errors"
"fmt"
"github.com/spf13/pflag"
"os"

"github.com/spf13/pflag"
)

const usage = `flog is a fake log generator for common log formats
Expand All @@ -16,7 +17,7 @@ Options:
-o, --output string Output filename. Path-like is allowed. (default "generated.log")
-t, --type string Log output type. ("stdout"|"log"|"gz") (default "stdout")
-n, --number integer Number of lines generate.
-b, --bytes integer Size of logs to generate. (in bytes)
-b, --bytes integer Size of logs to generate. (in bytes)
"bytes" will be ignored when "number" is set.
-s, --sleep numeric Sleep interval time between lines. (in seconds)
-p, --split-by integer Split the logs by this value in lines or bytes.
Expand Down
7 changes: 6 additions & 1 deletion option_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package main

import (
"github.com/stretchr/testify/assert"
"testing"

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

func TestParseFormat(t *testing.T) {
Expand Down Expand Up @@ -48,6 +49,10 @@ func TestParseSleep(t *testing.T) {
a.Equal(10.0, sleep, "sleep should be 10")
a.NoError(err, "there should be no error")

sleep, err = ParseSleep(5.5)
a.Equal(5.5, sleep, "sleep should be 5.5")
a.NoError(err, "there should be no error")

sleep, err = ParseSleep(-10)
a.Equal(0.0, sleep, "sleep should be 0 when negative is given")
a.Error(err, "there should be an error when negative is given")
Expand Down

0 comments on commit 92c2507

Please sign in to comment.