WIP: tests, REST API support (auth).
This commit is contained in:
17
src/test/json/strawboss.config.json
Normal file
17
src/test/json/strawboss.config.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"artifactsRepo": "artifacts",
|
||||
"users": [
|
||||
{ "name": "bob@builder.com", "hashedPwd": "testvalue" },
|
||||
{ "name": "sam@sousa.com", "hashedPwd": "testvalue" }
|
||||
],
|
||||
"authSecret": "change me",
|
||||
"projects": [
|
||||
{ "name": "test-project-1",
|
||||
"repo": "/non-existent/dir",
|
||||
"cfgFilePath": "strawhat.json",
|
||||
"defaultBranch": "deploy",
|
||||
"envVars": { "VAR1": "value" }
|
||||
},
|
||||
{ "name": "test-strawboss",
|
||||
"repo": "https://git.jdb-labs.com:jdb/test-strawboss.git" } ]
|
||||
}
|
16
src/test/json/test-project-1.config.json
Normal file
16
src/test/json/test-project-1.config.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "test-project-1",
|
||||
"versionCmd": "git describe --all --always",
|
||||
"steps": {
|
||||
"build": {
|
||||
"depends": ["test"],
|
||||
"workingDir": "dir1",
|
||||
"stepCmd": "cust-build",
|
||||
"artifacts": ["bin1", "doc1"],
|
||||
"expectedEnv": ["VAR1"],
|
||||
"dontSkip": true,
|
||||
"cmdInput": ["test", "this"]
|
||||
},
|
||||
"test": { }
|
||||
}
|
||||
}
|
4
src/test/json/test-status.json
Normal file
4
src/test/json/test-status.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"state": "failed",
|
||||
"details": "some very good reason"
|
||||
}
|
BIN
src/test/nim/strawbosspkg/tconfiguration
Normal file
BIN
src/test/nim/strawbosspkg/tconfiguration
Normal file
Binary file not shown.
62
src/test/nim/strawbosspkg/tconfiguration.nim
Normal file
62
src/test/nim/strawbosspkg/tconfiguration.nim
Normal file
@ -0,0 +1,62 @@
|
||||
import strtabs, tables, unittest
|
||||
import ./testutil
|
||||
import ../../../main/nim/strawbosspkg/configuration
|
||||
|
||||
suite "load and save configuration objects":
|
||||
|
||||
test "loadStrawBossConfig":
|
||||
let cfg = loadStrawBossConfig("src/test/json/strawboss.config.json")
|
||||
let expectedUsers = @[UserRef(name: "bob@builder.com", hashedPwd: "testvalue"),
|
||||
UserRef(name: "sam@sousa.com", hashedPwd: "testvalue")]
|
||||
let expectedProjects = @[
|
||||
ProjectDef(name: "test-project-1",
|
||||
repo: "/non-existent/dir",
|
||||
defaultBranch: "deploy",
|
||||
cfgFilePath: "strawhat.json",
|
||||
envVars: newStringTable("VAR1", "value", modeCaseSensitive)),
|
||||
ProjectDef(name: "test-strawboss",
|
||||
repo: "https://git.jdb-labs.com:jdb/test-strawboss.git",
|
||||
defaultBranch: "master",
|
||||
cfgFilePath: "strawboss.json",
|
||||
envVars: newStringTable(modeCaseSensitive))]
|
||||
|
||||
check:
|
||||
cfg.artifactsRepo == "artifacts"
|
||||
cfg.authSecret == "change me"
|
||||
sameContents(expectedUsers, cfg.users)
|
||||
sameContents(expectedProjects, cfg.projects)
|
||||
|
||||
test "loadProjectConfig":
|
||||
let pc = loadProjectConfig("src/test/json/test-project-1.config.json")
|
||||
|
||||
check:
|
||||
pc.name == "test-project-1"
|
||||
pc.versionCmd == "git describe --all --always"
|
||||
pc.steps.len == 2
|
||||
|
||||
# Explicitly set properties
|
||||
pc.steps["build"].name == "build"
|
||||
pc.steps["build"].dontSkip == true
|
||||
pc.steps["build"].stepCmd == "cust-build"
|
||||
pc.steps["build"].workingDir == "dir1"
|
||||
sameContents(pc.steps["build"].artifacts, @["bin1", "doc1"])
|
||||
sameContents(pc.steps["build"].depends, @["test"])
|
||||
sameContents(pc.steps["build"].expectedEnv, @["VAR1"])
|
||||
sameContents(pc.steps["build"].cmdInput, @["test", "this"])
|
||||
|
||||
# Step with defaulted properties
|
||||
pc.steps["test"].name == "test"
|
||||
pc.steps["test"].dontSkip == false
|
||||
pc.steps["test"].stepCmd == "sh"
|
||||
pc.steps["test"].workingDir == "."
|
||||
sameContents(pc.steps["test"].artifacts, @[])
|
||||
sameContents(pc.steps["test"].depends, @[])
|
||||
sameContents(pc.steps["test"].expectedEnv, @[])
|
||||
sameContents(pc.steps["test"].cmdInput, @[])
|
||||
|
||||
test "loadBuildStatus":
|
||||
let st = loadBuildStatus("src/test/json/test-status.json")
|
||||
|
||||
check:
|
||||
st.state == "failed"
|
||||
st.details == "some very good reason"
|
52
src/test/nim/strawbosspkg/testutil.nim
Normal file
52
src/test/nim/strawbosspkg/testutil.nim
Normal file
@ -0,0 +1,52 @@
|
||||
import unittest, sequtils
|
||||
|
||||
proc sameContents*[T](a1, a2: openArray[T]): bool =
|
||||
# Answers the question: do these two arrays contain the same contents,
|
||||
# regardless of their order?
|
||||
if a1.len != a2.len: return false
|
||||
for a in a1:
|
||||
if not a2.anyIt(a == it): return false
|
||||
return true
|
||||
|
||||
type
|
||||
SimpleObj* = object
|
||||
strVal*: string
|
||||
|
||||
TestObj = object
|
||||
strVal*: string
|
||||
intVal*: int
|
||||
objVal*: SimpleObj
|
||||
|
||||
suite "testutil":
|
||||
|
||||
test "sameContents":
|
||||
let a1 = [1, 2, 3, 4]
|
||||
let a2 = [3, 2, 4, 1]
|
||||
let a3 = [1, 2, 3, 5]
|
||||
let b1 = ["this", "is", "a", "test"]
|
||||
let b2 = ["a", "test", "this", "is"]
|
||||
let b3 = ["a", "negative", "test", "this", "is"]
|
||||
let c1 = [TestObj(strVal: "a", intVal: 1, objVal: SimpleObj(strVal: "innerA")),
|
||||
TestObj(strVal: "b", intVal: 2, objVal: SimpleObj(strVal: "innerB"))]
|
||||
let c2 = [c1[1], c1[0]]
|
||||
|
||||
check:
|
||||
sameContents(a1, a2)
|
||||
sameContents(b2, b1)
|
||||
sameContents(c1, c2)
|
||||
sameContents(a1, a3) == false
|
||||
sameContents(b1, b3) == false
|
||||
|
||||
test "sameContents (seq)":
|
||||
let a1 = @[1, 2, 3, 4]
|
||||
let a2 = @[3, 2, 4, 1]
|
||||
|
||||
check:
|
||||
sameContents(a1, a2)
|
||||
|
||||
test "sameContents (cross-type)":
|
||||
let a1 = @[1, 2, 3, 4]
|
||||
let a2 = [3, 2, 4, 1]
|
||||
|
||||
check:
|
||||
sameContents(a1, a2)
|
Reference in New Issue
Block a user