-
Notifications
You must be signed in to change notification settings - Fork 10
/
layer_test.go
80 lines (71 loc) · 2.27 KB
/
layer_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
package gismanager
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
func TestGetFeatures(t *testing.T) {
manager, _ := FromConfig("./testdata/test_config.yml")
files, _ := GetGISFiles(manager.Source.Path)
source, _ := manager.OpenSource(files[0], 1)
layer := source.LayerByIndex(0)
gLayer := GdalLayer{
Layer: &layer,
}
count, _ := layer.FeatureCount(true)
features := gLayer.GetFeatures()
assert.NotNil(t, features)
assert.Equal(t, count, len(features))
}
func TestGetLayerSchema(t *testing.T) {
manager, _ := FromConfig("./testdata/test_config.yml")
files, _ := GetGISFiles(manager.Source.Path)
source, _ := manager.OpenSource(files[0], 1)
layer := source.LayerByIndex(0)
gLayer := GdalLayer{
Layer: &layer,
}
fields := gLayer.GetLayerSchema()
assert.NotNil(t, fields)
assert.True(t, len(fields) > 0)
}
type ManagerLayerSuite struct {
suite.Suite
manager *ManagerConfig
}
func (suite *ManagerLayerSuite) SetupSuite() {
manager, _ := FromConfig("./testdata/test_config.yml")
suite.manager = manager
}
func (suite *ManagerLayerSuite) TestLayerOperations() {
manager := suite.manager
files, _ := GetGISFiles(manager.Source.Path)
source, _ := manager.OpenSource(files[0], 1)
layer := source.LayerByIndex(0)
gLayer := GdalLayer{
Layer: &layer,
}
dummyGLayer := GdalLayer{}
targetSource, _ := manager.OpenSource(manager.Datastore.BuildConnectionString(), 1)
nilStore, nilStoreErr := gLayer.LayerToPostgis(nil, manager, true)
assert.Nil(suite.T(), nilStore)
assert.NotNil(suite.T(), nilStoreErr)
nilLayer, nilLayerErr := dummyGLayer.LayerToPostgis(targetSource, manager, true)
assert.Nil(suite.T(), nilLayer)
assert.NotNil(suite.T(), nilLayerErr)
newLayer, err := gLayer.LayerToPostgis(targetSource, manager, true)
assert.NotNil(suite.T(), newLayer)
assert.Nil(suite.T(), err)
ok, publishErr := manager.PublishGeoserverLayer(newLayer)
assert.True(suite.T(), ok)
assert.Nil(suite.T(), publishErr)
}
func (suite *ManagerLayerSuite) TearDownSuite() {
catalog := suite.manager.GetGeoserverCatalog()
deleted, err := catalog.DeleteWorkspace(suite.manager.Geoserver.WorkspaceName, true)
assert.True(suite.T(), deleted)
assert.Nil(suite.T(), err)
}
func TestManagerLayerSuite(t *testing.T) {
suite.Run(t, new(ManagerLayerSuite))
}