Starting doing integration tests
This commit is contained in:
@@ -9,14 +9,5 @@ run-debug: debug
|
|||||||
test:
|
test:
|
||||||
GO15VENDOREXPERIMENT=1 go test `go list ./... | grep -v vendor`
|
GO15VENDOREXPERIMENT=1 go test `go list ./... | grep -v vendor`
|
||||||
|
|
||||||
macos:
|
dev-deps:
|
||||||
GO15VENDOREXPERIMENT=1 GOOS=darwin GOARCH=amd64 go install github.com/dimiro1/ipe
|
go get github.com/pusher/pusher-http-go
|
||||||
|
|
||||||
linux:
|
|
||||||
GO15VENDOREXPERIMENT=1 GOOS=linux GOARCH=amd64 go install github.com/dimiro1/ipe
|
|
||||||
|
|
||||||
windows:
|
|
||||||
GO15VENDOREXPERIMENT=1 GOOS=windows GOARCH=amd64 go install github.com/dimiro1/ipe
|
|
||||||
|
|
||||||
raspberry:
|
|
||||||
GO15VENDOREXPERIMENT=1 GOOS=linux GOARCH=arm go install github.com/dimiro1/ipe
|
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
client: go run client.go
|
||||||
|
server: go run ../main.go -config ./config.json -logtostderr
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/pusher/pusher-http-go"
|
||||||
|
)
|
||||||
|
|
||||||
|
var client pusher.Client
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
client = pusher.Client{
|
||||||
|
AppId: "1",
|
||||||
|
Key: "278d525bdf162c739803",
|
||||||
|
Secret: "7ad3753142a6693b25b9",
|
||||||
|
Host: ":8080",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func pusherPresenceAuth(res http.ResponseWriter, req *http.Request) {
|
||||||
|
presenceData := pusher.MemberData{
|
||||||
|
UserId: "1",
|
||||||
|
UserInfo: map[string]string{},
|
||||||
|
}
|
||||||
|
|
||||||
|
params, _ := ioutil.ReadAll(req.Body)
|
||||||
|
response, err := client.AuthenticatePresenceChannel(params, presenceData)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(res, string(response))
|
||||||
|
}
|
||||||
|
|
||||||
|
func pusherPrivateAuth(res http.ResponseWriter, req *http.Request) {
|
||||||
|
params, _ := ioutil.ReadAll(req.Body)
|
||||||
|
response, err := client.AuthenticatePrivateChannel(params)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(res, string(response))
|
||||||
|
}
|
||||||
|
|
||||||
|
func triggerMessage(res http.ResponseWriter, req *http.Request) {
|
||||||
|
client.Trigger("private-messages", "messages", "The message from server")
|
||||||
|
|
||||||
|
fmt.Fprintf(res, "OK")
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
http.HandleFunc("/pusher/presence/auth", pusherPresenceAuth)
|
||||||
|
http.HandleFunc("/pusher/private/auth", pusherPrivateAuth)
|
||||||
|
http.HandleFunc("/trigger", triggerMessage)
|
||||||
|
http.Handle("/", http.FileServer(http.Dir("./")))
|
||||||
|
http.ListenAndServe(":5000", nil)
|
||||||
|
}
|
||||||
@@ -1,18 +1,21 @@
|
|||||||
|
|
||||||
var assert = chai.assert;
|
var assert = chai.assert;
|
||||||
|
|
||||||
var APP_KEY = "7324d55a5eeb8f554761";
|
var APP_KEY = "278d525bdf162c739803";
|
||||||
var HOST = "localhost";
|
var HOST = "localhost";
|
||||||
var PORT = 8080;
|
var PORT = 8080;
|
||||||
|
var AUTH = "http://localhost:5000/pusher/private/auth"
|
||||||
|
var AUTH_PRESENCE = "http://localhost:5000/pusher/presence/auth"
|
||||||
|
|
||||||
Pusher.log = function(msg) {
|
Pusher.log = function(msg) {
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
function getPusher() {
|
function getPusher(auth) {
|
||||||
return new Pusher(APP_KEY, {
|
return new Pusher(APP_KEY, {
|
||||||
wsHost: HOST,
|
wsHost: HOST,
|
||||||
wsPort: PORT,
|
wsPort: PORT,
|
||||||
|
authEndpoint: auth,
|
||||||
enabledTransports: ["ws"],
|
enabledTransports: ["ws"],
|
||||||
disabledTransports: ["flash"]
|
disabledTransports: ["flash"]
|
||||||
});
|
});
|
||||||
@@ -21,8 +24,8 @@ function getPusher() {
|
|||||||
describe("Pusher", function() {
|
describe("Pusher", function() {
|
||||||
|
|
||||||
describe("connection", function() {
|
describe("connection", function() {
|
||||||
it("should connect sucessfully", function(done) {
|
it("should connect sucessfully with correct config", function(done) {
|
||||||
var pusher = getPusher();
|
var pusher = getPusher(AUTH);
|
||||||
|
|
||||||
pusher.connection.bind('connected', function() {
|
pusher.connection.bind('connected', function() {
|
||||||
assert.ok(true, "Connected");
|
assert.ok(true, "Connected");
|
||||||
@@ -30,7 +33,7 @@ describe("Pusher", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not connect", function(done) {
|
it("should not connect without the correct config", function(done) {
|
||||||
var pusher = new Pusher("INVALID_APP_KEY", {
|
var pusher = new Pusher("INVALID_APP_KEY", {
|
||||||
wsHost: HOST,
|
wsHost: HOST,
|
||||||
wsPort: PORT,
|
wsPort: PORT,
|
||||||
@@ -46,8 +49,8 @@ describe("Pusher", function() {
|
|||||||
}); // connection
|
}); // connection
|
||||||
|
|
||||||
describe("subscription", function() {
|
describe("subscription", function() {
|
||||||
it("should connect to a channel", function(done) {
|
it("should subscribe to a public channel", function(done) {
|
||||||
var pusher = getPusher();
|
var pusher = getPusher(AUTH);
|
||||||
|
|
||||||
var channel = pusher.subscribe('public-channel');
|
var channel = pusher.subscribe('public-channel');
|
||||||
channel.bind("pusher:subscription_succeeded", function(data) {
|
channel.bind("pusher:subscription_succeeded", function(data) {
|
||||||
@@ -55,11 +58,31 @@ describe("Pusher", function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should subscribe to a private channel", function(done) {
|
||||||
|
var pusher = getPusher(AUTH);
|
||||||
|
|
||||||
|
var channel = pusher.subscribe('private-channel');
|
||||||
|
channel.bind("pusher:subscription_succeeded", function(data) {
|
||||||
|
assert.ok(true, "Connected to the channel");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should subscribe to a presence channel", function(done) {
|
||||||
|
var pusher = getPusher(AUTH_PRESENCE);
|
||||||
|
|
||||||
|
var channel = pusher.subscribe('presence-channel');
|
||||||
|
channel.bind("pusher:subscription_succeeded", function(data) {
|
||||||
|
assert.ok(true, "Connected to the channel");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
}); // subscription
|
}); // subscription
|
||||||
|
|
||||||
describe("events", function() {
|
describe("events", function() {
|
||||||
it('should not allowed client events on public channels', function(done) {
|
it('should not allowed client events on public channels', function(done) {
|
||||||
var pusher = getPusher();
|
var pusher = getPusher(AUTH);
|
||||||
var channel = pusher.subscribe('public-channel');
|
var channel = pusher.subscribe('public-channel');
|
||||||
|
|
||||||
channel.bind("pusher:subscription_succeeded", function(data) {
|
channel.bind("pusher:subscription_succeeded", function(data) {
|
||||||
@@ -71,5 +94,42 @@ describe("Pusher", function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should allow client events on private channels', function(done) {
|
||||||
|
var pusher_a = getPusher(AUTH);
|
||||||
|
var pusher_b = getPusher(AUTH);
|
||||||
|
|
||||||
|
var channel_a = pusher_a.subscribe('private-channel');
|
||||||
|
var channel_b = pusher_b.subscribe('private-channel');
|
||||||
|
|
||||||
|
channel_a.bind("pusher:subscription_succeeded", function() {
|
||||||
|
channel_a.trigger("client-message", "The message");
|
||||||
|
});
|
||||||
|
|
||||||
|
channel_b.bind("client-message", function(data) {
|
||||||
|
assert.equal(data, "The message");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should publish event on private channel', function(done) {
|
||||||
|
var pusher_a = getPusher(AUTH);
|
||||||
|
var pusher_b = getPusher(AUTH);
|
||||||
|
|
||||||
|
var channel_a = pusher_a.subscribe('private-messages');
|
||||||
|
var channel_b = pusher_b.subscribe('private-messages');
|
||||||
|
|
||||||
|
channel_a.bind("pusher:subscription_succeeded", function() {
|
||||||
|
var xhttp = new XMLHttpRequest();
|
||||||
|
xhttp.open("GET", "/trigger", true);
|
||||||
|
xhttp.send();
|
||||||
|
});
|
||||||
|
|
||||||
|
channel_b.bind("messages", function(data) {
|
||||||
|
assert.equal(data, "The message from server");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
}); // events
|
}); // events
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-5
@@ -34,11 +34,7 @@ func GenerateSessionID() string {
|
|||||||
func IsChannelNameValid(channelName string) bool {
|
func IsChannelNameValid(channelName string) bool {
|
||||||
matched, err := regexp.MatchString("^[A-Za-z0-9_\\-=@,.;]+$", channelName)
|
matched, err := regexp.MatchString("^[A-Za-z0-9_\\-=@,.;]+$", channelName)
|
||||||
|
|
||||||
if err != nil {
|
if err == nil && matched {
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if matched {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user