Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Migrate to httpRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
cachedout committed Apr 2, 2021
1 parent 01adebe commit 8134ac8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 27 deletions.
27 changes: 2 additions & 25 deletions src/test/groovy/BuildStatusTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,28 @@ import org.junit.Before
import org.junit.After
import org.junit.Test
import static org.junit.Assert.assertTrue
import com.sun.net.httpserver.HttpServer
import com.sun.net.httpserver.HttpContext
import com.sun.net.httpserver.HttpExchange
import com.sun.net.httpserver.HttpHandler

class BuildStatusTests extends ApmBasePipelineTest {


// Build a small test server
def i = new InetSocketAddress('localhost', 9999)
def HttpServer ws = HttpServer.create(i, 100)
HttpContext job_status_context = ws.createContext("/buildStatus/text")


@Override
@Before
void setUp() throws Exception {
super.setUp()
script = loadScript('vars/buildStatus.groovy')
job_status_context.setHandler({ exchange ->
String response = "Success"
exchange.responseHeaders.set("Content-Type", "text/plain;charset=utf-8")
exchange.sendResponseHeaders(200, response.getBytes().length);
OutputStream os = exchange.getResponseBody();
os.write(response.getBytes());
os.close();
exchange.Send
});
ws.start()
}

@After
void tearDown() throws Exception {
ws.stop(0)
}

@Test
void test() throws Exception {
helper.registerAllowedMethod("httpRequest", [Map.class], { "Success" })
def result = script.call(host: 'localhost:9999', job: ['apm-agent-java', 'apm-agent-java-mbp', 'master'], ssl: false)
assertTrue("Success" == result)
assertJobStatusSuccess()
}

@Test
void testBoolSuccess() throws Exception {
helper.registerAllowedMethod("httpRequest", [Map.class], { "Success" })
def result = script.call(host: 'localhost:9999', job: ['apm-agent-java', 'apm-agent-java-mbp', 'master'], return_boolean: true, ssl: false)
assertTrue(result)
}
Expand Down
4 changes: 2 additions & 2 deletions vars/buildStatus.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def call(Map args = [:]) {
def job = args.get('job', [])
def return_boolean = args.get('return_boolean', false)
def ssl = args.get('ssl', true)
def result = httpRequest(url: constructURL(host, job, ssl))
log(level: 'INFO', text: "Request result: ${result}")
def to_url = constructURL(host, job, ssl).toString()
def result = httpRequest(url: to_url)
if (return_boolean){
if (result == "Success") {
return true
Expand Down

0 comments on commit 8134ac8

Please sign in to comment.