forked from hishamkaram/geoserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
styles_test.go
87 lines (80 loc) · 3.09 KB
/
styles_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
package geoserver
import (
"bytes"
"io/ioutil"
"path/filepath"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
type GeoserverStyleSuite struct {
suite.Suite
gsCatalog *GeoServer
}
func (suite *GeoserverStyleSuite) SetupSuite() {
suite.gsCatalog = GetCatalog("http://localhost:8080/geoserver/", "admin", "geoserver")
created, err := suite.gsCatalog.CreateWorkspace("styles_test")
assert.True(suite.T(), created)
assert.Nil(suite.T(), err)
}
func (suite *GeoserverStyleSuite) TestStyles() {
sldPath, _ := filepath.Abs("testdata/airports.sld")
sld, _ := ioutil.ReadFile(sldPath)
uploaded, err := suite.gsCatalog.UploadStyle(bytes.NewBuffer(sld), "styles_test", "test_test", false)
assert.True(suite.T(), uploaded)
assert.Nil(suite.T(), err)
styleUploaded, styleErr := suite.gsCatalog.UploadStyle(bytes.NewBuffer(sld), "styles_test", "test_test", false)
assert.False(suite.T(), styleUploaded)
assert.NotNil(suite.T(), styleErr)
styles, getErr := suite.gsCatalog.GetStyles("styles_test")
assert.NotEmpty(suite.T(), styles)
assert.Nil(suite.T(), getErr)
style, styleErr := suite.gsCatalog.GetStyle("styles_test", "test_test")
assert.NotEmpty(suite.T(), style)
assert.Nil(suite.T(), styleErr)
styleExists, styleErr := suite.gsCatalog.StyleExists("styles_test", "test_test")
assert.True(suite.T(), styleExists)
assert.Nil(suite.T(), styleErr)
deleted, deleteErr := suite.gsCatalog.DeleteStyle("styles_test", "test_test", true)
assert.True(suite.T(), deleted)
assert.Nil(suite.T(), deleteErr)
}
func (suite *GeoserverStyleSuite) TearDownSuite() {
suite.gsCatalog = GetCatalog("http://localhost:8080/geoserver/", "admin", "geoserver")
deleted, err := suite.gsCatalog.DeleteWorkspace("styles_test", true)
assert.True(suite.T(), deleted)
assert.Nil(suite.T(), err)
}
func TestGeoserverStyleSuite(t *testing.T) {
suite.Run(t, new(GeoserverStyleSuite))
}
func TestGeoserverImplemetStyleService(t *testing.T) {
gsCatalog := reflect.TypeOf(&GeoServer{})
StyleServiceType := reflect.TypeOf((*StyleService)(nil)).Elem()
check := gsCatalog.Implements(StyleServiceType)
assert.True(t, check)
}
func TestStylesError(t *testing.T) {
gsCatalog := GetCatalog("http://localhost:8080/geoserver_dummy/", "admin", "geoserver")
sldPath, _ := filepath.Abs("testdata/airports.sld")
sld, _ := ioutil.ReadFile(sldPath)
created, uploadErr := gsCatalog.CreateStyle("styles_test", "test_test")
assert.False(t, created)
assert.NotNil(t, uploadErr)
uploaded, err := gsCatalog.UploadStyle(bytes.NewBuffer(sld), "styles_test", "test_test", false)
assert.False(t, uploaded)
assert.NotNil(t, err)
styles, getErr := gsCatalog.GetStyles("styles_test")
assert.Nil(t, styles)
assert.NotNil(t, getErr)
styleExists, styleErr := gsCatalog.StyleExists("styles_test", "test_test")
assert.False(t, styleExists)
assert.NotNil(t, styleErr)
style, styleErr := gsCatalog.GetStyle("styles_test", "test_test")
assert.Equal(t, style, &Style{})
assert.NotNil(t, styleErr)
deleted, deleteErr := gsCatalog.DeleteStyle("styles_test", "test_test", true)
assert.False(t, deleted)
assert.NotNil(t, deleteErr)
}