Created
June 4, 2018 08:43
-
-
Save yasassri/55ff03c4f06de1c4becd87cb6fd5d3aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ballerina/http; | |
import ballerina/test; | |
import ballerina/config; | |
string uri = "http://0.0.0.0:9095/v1"; | |
boolean isServiceSkeletonStarted; | |
function init() { | |
// Starting the swagger based service | |
isServiceSkeletonStarted = test:startServiceSkeleton("mockservice", | |
"<PATH_TO_SWAGGER_DEFINITION>/petstore.yaml"); | |
} | |
function clean() { | |
// Stopping the swager based service | |
test:stopServiceSkeleton("mockservice"); | |
} | |
@test:Config{ | |
before: "init", | |
after: "clean" | |
} | |
function testService () { | |
endpoint http:Client httpEndpoint { | |
url:uri | |
}; | |
test:assertTrue(isServiceSkeletonStarted, msg = "Service skeleton failed to start"); | |
// Send a GET request to the specified endpoint | |
var response = httpEndpoint -> get("/pets"); | |
match response { | |
http:Response resp => { | |
var strRes = resp.getTextPayload(); | |
string expected = "Sample listPets Response"; | |
test:assertEquals(strRes, expected); | |
} | |
error err => test:assertFail(msg = "Failed to call the endpoint: "+uri); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment