| 28 | } |
| 29 | |
| 30 | func TestParseExec(t *testing.T) { |
| 31 | content := `ONE=1 |
| 32 | TWO=2 |
| 33 | ` |
| 34 | |
| 35 | tmpFile := fs.NewFile(t, t.Name(), fs.WithContent(content)) |
| 36 | defer tmpFile.Remove() |
| 37 | |
| 38 | testcases := []struct { |
| 39 | options ExecOptions |
| 40 | configFile configfile.ConfigFile |
| 41 | expected client.ExecCreateOptions |
| 42 | }{ |
| 43 | { |
| 44 | expected: client.ExecCreateOptions{ |
| 45 | Cmd: []string{"command"}, |
| 46 | AttachStdout: true, |
| 47 | AttachStderr: true, |
| 48 | }, |
| 49 | options: withDefaultOpts(ExecOptions{}), |
| 50 | }, |
| 51 | { |
| 52 | expected: client.ExecCreateOptions{ |
| 53 | Cmd: []string{"command1", "command2"}, |
| 54 | AttachStdout: true, |
| 55 | AttachStderr: true, |
| 56 | }, |
| 57 | options: withDefaultOpts(ExecOptions{ |
| 58 | Command: []string{"command1", "command2"}, |
| 59 | }), |
| 60 | }, |
| 61 | { |
| 62 | options: withDefaultOpts(ExecOptions{ |
| 63 | Interactive: true, |
| 64 | TTY: true, |
| 65 | User: "uid", |
| 66 | }), |
| 67 | expected: client.ExecCreateOptions{ |
| 68 | User: "uid", |
| 69 | AttachStdin: true, |
| 70 | AttachStdout: true, |
| 71 | AttachStderr: true, |
| 72 | TTY: true, |
| 73 | Cmd: []string{"command"}, |
| 74 | }, |
| 75 | }, |
| 76 | { |
| 77 | options: withDefaultOpts(ExecOptions{Detach: true}), |
| 78 | expected: client.ExecCreateOptions{ |
| 79 | Cmd: []string{"command"}, |
| 80 | }, |
| 81 | }, |
| 82 | { |
| 83 | options: withDefaultOpts(ExecOptions{ |
| 84 | TTY: true, |
| 85 | Interactive: true, |
| 86 | Detach: true, |
| 87 | }), |