1
0
Fork 0

go/workspace: fix nix-instantiate exec error typecast

Also skip nix tests on systems without nix.

Change-Id: I4c0069a429df10a496b2651c2506b2d4625d5f43
Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1585
Reviewed-by: q3k <q3k@hackerspace.pl>
master
q3k 2023-09-01 19:12:14 +02:00 committed by q3k
parent 0d3e609013
commit 54183ba222
2 changed files with 8 additions and 2 deletions

View File

@ -48,8 +48,10 @@ func EvalHscloudNix(ctx context.Context, target any, path string) error {
cmd := exec.CommandContext(ctx, "nix-instantiate", args...)
out, err := cmd.Output()
if err != nil {
eerr := err.(*exec.ExitError)
return fmt.Errorf("nix-instantiate failed: %w, stderr: %q", err, eerr.Stderr)
if eerr, ok := err.(*exec.ExitError); ok {
return fmt.Errorf("nix-instantiate failed: %w, stderr: %q", err, eerr.Stderr)
}
return fmt.Errorf("nix-instantiate failed: %w", err)
}
if err := json.Unmarshal(out, target); err != nil {

View File

@ -2,6 +2,7 @@ package workspace
import (
"context"
"os"
"testing"
"github.com/google/go-cmp/cmp"
@ -49,6 +50,9 @@ func TestCheckNixPath(t *testing.T) {
// TestEvalHscloud nix exercises EvalHscloudNix against
// //go/workspace/exports.nix.
func TestEvalHscloudNix(t *testing.T) {
if _, err := os.Stat("/nix/store"); err != nil {
t.Skip("no /nix/store")
}
ctx, ctxC := context.WithCancel(context.Background())
defer ctxC()