Skip to content

Commit 396587d

Browse files
committed
add test for log
1 parent 9e8b759 commit 396587d

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

log_test.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package obelisk
2+
3+
import (
4+
"bytes"
5+
"os"
6+
"testing"
7+
8+
"github.com/sirupsen/logrus"
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestArchiver_LogURL(t *testing.T) {
13+
arc := &Archiver{
14+
EnableLog: true,
15+
EnableVerboseLog: true,
16+
}
17+
18+
url := "https://example.com"
19+
parentURL := "https://parent.com"
20+
isCached := true
21+
22+
// Capture log output
23+
var logOutput bytes.Buffer
24+
logrus.SetOutput(&logOutput)
25+
26+
arc.logURL(url, parentURL, isCached)
27+
assert.Contains(t, logOutput.String(), url)
28+
29+
// clear log output
30+
logrus.SetOutput(os.Stdout)
31+
32+
arc = &Archiver{
33+
EnableLog: false,
34+
EnableVerboseLog: false,
35+
}
36+
arc.logURL(url, parentURL, isCached)
37+
assert.Contains(t, logOutput.String(), url)
38+
39+
}
40+
41+
func TestArchiver_LogURLdisable(t *testing.T) {
42+
arc := &Archiver{
43+
EnableLog: false,
44+
EnableVerboseLog: false,
45+
}
46+
47+
url := "https://example.com"
48+
parentURL := "https://parent.com"
49+
isCached := true
50+
51+
// Capture log output
52+
var logOutput bytes.Buffer
53+
logrus.SetOutput(&logOutput)
54+
55+
arc.logURL(url, parentURL, isCached)
56+
assert.NotContains(t, logOutput.String(), url)
57+
}

0 commit comments

Comments
 (0)