-
Notifications
You must be signed in to change notification settings - Fork 201
/
restapi_test.go
60 lines (51 loc) · 2.12 KB
/
restapi_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
package main
import (
"testing"
"github.com/uniqush/uniqush-push/testutil"
)
// TestValidateSubscribers tests valid and invalid subscriber names
func TestValidateSubscribers(t *testing.T) {
validName := "valid_subscriber.123-AZ@_"
err := validateSubscribers([]string{validName})
testutil.ExpectEquals(t, nil, err, "expected valid for "+validName)
invalidName := "invalid subscriber.123"
expectedError := `invalid subscriber name: "invalid subscriber.123". Accepted characters: a-z, A-Z, 0-9, -, _, @ or .`
err = validateSubscribers([]string{invalidName})
if err == nil {
t.Errorf("Expected error for " + invalidName)
} else {
testutil.ExpectEquals(t, expectedError, err.Error(), "unexpected error message")
}
err = validateSubscribers([]string{validName, invalidName})
if err == nil {
t.Errorf("Expected error for " + invalidName)
} else {
testutil.ExpectEquals(t, expectedError, err.Error(), "unexpected error message")
}
}
// TestValidateSubscribers tests valid and invalid service names
func TestValidateService(t *testing.T) {
validName := "valid_service.123"
err := validateSubscribers([]string{validName})
testutil.ExpectEquals(t, nil, err, "expected valid for "+validName)
invalidName := "$invalid_service.123"
expectedError := `invalid service name: "$invalid_service.123". Accepted characters: a-z, A-Z, 0-9, -, _, @ or .`
err = validateService(invalidName)
if err == nil {
t.Errorf("Expected error for " + invalidName)
} else {
testutil.ExpectEquals(t, expectedError, err.Error(), "unexpected error message")
}
}
// TestValidateLegacySubscribers tests that subscribers with the buggy regex will continue to work
func TestValidateLegacySubscribers(t *testing.T) {
legacyName := `valid\legacy^[]`
err := validateSubscribers([]string{legacyName})
testutil.ExpectEquals(t, nil, err, "expected valid for "+legacyName)
}
// TestValidateLegacyService tests that services with the buggy regex will continue to work
func TestValidateLegacyService(t *testing.T) {
legacyName := `valid\legacy^[]`
err := validateSubscribers([]string{legacyName})
testutil.ExpectEquals(t, nil, err, "expected valid for "+legacyName)
}