1package main
2
3import (
4 "os"
5 "path/filepath"
6 "testing"
7)
8
9func TestUsage(t *testing.T) {
10 if code := run(nil); code != 2 {
11 t.Fatalf("missing run: %d", code)
12 }
13 if code := run([]string{"run"}); code != 2 {
14 t.Fatalf("missing out: %d", code)
15 }
16 dir := t.TempDir()
17 p := filepath.Join(dir, "expect.json")
18 for _, text := range []string{`{"probes":[],"unexpected":1}`, `{} {}`, `{"probes":[]}{`} {
19 if err := os.WriteFile(p, []byte(text), 0600); err != nil {
20 t.Fatal(err)
21 }
22 if code := run([]string{"run", "--expect", p, "--out", filepath.Join(dir, "out")}); code != 2 {
23 t.Fatalf("%q: %d", text, code)
24 }
25 }
26}
27func TestUnpinnedFlag(t *testing.T) {
28 t.Setenv("NEFERGUI_NEFERWL", "/bin/true")
29 dir := t.TempDir()
30 if code := run([]string{"run", "--out", filepath.Join(dir, "denied")}); code != 2 {
31 t.Fatalf("override without flag: %d", code)
32 }
33 if code := run([]string{"run", "--allow-unpinned", "--out", filepath.Join(dir, "allowed"), "--timeout", "1s", "--ready-timeout", "500ms"}); code == 2 {
34 t.Fatalf("override with flag: %d", code)
35 }
36}