-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeps_internal_test.go
More file actions
54 lines (45 loc) · 1.07 KB
/
deps_internal_test.go
File metadata and controls
54 lines (45 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package st
import (
"bytes"
"fmt"
"log"
"strings"
"testing"
)
func TestDepsLogging(t *testing.T) {
t.Setenv("STAVEFILE_VERBOSE", "1")
buf := &bytes.Buffer{}
defaultLogger := simpleConsoleLogger
simpleConsoleLogger = log.New(buf, "", 0)
defer func() { simpleConsoleLogger = defaultLogger }()
foo()
if strings.Count(buf.String(), "github.com/yaklabco/stave/pkg/st.baz") != 1 {
t.Fatalf("expected one baz to be logged, but got\n%s", buf)
}
}
func foo() {
Deps(bar, baz)
}
func bar() {
Deps(baz)
}
func baz() {}
func TestDepWasNotInvoked(t *testing.T) {
fn1 := func() error {
return nil
}
defer func() {
err := recover()
if err == nil {
t.Fatal("expected panic, but didn't get one")
}
gotErr := fmt.Sprint(err)
wantErr := "non-function used as a target dependency: <nil>. The st.Deps, st.SerialDeps and st.CtxDeps functions accept function names, such as st.Deps(TargetA, TargetB)"
if !strings.Contains(gotErr, wantErr) {
t.Fatalf(`expected to get "%s" but got "%s"`, wantErr, gotErr)
}
}()
func(fns ...interface{}) {
checkFns(fns)
}(fn1())
}