MXS-1220: Extend and fix REST API tests
Fixed a few broken tests and extended the monitor tests.
This commit is contained in:
@ -9,7 +9,7 @@ test -z "$MAXSCALE_DIR" && exit 1
|
||||
|
||||
maxscaledir=$MAXSCALE_DIR
|
||||
|
||||
for ((i=0;i<60;i++))
|
||||
for ((i=0;i<10;i++))
|
||||
do
|
||||
pkill maxscale || break
|
||||
sleep 0.5
|
||||
|
@ -4,7 +4,7 @@
|
||||
"repository": "https://github.com/mariadb-corporation/MaxScale",
|
||||
"description": "MaxScale REST API tests",
|
||||
"scripts": {
|
||||
"test": "mocha --timeout 60000 --slow 10000"
|
||||
"test": "mocha --timeout 30000 --slow 10000"
|
||||
},
|
||||
"author": "",
|
||||
"license": "SEE LICENSE IN ../../../../LICENSE.txt",
|
||||
|
@ -10,7 +10,7 @@ var monitor = {
|
||||
}
|
||||
}
|
||||
|
||||
describe("Creating a Monitor", function() {
|
||||
describe("Monitor", function() {
|
||||
before(startMaxScale)
|
||||
|
||||
it("create new monitor", function() {
|
||||
@ -24,7 +24,9 @@ describe("Creating a Monitor", function() {
|
||||
});
|
||||
|
||||
it("alter monitor", function() {
|
||||
monitor.data.attributes.parameters.monitor_interval = 1000
|
||||
monitor.data.attributes.parameters = {
|
||||
monitor_interval: 1000
|
||||
}
|
||||
return request.put(base_url + "/monitors/" + monitor.data.id, {json:monitor})
|
||||
.should.be.fulfilled
|
||||
});
|
||||
@ -35,9 +37,9 @@ describe("Creating a Monitor", function() {
|
||||
});
|
||||
|
||||
after(stopMaxScale)
|
||||
}
|
||||
})
|
||||
|
||||
describe("Modifying Existing Monitor", function() {
|
||||
describe("Monitor Relationships", function() {
|
||||
before(startMaxScale)
|
||||
|
||||
it("create new monitor", function() {
|
||||
@ -50,7 +52,7 @@ describe("Modifying Existing Monitor", function() {
|
||||
return request.get(base_url + "/monitors/MySQL-Monitor")
|
||||
.then(function(resp) {
|
||||
var mon = JSON.parse(resp)
|
||||
delete mon.data.relationships
|
||||
delete mon.data.relationships.servers
|
||||
return request.put(base_url + "/monitors/MySQL-Monitor", {json: mon})
|
||||
})
|
||||
.should.be.fulfilled
|
||||
@ -72,5 +74,34 @@ describe("Modifying Existing Monitor", function() {
|
||||
.should.be.fulfilled
|
||||
});
|
||||
|
||||
it("move relationships back to old monitor", function() {
|
||||
|
||||
return request.get(base_url + "/monitors/" + monitor.data.id)
|
||||
.then(function(resp) {
|
||||
var mon = JSON.parse(resp)
|
||||
delete mon.data.relationships.servers
|
||||
return request.put(base_url + "/monitors/" + monitor.data.id, {json: mon})
|
||||
})
|
||||
.then(function() {
|
||||
return request.get(base_url + "/monitors/MySQL-Monitor")
|
||||
})
|
||||
.then(function(resp) {
|
||||
var mon = JSON.parse(resp)
|
||||
mon.data.relationships.servers = [
|
||||
{id: "server1", type: "servers"},
|
||||
{id: "server2", type: "servers"},
|
||||
{id: "server3", type: "servers"},
|
||||
{id: "server4", type: "servers"},
|
||||
]
|
||||
return request.put(base_url + "/monitors/MySQL-Monitor", {json: mon})
|
||||
})
|
||||
.should.be.fulfilled
|
||||
});
|
||||
|
||||
it("destroy created monitor", function() {
|
||||
return request.delete(base_url + "/monitors/" + monitor.data.id)
|
||||
.should.be.fulfilled
|
||||
});
|
||||
|
||||
after(stopMaxScale)
|
||||
}
|
||||
})
|
||||
|
@ -2,9 +2,8 @@
|
||||
|
||||
require("../utils.js")()
|
||||
|
||||
before(startMaxScale)
|
||||
|
||||
describe("Resource Collections", function(){
|
||||
describe("Resource Collections", function() {
|
||||
before(startMaxScale)
|
||||
|
||||
var tests = [
|
||||
"/servers/",
|
||||
@ -14,20 +13,23 @@ describe("Resource Collections", function(){
|
||||
"/filters/",
|
||||
]
|
||||
|
||||
tests.forEach(function(endpoint){
|
||||
it(endpoint + ': resource should be found', function() {
|
||||
tests.forEach(function(endpoint) {
|
||||
it(endpoint + ': resource found', function() {
|
||||
return request(base_url + endpoint)
|
||||
.should.be.fulfilled
|
||||
});
|
||||
|
||||
it(endpoint + ': resource schema should be valid', function() {
|
||||
it(endpoint + ': resource schema is valid', function() {
|
||||
return request(base_url + endpoint)
|
||||
.should.eventually.satisfy(validate)
|
||||
});
|
||||
})
|
||||
|
||||
after(stopMaxScale)
|
||||
});
|
||||
|
||||
describe("Individual Resources", function(){
|
||||
describe("Individual Resources", function() {
|
||||
before(startMaxScale)
|
||||
|
||||
var tests = [
|
||||
"/servers/server1",
|
||||
@ -38,17 +40,17 @@ describe("Individual Resources", function(){
|
||||
"/sessions/1",
|
||||
]
|
||||
|
||||
tests.forEach(function(endpoint){
|
||||
it(endpoint + ': resource should be found', function() {
|
||||
tests.forEach(function(endpoint) {
|
||||
it(endpoint + ': resource found', function() {
|
||||
return request(base_url + endpoint)
|
||||
.should.be.fulfilled
|
||||
});
|
||||
|
||||
it(endpoint + ': resource schema should be valid', function() {
|
||||
it(endpoint + ': resource schema is valid', function() {
|
||||
return request(base_url + endpoint)
|
||||
.should.eventually.satisfy(validate)
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
after(stopMaxScale)
|
||||
after(stopMaxScale)
|
||||
});
|
||||
|
@ -23,26 +23,26 @@ var rel = {
|
||||
}
|
||||
};
|
||||
|
||||
describe("Creating a Server", function(){
|
||||
describe("Server", function() {
|
||||
before(startMaxScale)
|
||||
|
||||
it("create the server", function(){
|
||||
it("create new server", function() {
|
||||
return request.post(base_url + "/servers/", {json: server })
|
||||
.should.be.fulfilled
|
||||
});
|
||||
|
||||
it("request the created server", function(){
|
||||
it("request server", function() {
|
||||
return request.get(base_url + "/servers/" + server.data.id)
|
||||
.should.be.fulfilled
|
||||
});
|
||||
|
||||
it("update the created server", function(){
|
||||
it("update server", function() {
|
||||
server.data.attributes.parameters.weight = 10
|
||||
return request.put(base_url + "/servers/" + server.data.id, { json: server})
|
||||
.should.be.fulfilled
|
||||
});
|
||||
|
||||
it("destroy the server", function(){
|
||||
it("destroy server", function() {
|
||||
return request.delete(base_url + "/servers/" + server.data.id)
|
||||
.should.be.fulfilled
|
||||
});
|
||||
@ -50,30 +50,30 @@ describe("Creating a Server", function(){
|
||||
after(stopMaxScale)
|
||||
});
|
||||
|
||||
describe("Creating a Server With Relationships", function(){
|
||||
describe("Server Relationships", function() {
|
||||
before(startMaxScale)
|
||||
|
||||
// We need a deep copy of the original server
|
||||
var rel_server = JSON.parse(JSON.stringify(server))
|
||||
rel_server.data.relationships = rel
|
||||
|
||||
it("create the server", function(){
|
||||
it("create new server", function() {
|
||||
return request.post(base_url + "/servers/", {json: rel_server})
|
||||
.should.be.fulfilled
|
||||
});
|
||||
|
||||
it("request the server", function(){
|
||||
it("request server", function() {
|
||||
return request.get(base_url + "/servers/" + rel_server.data.id)
|
||||
.should.be.fulfilled
|
||||
});
|
||||
|
||||
it("remove relationships", function(){
|
||||
it("remove relationships", function() {
|
||||
delete rel_server.data["relationships"]
|
||||
return request.put(base_url + "/servers/" + rel_server.data.id, {json: rel_server})
|
||||
.should.be.fulfilled
|
||||
});
|
||||
|
||||
it("destroy the server", function(){
|
||||
it("destroy server", function() {
|
||||
return request.delete(base_url + "/servers/" + rel_server.data.id)
|
||||
.should.be.fulfilled
|
||||
});
|
||||
|
Reference in New Issue
Block a user