-
Notifications
You must be signed in to change notification settings - Fork 10
/
manager_test.go
73 lines (67 loc) · 2.79 KB
/
manager_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
package gismanager
import (
"testing"
"github.com/lukeroth/gdal"
"github.com/stretchr/testify/assert"
)
func TestFromConfig(t *testing.T) {
manager, confErr := FromConfig("./testdata/test_config.yml")
assert.Nil(t, confErr)
assert.NotNil(t, manager)
expected := ManagerConfig{
Geoserver: GeoserverConfig{WorkspaceName: "golang", Username: "admin", Password: "geoserver", ServerURL: "http://localhost:8080/geoserver"},
Datastore: DatastoreConfig{Host: "localhost", Port: 5432, DBName: "gis", DBUser: "golang", DBPass: "golang", Name: "gismanager_data"},
Source: SourceConfig{Path: "./testdata"},
logger: manager.logger,
}
assert.Equal(t, expected.Geoserver, manager.Geoserver)
// assert.Equal(t, expected.Datastore, manager.Datastore)
assert.Equal(t, expected.Source, manager.Source)
assert.Equal(t, expected.logger, manager.logger)
nilManager, nilConfErr := FromConfig("./testdata/test_configs.yml")
assert.NotNil(t, nilConfErr)
assert.Nil(t, nilManager)
errManager, errConfErr := FromConfig("./testdata/test_config_err.yml")
assert.NotNil(t, errConfErr)
assert.Nil(t, errManager)
}
func TestOpenSource(t *testing.T) {
manager, _ := FromConfig("./testdata/test_config.yml")
datasource, ok := manager.OpenSource("./testdata/sample.gpkg", 0)
assert.True(t, ok)
assert.NotNil(t, datasource)
nilDatasource, fail := manager.OpenSource("./testdata/sample_dummy.xml", 0)
assert.False(t, fail)
assert.Nil(t, nilDatasource)
}
func TestGetGeoserverCatalog(t *testing.T) {
manager, _ := FromConfig("./testdata/test_config.yml")
catalog := manager.GetGeoserverCatalog()
assert.NotNil(t, catalog)
}
func TestGetDriver(t *testing.T) {
manager, _ := FromConfig("./testdata/test_config.yml")
gpkgDriver, gpkgErr := manager.GetDriver("./testdata/sample.gpkg")
assert.Nil(t, gpkgErr)
assert.NotNil(t, gpkgDriver)
assert.Equal(t, gdal.OGRDriverByName(geopackageDriver), gpkgDriver)
jsonDriver, jsonErr := manager.GetDriver("./testdata/neighborhood_names_gis.geojson")
assert.Nil(t, jsonErr)
assert.NotNil(t, jsonDriver)
assert.Equal(t, gdal.OGRDriverByName(geoJSONDriver), jsonDriver)
zipDriver, zipErr := manager.GetDriver("./testdata/shapeFile.zip")
assert.Nil(t, zipErr)
assert.NotNil(t, zipDriver)
assert.Equal(t, gdal.OGRDriverByName(shapeFileDriver), zipDriver)
KMLDriver, KMLErr := manager.GetDriver("./testdata/layer.kml")
assert.Nil(t, KMLErr)
assert.NotNil(t, KMLDriver)
assert.Equal(t, gdal.OGRDriverByName(kmlDriver), KMLDriver)
pgDriver, pgErr := manager.GetDriver("PG: host=localhost port=5432 dbname=gis user=golang password=golang")
assert.Nil(t, pgErr)
assert.NotNil(t, pgDriver)
assert.Equal(t, gdal.OGRDriverByName(postgreSQLDriver), pgDriver)
tiffDriver, tiffErr := manager.GetDriver("./testdata/layer.tiff")
assert.NotNil(t, tiffErr)
assert.Equal(t, gdal.OGRDriver{}, tiffDriver)
}