|
1 | 1 | package cmd |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "fmt" |
5 | | - "os" |
6 | | - "path/filepath" |
7 | 4 | "strings" |
8 | 5 | "testing" |
9 | 6 |
|
@@ -71,155 +68,3 @@ func TestLogsRunValidations(t *testing.T) { |
71 | 68 | }) |
72 | 69 | } |
73 | 70 | } |
74 | | - |
75 | | -func TestLogsRun(t *testing.T) { |
76 | | - defer trellis.LoadFixtureProject(t)() |
77 | | - trellis := trellis.NewTrellis() |
78 | | - |
79 | | - cases := []struct { |
80 | | - name string |
81 | | - args []string |
82 | | - out string |
83 | | - code int |
84 | | - }{ |
85 | | - { |
86 | | - "default", |
87 | | - []string{"development"}, |
88 | | - "ssh vagrant@example.test tail -f /srv/www/example.com/logs/*[^gz]?", |
89 | | - 0, |
90 | | - }, |
91 | | - { |
92 | | - "access option", |
93 | | - []string{"--access", "development"}, |
94 | | - "ssh vagrant@example.test tail -f /srv/www/example.com/logs/access.log", |
95 | | - 0, |
96 | | - }, |
97 | | - { |
98 | | - "error option", |
99 | | - []string{"--error", "development"}, |
100 | | - "ssh vagrant@example.test tail -f /srv/www/example.com/logs/error.log", |
101 | | - 0, |
102 | | - }, |
103 | | - { |
104 | | - "number option", |
105 | | - []string{"--number=10", "development"}, |
106 | | - "ssh vagrant@example.test tail -n 10 -f /srv/www/example.com/logs/*[^gz]?", |
107 | | - 0, |
108 | | - }, |
109 | | - } |
110 | | - |
111 | | - for _, tc := range cases { |
112 | | - t.Run(tc.name, func(t *testing.T) { |
113 | | - ui := cli.NewMockUi() |
114 | | - defer MockUiExec(t, ui)() |
115 | | - |
116 | | - logsCommand := NewLogsCommand(ui, trellis) |
117 | | - code := logsCommand.Run(tc.args) |
118 | | - |
119 | | - if code != tc.code { |
120 | | - t.Errorf("expected code %d to be %d", code, tc.code) |
121 | | - } |
122 | | - |
123 | | - combined := ui.OutputWriter.String() + ui.ErrorWriter.String() |
124 | | - |
125 | | - if !strings.Contains(combined, tc.out) { |
126 | | - t.Errorf("expected output %q to contain %q", combined, tc.out) |
127 | | - } |
128 | | - }) |
129 | | - } |
130 | | -} |
131 | | - |
132 | | -func TestLogsRunGoAccess(t *testing.T) { |
133 | | - defer trellis.LoadFixtureProject(t)() |
134 | | - trellis := trellis.NewTrellis() |
135 | | - |
136 | | - tmpDir := t.TempDir() |
137 | | - |
138 | | - // fake goaccess binary to satisfy ok.LookPath |
139 | | - goAccessPath := filepath.Join(tmpDir, "goaccess") |
140 | | - _, _ = os.OpenFile(goAccessPath, os.O_CREATE, 0555) |
141 | | - path := os.Getenv("PATH") |
142 | | - t.Setenv("PATH", fmt.Sprintf("PATH=%s:%s", path, tmpDir)) |
143 | | - |
144 | | - cases := []struct { |
145 | | - name string |
146 | | - args []string |
147 | | - out []string |
148 | | - code int |
149 | | - }{ |
150 | | - { |
151 | | - "goaccess", |
152 | | - []string{"--goaccess", "development"}, |
153 | | - []string{ |
154 | | - "ssh vagrant@example.test tail -n +0 -f /srv/www/example.com/logs/*", |
155 | | - "goaccess --log-format=COMBINED", |
156 | | - }, |
157 | | - 0, |
158 | | - }, |
159 | | - { |
160 | | - "goaccess flags", |
161 | | - []string{"--goaccess", "--goaccess-flags=-a -m", "development"}, |
162 | | - []string{ |
163 | | - "ssh vagrant@example.test tail -n +0 -f /srv/www/example.com/logs/*", |
164 | | - "goaccess --log-format=COMBINED -a -m", |
165 | | - }, |
166 | | - 0, |
167 | | - }, |
168 | | - { |
169 | | - "goaccess with access only", |
170 | | - []string{"--goaccess", "--access", "development"}, |
171 | | - []string{ |
172 | | - "ssh vagrant@example.test tail -n +0 -f /srv/www/example.com/logs/access.log", |
173 | | - "goaccess --log-format=COMBINED", |
174 | | - }, |
175 | | - 0, |
176 | | - }, |
177 | | - { |
178 | | - "goaccess with error only", |
179 | | - []string{"--goaccess", "--error", "development"}, |
180 | | - []string{ |
181 | | - "ssh vagrant@example.test tail -n +0 -f /srv/www/example.com/logs/error.log", |
182 | | - "goaccess --log-format=COMBINED", |
183 | | - }, |
184 | | - 0, |
185 | | - }, |
186 | | - } |
187 | | - |
188 | | - for _, tc := range cases { |
189 | | - t.Run(tc.name, func(t *testing.T) { |
190 | | - ui := cli.NewMockUi() |
191 | | - defer MockUiExec(t, ui)() |
192 | | - |
193 | | - logsCommand := NewLogsCommand(ui, trellis) |
194 | | - code := logsCommand.Run(tc.args) |
195 | | - |
196 | | - if code != tc.code { |
197 | | - t.Errorf("%s - actual code %d expected to be %d", tc.name, code, tc.code) |
198 | | - } |
199 | | - |
200 | | - combined := ui.OutputWriter.String() + ui.ErrorWriter.String() |
201 | | - |
202 | | - for _, out := range tc.out { |
203 | | - if !strings.Contains(combined, out) { |
204 | | - t.Errorf("%s - actual output %q expected to contain %q", tc.name, combined, out) |
205 | | - } |
206 | | - } |
207 | | - }) |
208 | | - } |
209 | | -} |
210 | | - |
211 | | -func TestLogsHelperProcess(t *testing.T) { |
212 | | - if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" { |
213 | | - return |
214 | | - } |
215 | | - |
216 | | - switch os.Args[3] { |
217 | | - case "ssh": |
218 | | - fmt.Fprintf(os.Stdout, "nginx log") |
219 | | - os.Exit(0) |
220 | | - case "tail": |
221 | | - os.Exit(0) |
222 | | - default: |
223 | | - t.Fatalf("unexpected command %s", os.Args[3]) |
224 | | - } |
225 | | -} |
0 commit comments