-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathstats_test.go
94 lines (71 loc) · 1.92 KB
/
stats_test.go
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package tiledb
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// Example usage of tiledb statistics
func ExampleStatsEnable() {
err := StatsEnable()
if err != nil {
// Handle error
}
// Perform tile operations
err = StatsDumpSTDOUT()
if err != nil {
// Handle error
}
}
// Test statistics
func TestStats(t *testing.T) {
// Enable statistics
err := StatsEnable()
require.NoError(t, err)
// Reset all internal counters to 0
require.NoError(t, StatsReset())
// Dump statistics to stdout
require.NoError(t, StatsDumpSTDOUT())
tmpPath := filepath.Join(t.TempDir(), "dump")
// Dump statistics to file
require.NoError(t, StatsDump(tmpPath))
// Validate dumped file is non-empty
fileInfo, err := os.Stat(tmpPath)
require.NoError(t, err)
assert.NotZero(t, fileInfo.Size())
// Dump statistics to existing file should error
assert.Error(t, StatsDump(tmpPath))
// Get statistics as string
stats, err := Stats()
require.NoError(t, err)
assert.NotEmpty(t, stats)
// Disable statistics
require.NoError(t, StatsDisable())
}
// Test statistics
func TestStatsRaw(t *testing.T) {
// Enable statistics
err := StatsEnable()
require.NoError(t, err)
// Reset all internal counters to 0
require.NoError(t, StatsReset())
// Dump raw (json) statistics to stdout
require.NoError(t, StatsRawDumpSTDOUT())
tmpPath := filepath.Join(t.TempDir(), "dump")
// Dump raw (json) statistics to file
require.NoError(t, StatsRawDump(tmpPath))
// Validate dumped file is non-empty
fileInfo, err := os.Stat(tmpPath)
require.NoError(t, err)
assert.NotZero(t, fileInfo.Size())
// Dump raw (json) statistics to existing file should error
err = StatsRawDump(tmpPath)
assert.Error(t, err)
// Get raw (json) statistics as string
stats, err := StatsRaw()
require.NoError(t, err)
assert.NotEmpty(t, stats)
// Disable statistics
require.NoError(t, StatsDisable())
}