-
Notifications
You must be signed in to change notification settings - Fork 8
/
domain_test.go
123 lines (99 loc) · 2.72 KB
/
domain_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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package tiledb
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func ExampleNewDomain() {
// Create Config, this is optional
config, err := NewConfig()
if err != nil {
// Handle error
return
}
// Test context with config
context, err := NewContext(config)
if err != nil {
// Handle error
return
}
// Create Dimension
dimension, err := NewDimension(context, "test", TILEDB_INT32, []int32{1, 10}, int32(5))
if err != nil {
// Handle error
return
}
// Create Domain
domain, err := NewDomain(context)
if err != nil {
// Handle error
return
}
// Add dimension to domain
err = domain.AddDimensions(dimension)
if err != nil {
// Handle error
return
}
}
// TestDomain tests creating a new dimension
func TestDomain(t *testing.T) {
// Create configuration
config, err := NewConfig()
require.NoError(t, err)
// Test context with config
context, err := NewContext(config)
require.NoError(t, err)
// Test create dimension
dimension, err := NewDimension(context, "test", TILEDB_INT32, []int32{1, 10}, int32(5))
require.NoError(t, err)
assert.NotNil(t, dimension)
// Test creating domain
domain, err := NewDomain(context)
require.NoError(t, err)
assert.NotNil(t, domain)
hasDim, err := domain.HasDimension("test")
require.NoError(t, err)
assert.Equal(t, false, hasDim)
// Add dimension
require.NoError(t, domain.AddDimensions(dimension))
hasDim, err = domain.HasDimension("test")
require.NoError(t, err)
assert.Equal(t, true, hasDim)
// Test getting type
datatype, err := domain.Type()
require.NoError(t, err)
assert.Equal(t, TILEDB_INT32, datatype)
// Test getting number of dimension
ndim, err := domain.NDim()
require.NoError(t, err)
assert.Equal(t, uint(1), ndim)
// Test getting dimension from index for domain
dimensionFromIndex, err := domain.DimensionFromIndex(0)
require.NoError(t, err)
assert.NotNil(t, dimension)
// Validate dimension returned
dimensionName, err := dimensionFromIndex.Name()
require.NoError(t, err)
assert.Equal(t, "test", dimensionName)
// Test getting dimension from name for domain
dimensionFromName, err := domain.DimensionFromName(dimensionName)
require.NoError(t, err)
assert.NotNil(t, dimension)
// Validate dimension returned
dimensionName, err = dimensionFromName.Name()
require.NoError(t, err)
assert.Equal(t, "test", dimensionName)
// Temp path for testing dump
tmpPathDump := filepath.Join(t.TempDir(), "dump")
// Test dumping to file
require.NoError(t, domain.Dump(tmpPathDump))
// Validate dumped file is non-empty
fileInfo, err := os.Stat(tmpPathDump)
require.NoError(t, err)
assert.NotZero(t, fileInfo.Size())
require.NoError(t, domain.DumpSTDOUT())
domain.Free()
}