(t *testing.T)
| 18 | } |
| 19 | |
| 20 | func TestShellCat(t *testing.T) { |
| 21 | file, err := os.CreateTemp(".", "testFile") |
| 22 | if err != nil { |
| 23 | t.Fatal(err) |
| 24 | } |
| 25 | defer os.Remove(file.Name()) |
| 26 | |
| 27 | if _, err = file.WriteString("Hello DevSpace!"); err != nil { |
| 28 | t.Fatalf("Unable to write to temporary file %v", err) |
| 29 | } |
| 30 | |
| 31 | testCases := []testCaseShell{ |
| 32 | { |
| 33 | command: "cat " + filepath.ToSlash(file.Name()), |
| 34 | expectedOutput: "Hello DevSpace!", |
| 35 | }, |
| 36 | { |
| 37 | command: "echo 123 | cat", |
| 38 | expectedOutput: "123\n", |
| 39 | }, |
| 40 | } |
| 41 | |
| 42 | for _, testCase := range testCases { |
| 43 | stdout := &bytes.Buffer{} |
| 44 | err := ExecuteSimpleShellCommand(context.Background(), ".", expand.ListEnviron(os.Environ()...), stdout, nil, nil, testCase.command) |
| 45 | if err != nil { |
| 46 | t.Fatal(err) |
| 47 | } |
| 48 | assert.Equal(t, stdout.String(), testCase.expectedOutput) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | func TestShellCatError(t *testing.T) { |
| 53 | testCases := []testCaseShell{ |
nothing calls this directly
no test coverage detected