mirror of https://gerrit.hackerspace.pl/hscloud
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>changes/85/1585/4
parent
0d3e609013
commit
54183ba222
|
@ -48,8 +48,10 @@ func EvalHscloudNix(ctx context.Context, target any, path string) error {
|
||||||
cmd := exec.CommandContext(ctx, "nix-instantiate", args...)
|
cmd := exec.CommandContext(ctx, "nix-instantiate", args...)
|
||||||
out, err := cmd.Output()
|
out, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
eerr := err.(*exec.ExitError)
|
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, stderr: %q", err, eerr.Stderr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("nix-instantiate failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal(out, target); err != nil {
|
if err := json.Unmarshal(out, target); err != nil {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package workspace
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
@ -49,6 +50,9 @@ func TestCheckNixPath(t *testing.T) {
|
||||||
// TestEvalHscloud nix exercises EvalHscloudNix against
|
// TestEvalHscloud nix exercises EvalHscloudNix against
|
||||||
// //go/workspace/exports.nix.
|
// //go/workspace/exports.nix.
|
||||||
func TestEvalHscloudNix(t *testing.T) {
|
func TestEvalHscloudNix(t *testing.T) {
|
||||||
|
if _, err := os.Stat("/nix/store"); err != nil {
|
||||||
|
t.Skip("no /nix/store")
|
||||||
|
}
|
||||||
ctx, ctxC := context.WithCancel(context.Background())
|
ctx, ctxC := context.WithCancel(context.Background())
|
||||||
defer ctxC()
|
defer ctxC()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue