1
1
package solr
2
2
3
3
import (
4
- "testing"
5
4
"fmt"
6
5
"net/url"
7
- )
6
+ "strings"
7
+ "testing"
8
+ )
8
9
9
10
func TestConnection (t * testing.T ) {
10
11
_ , err1 := NewConnection ("fakedomain.tld" , "core0" )
@@ -26,22 +27,23 @@ func TestConnection(t *testing.T) {
26
27
func TestConnectionResourceInvalidDomain (t * testing.T ) {
27
28
conn , err := NewConnection ("http://www.fakedomain.tld/" , "core0" )
28
29
_ , err = conn .Resource ("select" , & url.Values {})
29
- expected := "Get http://www.fakedomain.tld/core0/select?wt=json: dial tcp: lookup www.fakedomain.tld: no such host"
30
- if err .Error () != expected {
30
+ expected := "Get http://www.fakedomain.tld/core0/select?wt=json: dial tcp"
31
+ error_report := err .Error ()
32
+ if strings .HasPrefix (error_report , expected ) == false {
31
33
t .Errorf ("expected '%s' but got '%s'" , expected , err .Error ())
32
34
}
33
35
}
34
36
35
37
func TestConnectionUpdateInvalidDomain (t * testing.T ) {
36
38
conn , err := NewConnection ("http://www.fakedomain.tld/" , "core0" )
37
39
_ , err = conn .Update (map [string ]interface {}{}, nil )
38
- expected := "Post http://www.fakedomain.tld/core0/update/?wt=json: dial tcp: lookup www.fakedomain.tld: no such host"
39
- if err .Error () != expected {
40
+ expected := "Post http://www.fakedomain.tld/core0/update/?wt=json: dial tcp"
41
+ error_report := err .Error ()
42
+ if strings .HasPrefix (error_report , expected ) == false {
40
43
t .Errorf ("expected '%s' but got '%s'" , expected , err .Error ())
41
44
}
42
45
}
43
46
44
-
45
47
func TestBytes2JsonWrongJson (t * testing.T ) {
46
48
data := []byte (`<xml><x>y</x><yy>boo</yy></xml>` )
47
49
d , err := bytes2json (& data )
@@ -63,7 +65,7 @@ func TestBytes2Json(t *testing.T) {
63
65
if d ["two" ].(float64 ) != 2 {
64
66
t .Errorf ("two should have 2 as value" )
65
67
}
66
-
68
+
67
69
}
68
70
69
71
func PrintMapInterface (d map [string ]interface {}) {
@@ -171,16 +173,16 @@ func TestSuccessStatus(t *testing.T) {
171
173
if successStatus (data ) != false {
172
174
t .Errorf ("Status check should give false but got true" )
173
175
}
174
-
176
+
175
177
data2 := map [string ]interface {}{
176
178
"error" : map [string ]interface {}{
177
179
"msg" : "Must specify a Content-Type header with POST requests" ,
178
180
"code" : float64 (415 )}}
179
-
181
+
180
182
if successStatus (data2 ) != false {
181
183
t .Errorf ("Status check should give false but got true" )
182
184
}
183
-
185
+
184
186
data3 := map [string ]interface {}{
185
187
"responseHeader" : map [string ]interface {}{
186
188
"status" : float64 (0 ),
@@ -200,4 +202,4 @@ func TestSuccessStatus(t *testing.T) {
200
202
if successStatus (data3 ) != true {
201
203
t .Errorf ("Status check should give true but got false" )
202
204
}
203
- }
205
+ }
0 commit comments