forked from deusdat/arangomigo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimpls_view_test.go
188 lines (149 loc) · 4.87 KB
/
impls_view_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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package arangomigo
import (
"context"
"errors"
"github.com/stretchr/testify/assert"
"testing"
driver "github.com/arangodb/go-driver"
)
// Simple struct that mocks Arango's View interface.
type MockView struct {
driver.View
name string
}
// Implements View.Name() and used in testing.
func (mv MockView) Name() string {
return mv.name
}
// Implements View.ArangoSearchView() to get an ArangoSearchView or return an error as the test expects.
func (mv MockView) ArangoSearchView() (driver.ArangoSearchView, error) {
if "GetSearchViewError" == mv.Name() {
return nil, errors.New("this is just a test")
}
return MockArangoSearchView{
name: mv.Name(),
}, nil
}
// Implements View.Remove.
func (mv MockView) Remove(ctx context.Context) error {
return errors.New("this is just a test")
}
// Simple struct that implements Arango's ArangoSearchView interface.
type MockArangoSearchView struct {
name string
}
// Implements ArangoSearchView.Name()
func (mv MockArangoSearchView) Name() string {
return mv.name
}
// Implements ArangoSearchView.Type()
func (mv MockArangoSearchView) Type() driver.ViewType {
return driver.ViewTypeArangoSearch
}
// Implements ArangoSearchView.Properties()
func (mv MockArangoSearchView) Properties(ctx context.Context) (driver.ArangoSearchViewProperties, error) {
return driver.ArangoSearchViewProperties{}, nil
}
// An empty implementation of ArangoSearchView.View.ArangoSearchView().
func (mv MockArangoSearchView) ArangoSearchView() (driver.ArangoSearchView, error) {
return nil, nil
}
// An empty implementation of ArangoSearchView.View.ArangoSearchViewAlias().
func (mv MockArangoSearchView) ArangoSearchViewAlias() (driver.ArangoSearchViewAlias, error) {
return nil, nil
}
// An empty implementation of ArangoSearchView.View.Database().
func (mv MockArangoSearchView) Database() driver.Database {
return nil
}
// An empty implementation of ArangoSearchView.View.Rename().
func (mv MockArangoSearchView) Rename(ctx context.Context, newName string) error {
return nil
}
// An empty implementation of ArangoSearchView.View.Remove().
func (mv MockArangoSearchView) Remove(ctx context.Context) error {
return nil
}
// Implements ArangoSearchView.SetProperties()
func (mv MockArangoSearchView) SetProperties(ctx context.Context, options driver.ArangoSearchViewProperties) error {
return errors.New("this is just a test")
}
// Implements Database.CreateArangoSearchView()
func (mdb MockDB) CreateArangoSearchView(ctx context.Context, name string, options *driver.ArangoSearchViewProperties) (driver.ArangoSearchView, error) {
return nil, errors.New("this is just a test")
}
// Implements Database.View() to get a View or return an error as the test expects.
func (mdb MockDB) View(ctx context.Context, name string) (driver.View, error) {
if name == "ViewError" {
return nil, errors.New("this is just a test")
}
return MockView{
name: name,
}, nil
}
// Test the error is handled during creating a view.
func TestViewCreateError(t *testing.T) {
view := SearchView{}
view.Action = CREATE
view.Name = "TestView"
err := view.Migrate(
context.Background(),
MockDB{},
nil)
assert.EqualError(t, err, "Couldn't create view 'TestView': this is just a test")
}
// Test the error is handled when getting a view for delete.
func TestViewDeleteErrorGetting(t *testing.T) {
view := SearchView{}
view.Action = DELETE
view.Name = "ViewError"
err := view.Migrate(
context.Background(),
MockDB{},
nil)
assert.EqualError(t, err, "Couldn't find view 'ViewError' to delete: this is just a test")
}
// Test the error is handled during deleting a view.
func TestViewDeleteErrorRemove(t *testing.T) {
view := SearchView{}
view.Action = DELETE
view.Name = "TestView"
err := view.Migrate(
context.Background(),
MockDB{},
nil)
assert.EqualError(t, err, "Couldn't delete view 'TestView': this is just a test")
}
// Test the error is handled when getting a view to update.
func TestViewModifyErrorGetting(t *testing.T) {
view := SearchView{}
view.Action = MODIFY
view.Name = "ViewError"
err := view.Migrate(
context.Background(),
MockDB{},
nil)
assert.EqualError(t, err, "Couldn't find view 'ViewError' to update: this is just a test")
}
// Test the error is handled when getting the ArangoSearchView from a view.
func TestViewModifyErrorGetSearchView(t *testing.T) {
view := SearchView{}
view.Action = MODIFY
view.Name = "GetSearchViewError"
err := view.Migrate(
context.Background(),
MockDB{},
nil)
assert.EqualError(t, err, "Couldn't get ArangoSearchView 'GetSearchViewError' to update: this is just a test")
}
// Test the error is handled when updating the ArangoSearchView's properties.
func TestViewModifyErrorSetProperties(t *testing.T) {
view := SearchView{}
view.Action = MODIFY
view.Name = "TestView"
err := view.Migrate(
context.Background(),
MockDB{},
nil)
assert.EqualError(t, err, "Couldn't update SearchView 'TestView': this is just a test")
}