mirror of
https://gitlab.com/TECHNOFAB/nixtest.git
synced 2025-12-12 18:20:11 +01:00
fix: allow snapshots to use actualDrv aswell
This commit is contained in:
parent
482f15c486
commit
abac8aaf3e
3 changed files with 21 additions and 11 deletions
|
|
@ -88,8 +88,17 @@ func runTest(spec TestSpec) TestResult {
|
||||||
var actual any
|
var actual any
|
||||||
var expected any
|
var expected any
|
||||||
|
|
||||||
if spec.Type == "snapshot" {
|
if spec.ActualDrv != "" {
|
||||||
|
var err error
|
||||||
|
actual, err = buildAndParse(spec.ActualDrv)
|
||||||
|
if err != nil {
|
||||||
|
result.Error = fmt.Sprintf("[system] failed to parse drv output: %v", err.Error())
|
||||||
|
goto end
|
||||||
|
}
|
||||||
|
} else {
|
||||||
actual = spec.Actual
|
actual = spec.Actual
|
||||||
|
}
|
||||||
|
if spec.Type == "snapshot" {
|
||||||
filePath := path.Join(
|
filePath := path.Join(
|
||||||
*snapshotDir,
|
*snapshotDir,
|
||||||
fmt.Sprintf("%s.snap.json", strings.ToLower(spec.Name)),
|
fmt.Sprintf("%s.snap.json", strings.ToLower(spec.Name)),
|
||||||
|
|
@ -111,16 +120,6 @@ func runTest(spec TestSpec) TestResult {
|
||||||
goto end
|
goto end
|
||||||
}
|
}
|
||||||
} else if spec.Type == "unit" {
|
} else if spec.Type == "unit" {
|
||||||
if spec.ActualDrv != "" {
|
|
||||||
var err error
|
|
||||||
actual, err = buildAndParse(spec.ActualDrv)
|
|
||||||
if err != nil {
|
|
||||||
result.Error = fmt.Sprintf("[system] failed to parse drv output: %v", err.Error())
|
|
||||||
goto end
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
actual = spec.Actual
|
|
||||||
}
|
|
||||||
expected = spec.Expected
|
expected = spec.Expected
|
||||||
} else {
|
} else {
|
||||||
log.Panic().Str("type", spec.Type).Msg("Invalid test type")
|
log.Panic().Str("type", spec.Type).Msg("Invalid test type")
|
||||||
|
|
|
||||||
10
flake.nix
10
flake.nix
|
|
@ -52,6 +52,7 @@
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name = "fail";
|
name = "fail";
|
||||||
|
pos = __curPos;
|
||||||
expected = 0;
|
expected = 0;
|
||||||
actual = "meow";
|
actual = "meow";
|
||||||
}
|
}
|
||||||
|
|
@ -61,11 +62,20 @@
|
||||||
pos = __curPos;
|
pos = __curPos;
|
||||||
actual = "test";
|
actual = "test";
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
name = "test-snapshot-drv";
|
||||||
|
type = "snapshot";
|
||||||
|
pos = __curPos;
|
||||||
|
actualDrv = pkgs.runCommand "test-snapshot" {} ''
|
||||||
|
echo '"snapshot drv"' > $out
|
||||||
|
'';
|
||||||
|
}
|
||||||
];
|
];
|
||||||
"other-suite" = [
|
"other-suite" = [
|
||||||
{
|
{
|
||||||
name = "obj-snapshot";
|
name = "obj-snapshot";
|
||||||
type = "snapshot";
|
type = "snapshot";
|
||||||
|
pos = __curPos;
|
||||||
actual = {hello = "world";};
|
actual = {hello = "world";};
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|
|
||||||
1
snapshots/test-snapshot-drv.snap.json
Normal file
1
snapshots/test-snapshot-drv.snap.json
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
"snapshot drv"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue