| 36 | } |
| 37 | |
| 38 | func runTest(tc testCase) func(t *testing.T) { |
| 39 | return func(t *testing.T) { |
| 40 | if tc.stdout == nil { |
| 41 | tc.stdout = []byte{} |
| 42 | } |
| 43 | if tc.stderr == nil { |
| 44 | tc.stderr = []byte{} |
| 45 | } |
| 46 | |
| 47 | gotStdOut, gotStdErr, gotErr := runDasel(tc.args, tc.in) |
| 48 | if !errors.Is(gotErr, tc.err) && !errors.Is(tc.err, gotErr) { |
| 49 | t.Errorf("expected error %v, got %v", tc.err, gotErr) |
| 50 | return |
| 51 | } |
| 52 | |
| 53 | if !reflect.DeepEqual(tc.stderr, gotStdErr) { |
| 54 | t.Errorf("expected stderr %s, got %s", string(tc.stderr), string(gotStdErr)) |
| 55 | } |
| 56 | |
| 57 | if !reflect.DeepEqual(tc.stdout, gotStdOut) { |
| 58 | t.Errorf("expected stdout %s, got %s", string(tc.stdout), string(gotStdOut)) |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | func TestRun(t *testing.T) { |
| 64 | t.Run("complex set", func(t *testing.T) { |