Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed May 22, 2019
1 parent 289215f commit 193339e
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/guard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {
for _, opts := range optsList {
fns = append(fns, func(opts *options) func() {
return func() {
g.E(g.Guard(opts.cmd, opts.patterns, g.GuardOptions{
g.E(g.Guard(opts.cmd, *opts.patterns, g.GuardOptions{
ExecOpts: g.ExecOptions{
Dir: *opts.dir,
IsRaw: *opts.raw,
Expand Down
23 changes: 23 additions & 0 deletions copy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package gokit_test

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"

g "github.com/ysmood/gokit"
)

func TestCopy(t *testing.T) {
str, _ := g.GenerateRandomString(10)
p := fmt.Sprintf("fixtures/deep/path/%s", str)

g.OutputFile(p+"/a/b", "ok", nil)
g.OutputFile(p+"/a/c/c", "ok", nil)

g.Copy(p+"/a", p+"/d")

assert.True(t, g.Exists(p+"/d/b"))
assert.True(t, g.Exists(p+"/d/c/c"))
}
2 changes: 1 addition & 1 deletion gokit.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gokit

// Version ...
const Version = "v0.2.1"
const Version = "v0.2.2"
38 changes: 38 additions & 0 deletions guard_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package gokit_test

import (
"fmt"
"testing"
"time"

g "github.com/ysmood/gokit"
)

func TestGuard(t *testing.T) {
str, _ := g.GenerateRandomString(10)
p := fmt.Sprintf("fixtures/%s", str)

g.OutputFile(p+"/f", "ok", nil)

stop := make(chan g.Nil)
d := 10 * time.Millisecond

go g.Guard([]string{"echo", "ok", "{{path}}"}, []string{p}, g.GuardOptions{
Stop: stop,
Debounce: &d,
})

go func() {
for {
time.Sleep(300 * time.Millisecond)
g.OutputFile(p+"/f", "ok", nil)
g.OutputFile(p+"/b", "ok", nil)
time.Sleep(300 * time.Millisecond)
g.Mkdir(p+"/d", nil)
}
}()

time.Sleep(1 * time.Second)

stop <- g.Nil{}
}
14 changes: 14 additions & 0 deletions log_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package gokit_test

import (
"testing"

g "github.com/ysmood/gokit"
)

func TestLog(t *testing.T) {
g.Log("ok")
g.Err("err")
g.Dump(10)
g.ClearScreen()
}

0 comments on commit 193339e

Please sign in to comment.