diff --git a/src/main/nim/strawbosspkg/core.nim b/src/main/nim/strawbosspkg/core.nim index 1aca01e..78134f0 100644 --- a/src/main/nim/strawbosspkg/core.nim +++ b/src/main/nim/strawbosspkg/core.nim @@ -1,4 +1,4 @@ -import logging, nre, os, osproc, sequtils, streams, strtabs, strutils, tables +import logging, nre, os, osproc, sequtils, streams, strtabs, strutils, tables, uuids import private/util import configuration diff --git a/src/main/nim/strawbosspkg/server.nim b/src/main/nim/strawbosspkg/server.nim index a71b2bb..83dc4a7 100644 --- a/src/main/nim/strawbosspkg/server.nim +++ b/src/main/nim/strawbosspkg/server.nim @@ -77,7 +77,7 @@ proc spawnWorker(cfg: StrawBossConfig, req: RunRequest): Worker = let dir = mkdtemp() var args = @["run", req.projectName, req.stepName, "-r", req.buildRef, - "-w", dir, "-c", cfg.filePath, "-i", req.id] + "-w", dir, "-c", cfg.filePath, "-i", $req.id] if req.forceRebuild: args.add("-f") debug "Launching worker: " & cfg.pathToExe & " " & args.join(" ") result = Worker( diff --git a/src/test/nim/functional/tserver.nim b/src/test/nim/functional/tserver.nim index f5884c3..6780a39 100644 --- a/src/test/nim/functional/tserver.nim +++ b/src/test/nim/functional/tserver.nim @@ -1,4 +1,4 @@ -import httpclient, json, os, osproc, sequtils, strutils, tempfile, unittest, untar +import httpclient, json, os, osproc, sequtils, strutils, tempfile, times, unittest, untar from langutils import sameContents @@ -9,6 +9,7 @@ import ../../../main/nim/strawbosspkg/private/util let apiBase = "http://localhost:8180/api" let cfgFilePath = "src/test/json/strawboss.config.json" let cfg = loadStrawBossConfig(cfgFilePath) +let TIMEOUT = 2.minutes # Util template intended for use to manually review test case. # Inserting into a test case will prevent the test case from cleaning up it's @@ -39,7 +40,7 @@ suite "strawboss server": # update the repo string for the extracted test project var testProjDef = newCfg.findProject(testProjName) - testProjDef.repo = testProjTempDir & "/" & testProjName + testProjDef.repo = testProjTempDir newCfg.setProject(testProjName, testProjDef) # save the updated config and start the strawboss instance using it @@ -89,19 +90,39 @@ suite "strawboss server": test "run a successful build with artifacts": let http = newAuthenticatedHttpClient(apibase, "bob@builder.com", "password") - let resp = http.get(apiBase & "/project/" & testProjName & "/step/build/run/0.1.0" + let resp = http.post(apiBase & "/project/" & testProjName & "/step/build/run/0.1.0") check resp.status.startsWith("200") - # TODO - # check that the project directory has been created in the artifacts repo - # check that the run status file has been created in the artifacts repo - # check that the run status is not failed - # wait for the build to complete - # check that the status is "complete" - # check that the artifacts we expect are present - check false + # give the filesystem time to create stuff + sleep(100) - test "run a time-consuming build and check the status via the API" + # check that the project directory has been created in the artifacts repo + let runArtifactsDir = tempArtifactsDir & "/" & testProjName & "/build/0.1.0" + check existsDir(runArtifactsDir) + + # check that the run status file has been created in the artifacts repo + let statusFile = runArtifactsDir & "/status.json" + check fileExists(statusFile) + + # TODO + # check that the run status is not failed + var status = loadBuildStatus(statusFile) + check status.state != "failed" + + # wait for the build to complete + let expTime = getTime() + TIMEOUT + while getTime() < expTime and not contains(["complete", "failed"], status.state): + sleep(1000) + status = loadBuildStatus(statusFile) + + # check that the status is "complete" + check status.state == "complete" + + # check that the artifacts we expect are present + let binFile = runArtifactsDir & "/test_project" + check existsFile(binFile) + + test "run a time-consuming build and check the status via the API": check false # Last-chance catch to kill the server in case some test err'ed and didn't diff --git a/src/test/test-project.tar.gz b/src/test/test-project.tar.gz index c0654a2..106efe0 100644 Binary files a/src/test/test-project.tar.gz and b/src/test/test-project.tar.gz differ