File tree Expand file tree Collapse file tree 1 file changed +0
-45
lines changed Expand file tree Collapse file tree 1 file changed +0
-45
lines changed Original file line number Diff line number Diff line change 6
6
"github.com/oschwald/maxminddb-golang"
7
7
"github.com/stretchr/testify/assert"
8
8
"github.com/stretchr/testify/require"
9
- "bytes"
10
- "errors"
11
9
"fmt"
12
10
"os"
13
11
"testing"
@@ -19,49 +17,6 @@ const (
19
17
TestDataset = "./testdata/dataset.json"
20
18
)
21
19
22
- func captureOutput (f func ()) string {
23
- // Create a pipe to capture the output
24
- r , w , _ := os .Pipe ()
25
- // Save the original stdout
26
- stdout := os .Stdout
27
- // Set stdout to the write end of the pipe
28
- os .Stdout = w
29
-
30
- // Run the function (which will print to stdout)
31
- f ()
32
-
33
- // Close the writer end and restore stdout
34
- w .Close ()
35
- os .Stdout = stdout
36
-
37
- // Read the captured output from the read end of the pipe
38
- var buf bytes.Buffer
39
- buf .ReadFrom (r )
40
-
41
- return buf .String ()
42
- }
43
-
44
- func TestCheck (t * testing.T ) {
45
- output := captureOutput (func () {
46
- Check (func () error {
47
- return nil
48
- })
49
- })
50
-
51
- // Check that there was no output (since no error should be printed)
52
- assert .Empty (t , output )
53
-
54
- output = captureOutput (func () {
55
- Check (func () error {
56
- return errors .New ("test error" )
57
- })
58
- })
59
-
60
- // Check that the error message was printed
61
- expectedOutput := "Received error: test error\n "
62
- assert .Equal (t , expectedOutput , output )
63
- }
64
-
65
20
func TestToMMDBType (t * testing.T ) {
66
21
tests := []struct {
67
22
key string
You can’t perform that action at this time.
0 commit comments