Implemented GET on /projects/<proj-id> and started unit tests.
This commit is contained in:
@ -107,6 +107,10 @@ suite "load and save configuration objects":
|
||||
sameContents(pc.steps["test"].expectedEnv, @[])
|
||||
sameContents(pc.steps["test"].cmdInput, @[])
|
||||
|
||||
test "StrawBossConfig to string":
|
||||
# TODO
|
||||
check false
|
||||
|
||||
test "loadBuildStatus":
|
||||
let st = loadBuildStatus("src/test/json/test-status.json")
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
import asyncdispatch, httpclient, json, os, osproc, sequtils, strutils, times, unittest
|
||||
import asyncdispatch, httpclient, json, os, osproc, sequtils, strutils,
|
||||
tempfile, times, unittest
|
||||
|
||||
import logging
|
||||
import ./testutil
|
||||
import ../../main/nim/strawbosspkg/configuration
|
||||
import ../../main/nim/strawbosspkg/server
|
||||
import ../../main/nim/strawbosspkg/private/util
|
||||
|
||||
import strtabs
|
||||
|
||||
# test helpers
|
||||
proc newAuthenticatedHttpClient(apiBase, uname, pwd: string): HttpClient =
|
||||
result = newHttpClient()
|
||||
@ -13,20 +14,20 @@ proc newAuthenticatedHttpClient(apiBase, uname, pwd: string): HttpClient =
|
||||
assert authResp.status.startsWith("200")
|
||||
result.headers = newHttpHeaders({"Authorization": "Bearer " & parseJson(authResp.body).getStr})
|
||||
|
||||
suite "strawboss server can...":
|
||||
let apiBase = "http://localhost:8180/api"
|
||||
let cfgFilePath = "src/test/json/strawboss.config.json"
|
||||
let cfg = loadStrawBossConfig(cfgFilePath)
|
||||
|
||||
let testuser = UserRef( # note: needs to correspond to an actual user
|
||||
name: "bob@builder.com",
|
||||
hashedPwd: "$2a$11$lVZ9U4optQMhzPh0E9A7Yu6XndXblUF3gCa.zmEvJy4F.4C4718b.")
|
||||
|
||||
suite "strawboss server":
|
||||
|
||||
# suite setup code
|
||||
let cfgFilePath = "src/test/json/strawboss.config.json"
|
||||
let cfg = loadStrawBossConfig(cfgFilePath)
|
||||
|
||||
discard startProcess("./strawboss", ".", @["serve", "-c", cfgFilePath], loadEnv(), {poUsePath})
|
||||
|
||||
let http = newHttpClient()
|
||||
let apiBase = "http://localhost:8180/api"
|
||||
|
||||
let testuser = UserRef( # note: needs to correspond to an actual user
|
||||
name: "bob@builder.com",
|
||||
hashedPwd: "$2a$11$lVZ9U4optQMhzPh0E9A7Yu6XndXblUF3gCa.zmEvJy4F.4C4718b.")
|
||||
|
||||
# give the server time to spin up
|
||||
sleep(100)
|
||||
@ -88,5 +89,25 @@ suite "strawboss server can...":
|
||||
check sameContents(projects, cfg.projects)
|
||||
|
||||
# suite tear-down
|
||||
try: discard http.post(apiBase & "/service/debug/stop")
|
||||
except: discard ""
|
||||
discard newAsyncHttpClient().post(apiBase & "/service/debug/stop")
|
||||
|
||||
suite "strawboss server continued":
|
||||
|
||||
setup:
|
||||
let tmpArtifactsDir = mkdtemp()
|
||||
let (_, tmpCfgPath) = mkstemp()
|
||||
var newCfg = cfg
|
||||
newCfg.artifactsRepo = tmpArtifactsDir
|
||||
writeFile(tmpCfgPath, $newCfg)
|
||||
discard startProcess("./strawboss", ".", @["serve", "-c", tmpCfgPath], loadEnv(), {poUsePath})
|
||||
|
||||
# give the server time to spin up
|
||||
sleep(100)
|
||||
|
||||
teardown:
|
||||
discard newAsyncHttpClient().post(apiBase & "/service/debug/stop")
|
||||
|
||||
test "handle missing project configuration":
|
||||
let http = newAuthenticatedHttpClient(apibase, "bob@builder.com", "password")
|
||||
let resp = http.get(apiBase & "/projects/test-project-1")
|
||||
check resp.status.startsWith("404")
|
||||
|
Reference in New Issue
Block a user