Debian Codegraph @

core/lstreams_resolver_test.go

raw
1 package core
2
3 import (
4 "bytes"
5 _ "embed"
6 "fmt"
7 "testing"
8
9 "github.com/dimonomid/ssh_config"
10 "github.com/stretchr/testify/assert"
11 )
12
13 //go:embed resolver_testdata/ssh_config_1
14 var testSSHConfig1Str []byte
15 var testSSHConfig1 *ssh_config.Config
16
17 func init() {
18 buf := bytes.NewBuffer(testSSHConfig1Str)
19 var err error
20 testSSHConfig1, err = ssh_config.Decode(buf, false)
21 if err != nil {
22 panic(fmt.Sprintf("embedded ssh_config_1 is broken: %s", err.Error()))
23 }
24 }
25
26 var testConfigLogStreams1 = ConfigLogStreams(map[string]ConfigLogStream{
27 "myhost-01": ConfigLogStream{
28 Hostname: "host-from-nerdlog-config-01.com",
29 Port: "1001",
30 User: "user-from-nerdlog-config-01",
31 LogFiles: []string{"/from/nerdlog/config/mylog_1"},
32 },
33 "myhost-02": ConfigLogStream{
34 Hostname: "host-from-nerdlog-config-02.com",
35 Port: "1002",
36 User: "user-from-nerdlog-config-02",
37 LogFiles: []string{"/from/nerdlog/config/mylog_1", "/from/nerdlog/config/mylog_2"},
38 },
39 "myhost-03": ConfigLogStream{
40 Hostname: "host-from-nerdlog-config-03.com",
41 Port: "1003",
42 User: "user-from-nerdlog-config-03",
43 LogFiles: []string{"/from/nerdlog/config/mylog_1", "/from/nerdlog/config/mylog_2"},
44 },
45
46 "foo-01": ConfigLogStream{
47 Hostname: "host-foo-from-nerdlog-config-01.com",
48 Port: "2001",
49 User: "user-foo-from-nerdlog-config-01",
50 LogFiles: []string{"/from/nerdlog/config/foolog"},
51 },
52 "foo-02": ConfigLogStream{
53 Hostname: "host-foo-from-nerdlog-config-02.com",
54 Port: "2002",
55 User: "user-foo-from-nerdlog-config-02",
56 LogFiles: []string{"/from/nerdlog/config/foolog"},
57 },
58
59 "bar-01": ConfigLogStream{
60 Hostname: "host-bar-from-nerdlog-config-01.com",
61 User: "user-bar-from-nerdlog-config-01",
62 },
63 "bar-02": ConfigLogStream{
64 Hostname: "host-bar-from-nerdlog-config-02.com",
65 User: "user-bar-from-nerdlog-config-02",
66 },
67
68 "baz-01": ConfigLogStream{
69 LogFiles: []string{"/from/nerdlog/config/bazlog"},
70 },
71
72 "baz-02": ConfigLogStream{
73 LogFiles: []string{"/from/nerdlog/config/bazlog"},
74 },
75
76 "realhost.com": ConfigLogStream{
77 User: "user-from-nerdlog-config",
78 },
79
80 "my-with-shell-init": ConfigLogStream{
81 Hostname: "host-with-shell-init.com",
82 Options: ConfigLogStreamOptions{
83 ShellInit: []string{
84 "export TZ=UTC",
85 },
86 },
87 },
88 })
89
90 type resolverTestCase struct {
91 // name is the name of the test case
92 name string
93 // osUser is the current OS username
94 osUser string
95
96 configLogStreams ConfigLogStreams
97 sshConfig *ssh_config.Config
98
99 // input is the logstream spec string that we're feeding to Resolve()
100 input string
101
102 wantErr string
103 wantErrSSHBin string
104 // wantStreams is the expected streams when UseExternalSSH is false.
105 wantStreams map[string]LogStream
106 // wantStreamsSSHBin is the expected streams when UseExternalSSH is true. If
107 // nil, then wantStreams will be used (so the expectation is that
108 // UseExternalSSH makes not difference).
109 wantStreamsSSHBin map[string]LogStream
110 }
111
112 func runResolverTestCase(t *testing.T, tc resolverTestCase) {
113 t.Helper()
114
115 resolverSSHLib := NewLStreamsResolver(LStreamsResolverParams{
116 CurOSUser: tc.osUser,
117 ConfigLogStreams: tc.configLogStreams,
118 SSHConfig: tc.sshConfig,
119 })
120
121 resolverSSHBin := NewLStreamsResolver(LStreamsResolverParams{
122 CurOSUser: tc.osUser,
123 UseExternalSSH: true,
124 ConfigLogStreams: tc.configLogStreams,
125 SSHConfig: tc.sshConfig,
126 })
127
128 gotStreamsSSHLib, err := resolverSSHLib.Resolve(tc.input)
129
130 if tc.wantErr != "" {
131 assert.EqualError(t, err, tc.wantErr)
132 } else {
133 assert.NoError(t, err, "unexpected error without UseExternalSSH")
134 assert.Equal(t, tc.wantStreams, gotStreamsSSHLib)
135 }
136
137 gotStreamsSSHBin, err := resolverSSHBin.Resolve(tc.input)
138
139 wantErrSSHBin := tc.wantErrSSHBin
140 if wantErrSSHBin == "" {
141 wantErrSSHBin = tc.wantErr
142 }
143
144 wantStreamsSSHBin := tc.wantStreamsSSHBin
145 if wantStreamsSSHBin == nil {
146 wantStreamsSSHBin = tc.wantStreams
147 }
148
149 if wantErrSSHBin != "" {
150 assert.EqualError(t, err, wantErrSSHBin)
151 } else {
152 assert.NoError(t, err, "unexpected error with UseExternalSSH")
153 assert.Equal(t, wantStreamsSSHBin, gotStreamsSSHBin)
154 }
155 }
156
157 func TestLStreamsResolverSingleEntryNoGlob(t *testing.T) {
158 tests := []resolverTestCase{
159 {
160 name: "simple hostname only",
161 osUser: "osuser",
162 input: "myserver.com",
163 wantStreams: map[string]LogStream{
164 "myserver.com": {
165 Name: "myserver.com",
166 Transport: ConfigLogStreamShellTransport{
167 SSHLib: &ConfigLogStreamShellTransportSSHLib{
168 Host: ConfigHost{
169 Addr: "myserver.com:22",
170 User: "osuser",
171 },
172 },
173 },
174 LogFiles: []string{"auto", "auto"},
175 },
176 },
177 wantStreamsSSHBin: map[string]LogStream{
178 "myserver.com": {
179 Name: "myserver.com",
180 Transport: ConfigLogStreamShellTransport{
181 SSHBin: &ConfigLogStreamShellTransportSSHBin{
182 Host: "myserver.com",
183 },
184 },
185 LogFiles: []string{"auto", "auto"},
186 },
187 },
188 },
189 {
190 name: "hostname with user",
191 osUser: "osuser",
192 input: "[email protected]",
193 wantStreams: map[string]LogStream{
194 "[email protected]": {
195 Name: "[email protected]",
196 Transport: ConfigLogStreamShellTransport{
197 SSHLib: &ConfigLogStreamShellTransportSSHLib{
198 Host: ConfigHost{
199 Addr: "myserver.com:22",
200 User: "myuser",
201 },
202 },
203 },
204 LogFiles: []string{"auto", "auto"},
205 },
206 },
207 wantStreamsSSHBin: map[string]LogStream{
208 "[email protected]": {
209 Name: "[email protected]",
210 Transport: ConfigLogStreamShellTransport{
211 SSHBin: &ConfigLogStreamShellTransportSSHBin{
212 Host: "myserver.com",
213 User: "myuser",
214 },
215 },
216 LogFiles: []string{"auto", "auto"},
217 },
218 },
219 },
220 {
221 name: "hostname with user and port",
222 osUser: "osuser",
223 input: "[email protected]:777",
224 wantStreams: map[string]LogStream{
225 "[email protected]:777": {
226 Name: "[email protected]:777",
227 Transport: ConfigLogStreamShellTransport{
228 SSHLib: &ConfigLogStreamShellTransportSSHLib{
229 Host: ConfigHost{
230 Addr: "myserver.com:777",
231 User: "myuser",
232 },
233 },
234 },
235 LogFiles: []string{"auto", "auto"},
236 },
237 },
238 wantStreamsSSHBin: map[string]LogStream{
239 "[email protected]:777": {
240 Name: "[email protected]:777",
241 Transport: ConfigLogStreamShellTransport{
242 SSHBin: &ConfigLogStreamShellTransportSSHBin{
243 Host: "myserver.com",
244 Port: "777",
245 User: "myuser",
246 },
247 },
248 LogFiles: []string{"auto", "auto"},
249 },
250 },
251 },
252 {
253 name: "hostname with port",
254 osUser: "osuser",
255 input: "myserver.com:777",
256 wantStreams: map[string]LogStream{
257 "myserver.com:777": {
258 Name: "myserver.com:777",
259 Transport: ConfigLogStreamShellTransport{
260 SSHLib: &ConfigLogStreamShellTransportSSHLib{
261 Host: ConfigHost{
262 Addr: "myserver.com:777",
263 User: "osuser",
264 },
265 },
266 },
267 LogFiles: []string{"auto", "auto"},
268 },
269 },
270 wantStreamsSSHBin: map[string]LogStream{
271 "myserver.com:777": {
272 Name: "myserver.com:777",
273 Transport: ConfigLogStreamShellTransport{
274 SSHBin: &ConfigLogStreamShellTransportSSHBin{
275 Host: "myserver.com",
276 Port: "777",
277 },
278 },
279 LogFiles: []string{"auto", "auto"},
280 },
281 },
282 },
283 {
284 name: "hostname with user, port, and log file",
285 osUser: "osuser",
286 input: "[email protected]:22:/var/log/syslog",
287 wantStreams: map[string]LogStream{
288 "[email protected]:22:/var/log/syslog": {
289 Name: "[email protected]:22:/var/log/syslog",
290 Transport: ConfigLogStreamShellTransport{
291 SSHLib: &ConfigLogStreamShellTransportSSHLib{
292 Host: ConfigHost{
293 Addr: "myserver.com:22",
294 User: "myuser",
295 },
296 },
297 },
298 LogFiles: []string{"/var/log/syslog", "auto"},
299 },
300 },
301 wantStreamsSSHBin: map[string]LogStream{
302 "[email protected]:22:/var/log/syslog": {
303 Name: "[email protected]:22:/var/log/syslog",
304 Transport: ConfigLogStreamShellTransport{
305 SSHBin: &ConfigLogStreamShellTransportSSHBin{
306 Host: "myserver.com",
307 Port: "22",
308 User: "myuser",
309 },
310 },
311 LogFiles: []string{"/var/log/syslog", "auto"},
312 },
313 },
314 },
315 {
316 name: "hostname with user, port, and different log file",
317 osUser: "osuser",
318 input: "[email protected]:22:/var/log/auth.log",
319 wantStreams: map[string]LogStream{
320 "[email protected]:22:/var/log/auth.log": {
321 Name: "[email protected]:22:/var/log/auth.log",
322 Transport: ConfigLogStreamShellTransport{
323 SSHLib: &ConfigLogStreamShellTransportSSHLib{
324 Host: ConfigHost{
325 Addr: "myserver.com:22",
326 User: "myuser",
327 },
328 },
329 },
330 LogFiles: []string{"/var/log/auth.log", "auto"},
331 },
332 },
333 wantStreamsSSHBin: map[string]LogStream{
334 "[email protected]:22:/var/log/auth.log": {
335 Name: "[email protected]:22:/var/log/auth.log",
336 Transport: ConfigLogStreamShellTransport{
337 SSHBin: &ConfigLogStreamShellTransportSSHBin{
338 Host: "myserver.com",
339 Port: "22",
340 User: "myuser",
341 },
342 },
343 LogFiles: []string{"/var/log/auth.log", "auto"},
344 },
345 },
346 },
347 {
348 name: "hostname with user, port, and two log files",
349 osUser: "osuser",
350 input: "[email protected]:22:/var/log/mylog_last:/var/log/mylog_prev",
351 wantStreams: map[string]LogStream{
352 "[email protected]:22:/var/log/mylog_last:/var/log/mylog_prev": {
353 Name: "[email protected]:22:/var/log/mylog_last:/var/log/mylog_prev",
354 Transport: ConfigLogStreamShellTransport{
355 SSHLib: &ConfigLogStreamShellTransportSSHLib{
356 Host: ConfigHost{
357 Addr: "myserver.com:22",
358 User: "myuser",
359 },
360 },
361 },
362 LogFiles: []string{"/var/log/mylog_last", "/var/log/mylog_prev"},
363 },
364 },
365 wantStreamsSSHBin: map[string]LogStream{
366 "[email protected]:22:/var/log/mylog_last:/var/log/mylog_prev": {
367 Name: "[email protected]:22:/var/log/mylog_last:/var/log/mylog_prev",
368 Transport: ConfigLogStreamShellTransport{
369 SSHBin: &ConfigLogStreamShellTransportSSHBin{
370 Host: "myserver.com",
371 Port: "22",
372 User: "myuser",
373 },
374 },
375 LogFiles: []string{"/var/log/mylog_last", "/var/log/mylog_prev"},
376 },
377 },
378 },
379 {
380 name: "empty string is allowed",
381 osUser: "myuser",
382 input: "",
383 wantStreams: map[string]LogStream{},
384 wantStreamsSSHBin: map[string]LogStream{},
385 },
386 {
387 name: "empty string with whitespaces is allowed",
388 osUser: "myuser",
389 input: "", // TODO it's the same as previous case
390 wantStreams: map[string]LogStream{},
391 wantStreamsSSHBin: map[string]LogStream{},
392 },
393 }
394
395 for _, tt := range tests {
396 t.Run(tt.name, func(t *testing.T) {
397 runResolverTestCase(t, tt)
398 })
399 }
400 }
401
402 func TestLStreamsResolverMultipleEntriesNoGlob(t *testing.T) {
403 tests := []resolverTestCase{
404 {
405 name: "two hosts with defaults",
406 osUser: "osuser",
407 input: "host1.com,host2.com",
408 wantStreams: map[string]LogStream{
409 "host1.com": {
410 Name: "host1.com",
411 Transport: ConfigLogStreamShellTransport{
412 SSHLib: &ConfigLogStreamShellTransportSSHLib{
413 Host: ConfigHost{
414 Addr: "host1.com:22",
415 User: "osuser",
416 },
417 },
418 },
419 LogFiles: []string{"auto", "auto"},
420 },
421 "host2.com": {
422 Name: "host2.com",
423 Transport: ConfigLogStreamShellTransport{
424 SSHLib: &ConfigLogStreamShellTransportSSHLib{
425 Host: ConfigHost{
426 Addr: "host2.com:22",
427 User: "osuser",
428 },
429 },
430 },
431 LogFiles: []string{"auto", "auto"},
432 },
433 },
434 wantStreamsSSHBin: map[string]LogStream{
435 "host1.com": {
436 Name: "host1.com",
437 Transport: ConfigLogStreamShellTransport{
438 SSHBin: &ConfigLogStreamShellTransportSSHBin{
439 Host: "host1.com",
440 },
441 },
442 LogFiles: []string{"auto", "auto"},
443 },
444 "host2.com": {
445 Name: "host2.com",
446 Transport: ConfigLogStreamShellTransport{
447 SSHBin: &ConfigLogStreamShellTransportSSHBin{
448 Host: "host2.com",
449 },
450 },
451 LogFiles: []string{"auto", "auto"},
452 },
453 },
454 },
455 {
456 name: "mixed full and partial formats",
457 osUser: "osuser",
458 input: "[email protected]:2200:/a.log:/b.log, [email protected]",
459 wantStreams: map[string]LogStream{
460 "[email protected]:2200:/a.log:/b.log": {
461 Name: "[email protected]:2200:/a.log:/b.log",
462 Transport: ConfigLogStreamShellTransport{
463 SSHLib: &ConfigLogStreamShellTransportSSHLib{
464 Host: ConfigHost{
465 Addr: "foo.com:2200",
466 User: "alice",
467 },
468 },
469 },
470 LogFiles: []string{"/a.log", "/b.log"},
471 },
472 "[email protected]": {
473 Name: "[email protected]",
474 Transport: ConfigLogStreamShellTransport{
475 SSHLib: &ConfigLogStreamShellTransportSSHLib{
476 Host: ConfigHost{
477 Addr: "bar.com:22",
478 User: "bob",
479 },
480 },
481 },
482 LogFiles: []string{"auto", "auto"},
483 },
484 },
485 wantStreamsSSHBin: map[string]LogStream{
486 "[email protected]:2200:/a.log:/b.log": {
487 Name: "[email protected]:2200:/a.log:/b.log",
488 Transport: ConfigLogStreamShellTransport{
489 SSHBin: &ConfigLogStreamShellTransportSSHBin{
490 Host: "foo.com",
491 Port: "2200",
492 User: "alice",
493 },
494 },
495 LogFiles: []string{"/a.log", "/b.log"},
496 },
497 "[email protected]": {
498 Name: "[email protected]",
499 Transport: ConfigLogStreamShellTransport{
500 SSHBin: &ConfigLogStreamShellTransportSSHBin{
501 Host: "bar.com",
502 User: "bob",
503 },
504 },
505 LogFiles: []string{"auto", "auto"},
506 },
507 },
508 },
509 {
510 name: "second entry is empty",
511 osUser: "osuser",
512 input: "[email protected]:2200:/a.log:/b.log, , [email protected]",
513 wantErr: "entry #2 is empty",
514 },
515 {
516 name: "error in second entry",
517 osUser: "osuser",
518 input: "valid.com,myuser@",
519 wantErr: "parsing entry #2 (myuser@): parsing \"myuser@\" as a logstream: no hostname",
520 },
521 {
522 name: "empty input with comma",
523 osUser: "osuser",
524 input: ",",
525 wantErr: "entry #1 is empty",
526 },
527 }
528
529 for _, tt := range tests {
530 t.Run(tt.name, func(t *testing.T) {
531 runResolverTestCase(t, tt)
532 })
533 }
534 }
535
536 func TestLStreamsResolverGlobOnlyNerdlogConfig(t *testing.T) {
537 tests := []resolverTestCase{
538 {
539 name: "single glob, everything is taken from nerdlog config",
540 osUser: "osuser",
541
542 configLogStreams: testConfigLogStreams1,
543 input: "myhost-*",
544
545 wantStreams: map[string]LogStream{
546 "myhost-01": {
547 Name: "myhost-01",
548 Transport: ConfigLogStreamShellTransport{
549 SSHLib: &ConfigLogStreamShellTransportSSHLib{
550 Host: ConfigHost{
551 Addr: "host-from-nerdlog-config-01.com:1001",
552 User: "user-from-nerdlog-config-01",
553 },
554 },
555 },
556 LogFiles: []string{"/from/nerdlog/config/mylog_1", "auto"},
557 },
558 "myhost-02": {
559 Name: "myhost-02",
560 Transport: ConfigLogStreamShellTransport{
561 SSHLib: &ConfigLogStreamShellTransportSSHLib{
562 Host: ConfigHost{
563 Addr: "host-from-nerdlog-config-02.com:1002",
564 User: "user-from-nerdlog-config-02",
565 },
566 },
567 },
568 LogFiles: []string{"/from/nerdlog/config/mylog_1", "/from/nerdlog/config/mylog_2"},
569 },
570 "myhost-03": {
571 Name: "myhost-03",
572 Transport: ConfigLogStreamShellTransport{
573 SSHLib: &ConfigLogStreamShellTransportSSHLib{
574 Host: ConfigHost{
575 Addr: "host-from-nerdlog-config-03.com:1003",
576 User: "user-from-nerdlog-config-03",
577 },
578 },
579 },
580 LogFiles: []string{"/from/nerdlog/config/mylog_1", "/from/nerdlog/config/mylog_2"},
581 },
582 },
583 wantStreamsSSHBin: map[string]LogStream{
584 "myhost-01": {
585 Name: "myhost-01",
586 Transport: ConfigLogStreamShellTransport{
587 SSHBin: &ConfigLogStreamShellTransportSSHBin{
588 Host: "host-from-nerdlog-config-01.com",
589 Port: "1001",
590 User: "user-from-nerdlog-config-01",
591 },
592 },
593 LogFiles: []string{"/from/nerdlog/config/mylog_1", "auto"},
594 },
595 "myhost-02": {
596 Name: "myhost-02",
597 Transport: ConfigLogStreamShellTransport{
598 SSHBin: &ConfigLogStreamShellTransportSSHBin{
599 Host: "host-from-nerdlog-config-02.com",
600 Port: "1002",
601 User: "user-from-nerdlog-config-02",
602 },
603 },
604 LogFiles: []string{"/from/nerdlog/config/mylog_1", "/from/nerdlog/config/mylog_2"},
605 },
606 "myhost-03": {
607 Name: "myhost-03",
608 Transport: ConfigLogStreamShellTransport{
609 SSHBin: &ConfigLogStreamShellTransportSSHBin{
610 Host: "host-from-nerdlog-config-03.com",
611 Port: "1003",
612 User: "user-from-nerdlog-config-03",
613 },
614 },
615 LogFiles: []string{"/from/nerdlog/config/mylog_1", "/from/nerdlog/config/mylog_2"},
616 },
617 },
618 },
619 {
620 name: "two globs, everything is taken from nerdlog config",
621 osUser: "osuser",
622
623 configLogStreams: testConfigLogStreams1,
624 input: "myhost-*, foo-*",
625
626 wantStreams: map[string]LogStream{
627 "myhost-01": {
628 Name: "myhost-01",
629 Transport: ConfigLogStreamShellTransport{
630 SSHLib: &ConfigLogStreamShellTransportSSHLib{
631 Host: ConfigHost{
632 Addr: "host-from-nerdlog-config-01.com:1001",
633 User: "user-from-nerdlog-config-01",
634 },
635 },
636 },
637 LogFiles: []string{"/from/nerdlog/config/mylog_1", "auto"},
638 },
639 "myhost-02": {
640 Name: "myhost-02",
641 Transport: ConfigLogStreamShellTransport{
642 SSHLib: &ConfigLogStreamShellTransportSSHLib{
643 Host: ConfigHost{
644 Addr: "host-from-nerdlog-config-02.com:1002",
645 User: "user-from-nerdlog-config-02",
646 },
647 },
648 },
649 LogFiles: []string{"/from/nerdlog/config/mylog_1", "/from/nerdlog/config/mylog_2"},
650 },
651 "myhost-03": {
652 Name: "myhost-03",
653 Transport: ConfigLogStreamShellTransport{
654 SSHLib: &ConfigLogStreamShellTransportSSHLib{
655 Host: ConfigHost{
656 Addr: "host-from-nerdlog-config-03.com:1003",
657 User: "user-from-nerdlog-config-03",
658 },
659 },
660 },
661 LogFiles: []string{"/from/nerdlog/config/mylog_1", "/from/nerdlog/config/mylog_2"},
662 },
663
664 "foo-01": {
665 Name: "foo-01",
666 Transport: ConfigLogStreamShellTransport{
667 SSHLib: &ConfigLogStreamShellTransportSSHLib{
668 Host: ConfigHost{
669 Addr: "host-foo-from-nerdlog-config-01.com:2001",
670 User: "user-foo-from-nerdlog-config-01",
671 },
672 },
673 },
674 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
675 },
676 "foo-02": {
677 Name: "foo-02",
678 Transport: ConfigLogStreamShellTransport{
679 SSHLib: &ConfigLogStreamShellTransportSSHLib{
680 Host: ConfigHost{
681 Addr: "host-foo-from-nerdlog-config-02.com:2002",
682 User: "user-foo-from-nerdlog-config-02",
683 },
684 },
685 },
686 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
687 },
688 },
689 wantStreamsSSHBin: map[string]LogStream{
690 "myhost-01": {
691 Name: "myhost-01",
692 Transport: ConfigLogStreamShellTransport{
693 SSHBin: &ConfigLogStreamShellTransportSSHBin{
694 Host: "host-from-nerdlog-config-01.com",
695 Port: "1001",
696 User: "user-from-nerdlog-config-01",
697 },
698 },
699 LogFiles: []string{"/from/nerdlog/config/mylog_1", "auto"},
700 },
701 "myhost-02": {
702 Name: "myhost-02",
703 Transport: ConfigLogStreamShellTransport{
704 SSHBin: &ConfigLogStreamShellTransportSSHBin{
705 Host: "host-from-nerdlog-config-02.com",
706 Port: "1002",
707 User: "user-from-nerdlog-config-02",
708 },
709 },
710 LogFiles: []string{"/from/nerdlog/config/mylog_1", "/from/nerdlog/config/mylog_2"},
711 },
712 "myhost-03": {
713 Name: "myhost-03",
714 Transport: ConfigLogStreamShellTransport{
715 SSHBin: &ConfigLogStreamShellTransportSSHBin{
716 Host: "host-from-nerdlog-config-03.com",
717 Port: "1003",
718 User: "user-from-nerdlog-config-03",
719 },
720 },
721 LogFiles: []string{"/from/nerdlog/config/mylog_1", "/from/nerdlog/config/mylog_2"},
722 },
723
724 "foo-01": {
725 Name: "foo-01",
726 Transport: ConfigLogStreamShellTransport{
727 SSHBin: &ConfigLogStreamShellTransportSSHBin{
728 Host: "host-foo-from-nerdlog-config-01.com",
729 Port: "2001",
730 User: "user-foo-from-nerdlog-config-01",
731 },
732 },
733 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
734 },
735 "foo-02": {
736 Name: "foo-02",
737 Transport: ConfigLogStreamShellTransport{
738 SSHBin: &ConfigLogStreamShellTransportSSHBin{
739 Host: "host-foo-from-nerdlog-config-02.com",
740 Port: "2002",
741 User: "user-foo-from-nerdlog-config-02",
742 },
743 },
744 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
745 },
746 },
747 },
748
749 {
750 name: "single glob, everything is taken from nerdlog config, but port and logfiles are defaults",
751 osUser: "osuser",
752
753 configLogStreams: testConfigLogStreams1,
754 input: "bar-*",
755
756 wantStreams: map[string]LogStream{
757 "bar-01": {
758 Name: "bar-01",
759 Transport: ConfigLogStreamShellTransport{
760 SSHLib: &ConfigLogStreamShellTransportSSHLib{
761 Host: ConfigHost{
762 Addr: "host-bar-from-nerdlog-config-01.com:22",
763 User: "user-bar-from-nerdlog-config-01",
764 },
765 },
766 },
767 LogFiles: []string{"auto", "auto"},
768 },
769 "bar-02": {
770 Name: "bar-02",
771 Transport: ConfigLogStreamShellTransport{
772 SSHLib: &ConfigLogStreamShellTransportSSHLib{
773 Host: ConfigHost{
774 Addr: "host-bar-from-nerdlog-config-02.com:22",
775 User: "user-bar-from-nerdlog-config-02",
776 },
777 },
778 },
779 LogFiles: []string{"auto", "auto"},
780 },
781 },
782 wantStreamsSSHBin: map[string]LogStream{
783 "bar-01": {
784 Name: "bar-01",
785 Transport: ConfigLogStreamShellTransport{
786 SSHBin: &ConfigLogStreamShellTransportSSHBin{
787 Host: "host-bar-from-nerdlog-config-01.com",
788 User: "user-bar-from-nerdlog-config-01",
789 },
790 },
791 LogFiles: []string{"auto", "auto"},
792 },
793 "bar-02": {
794 Name: "bar-02",
795 Transport: ConfigLogStreamShellTransport{
796 SSHBin: &ConfigLogStreamShellTransportSSHBin{
797 Host: "host-bar-from-nerdlog-config-02.com",
798 User: "user-bar-from-nerdlog-config-02",
799 },
800 },
801 LogFiles: []string{"auto", "auto"},
802 },
803 },
804 },
805
806 {
807 name: "one glob, port is overridden by the input",
808 osUser: "osuser",
809
810 configLogStreams: testConfigLogStreams1,
811 input: "foo-*:123",
812
813 wantStreams: map[string]LogStream{
814 "foo-01:123": {
815 Name: "foo-01:123",
816 Transport: ConfigLogStreamShellTransport{
817 SSHLib: &ConfigLogStreamShellTransportSSHLib{
818 Host: ConfigHost{
819 Addr: "host-foo-from-nerdlog-config-01.com:123",
820 User: "user-foo-from-nerdlog-config-01",
821 },
822 },
823 },
824 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
825 },
826 "foo-02:123": {
827 Name: "foo-02:123",
828 Transport: ConfigLogStreamShellTransport{
829 SSHLib: &ConfigLogStreamShellTransportSSHLib{
830 Host: ConfigHost{
831 Addr: "host-foo-from-nerdlog-config-02.com:123",
832 User: "user-foo-from-nerdlog-config-02",
833 },
834 },
835 },
836 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
837 },
838 },
839 wantStreamsSSHBin: map[string]LogStream{
840 "foo-01:123": {
841 Name: "foo-01:123",
842 Transport: ConfigLogStreamShellTransport{
843 SSHBin: &ConfigLogStreamShellTransportSSHBin{
844 Host: "host-foo-from-nerdlog-config-01.com",
845 Port: "123",
846 User: "user-foo-from-nerdlog-config-01",
847 },
848 },
849 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
850 },
851 "foo-02:123": {
852 Name: "foo-02:123",
853 Transport: ConfigLogStreamShellTransport{
854 SSHBin: &ConfigLogStreamShellTransportSSHBin{
855 Host: "host-foo-from-nerdlog-config-02.com",
856 Port: "123",
857 User: "user-foo-from-nerdlog-config-02",
858 },
859 },
860 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
861 },
862 },
863 },
864
865 {
866 name: "one glob, user is overridden by the input",
867 osUser: "osuser",
868
869 configLogStreams: testConfigLogStreams1,
870 input: "customuser@foo-*",
871
872 wantStreams: map[string]LogStream{
873 "customuser@foo-01": {
874 Name: "customuser@foo-01",
875 Transport: ConfigLogStreamShellTransport{
876 SSHLib: &ConfigLogStreamShellTransportSSHLib{
877 Host: ConfigHost{
878 Addr: "host-foo-from-nerdlog-config-01.com:2001",
879 User: "customuser",
880 },
881 },
882 },
883 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
884 },
885 "customuser@foo-02": {
886 Name: "customuser@foo-02",
887 Transport: ConfigLogStreamShellTransport{
888 SSHLib: &ConfigLogStreamShellTransportSSHLib{
889 Host: ConfigHost{
890 Addr: "host-foo-from-nerdlog-config-02.com:2002",
891 User: "customuser",
892 },
893 },
894 },
895 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
896 },
897 },
898 wantStreamsSSHBin: map[string]LogStream{
899 "customuser@foo-01": {
900 Name: "customuser@foo-01",
901 Transport: ConfigLogStreamShellTransport{
902 SSHBin: &ConfigLogStreamShellTransportSSHBin{
903 Host: "host-foo-from-nerdlog-config-01.com",
904 Port: "2001",
905 User: "customuser",
906 },
907 },
908 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
909 },
910 "customuser@foo-02": {
911 Name: "customuser@foo-02",
912 Transport: ConfigLogStreamShellTransport{
913 SSHBin: &ConfigLogStreamShellTransportSSHBin{
914 Host: "host-foo-from-nerdlog-config-02.com",
915 Port: "2002",
916 User: "customuser",
917 },
918 },
919 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
920 },
921 },
922 },
923
924 {
925 name: "one glob, first logfile is overridden by the input, second is inferred",
926 osUser: "osuser",
927
928 configLogStreams: testConfigLogStreams1,
929 input: "foo-*::/var/log/custom",
930
931 wantStreams: map[string]LogStream{
932 "foo-01::/var/log/custom": {
933 Name: "foo-01::/var/log/custom",
934 Transport: ConfigLogStreamShellTransport{
935 SSHLib: &ConfigLogStreamShellTransportSSHLib{
936 Host: ConfigHost{
937 Addr: "host-foo-from-nerdlog-config-01.com:2001",
938 User: "user-foo-from-nerdlog-config-01",
939 },
940 },
941 },
942 LogFiles: []string{"/var/log/custom", "auto"},
943 },
944 "foo-02::/var/log/custom": {
945 Name: "foo-02::/var/log/custom",
946 Transport: ConfigLogStreamShellTransport{
947 SSHLib: &ConfigLogStreamShellTransportSSHLib{
948 Host: ConfigHost{
949 Addr: "host-foo-from-nerdlog-config-02.com:2002",
950 User: "user-foo-from-nerdlog-config-02",
951 },
952 },
953 },
954 LogFiles: []string{"/var/log/custom", "auto"},
955 },
956 },
957 wantStreamsSSHBin: map[string]LogStream{
958 "foo-01::/var/log/custom": {
959 Name: "foo-01::/var/log/custom",
960 Transport: ConfigLogStreamShellTransport{
961 SSHBin: &ConfigLogStreamShellTransportSSHBin{
962 Host: "host-foo-from-nerdlog-config-01.com",
963 Port: "2001",
964 User: "user-foo-from-nerdlog-config-01",
965 },
966 },
967 LogFiles: []string{"/var/log/custom", "auto"},
968 },
969 "foo-02::/var/log/custom": {
970 Name: "foo-02::/var/log/custom",
971 Transport: ConfigLogStreamShellTransport{
972 SSHBin: &ConfigLogStreamShellTransportSSHBin{
973 Host: "host-foo-from-nerdlog-config-02.com",
974 Port: "2002",
975 User: "user-foo-from-nerdlog-config-02",
976 },
977 },
978 LogFiles: []string{"/var/log/custom", "auto"},
979 },
980 },
981 },
982
983 {
984 name: "one glob, both logfiles are overridden by the input",
985 osUser: "osuser",
986
987 configLogStreams: testConfigLogStreams1,
988 input: "foo-*::/var/log/custom:/var/log/custom_prev",
989
990 wantStreams: map[string]LogStream{
991 "foo-01::/var/log/custom:/var/log/custom_prev": {
992 Name: "foo-01::/var/log/custom:/var/log/custom_prev",
993 Transport: ConfigLogStreamShellTransport{
994 SSHLib: &ConfigLogStreamShellTransportSSHLib{
995 Host: ConfigHost{
996 Addr: "host-foo-from-nerdlog-config-01.com:2001",
997 User: "user-foo-from-nerdlog-config-01",
998 },
999 },
1000 },
1001 LogFiles: []string{"/var/log/custom", "/var/log/custom_prev"},
1002 },
1003 "foo-02::/var/log/custom:/var/log/custom_prev": {
1004 Name: "foo-02::/var/log/custom:/var/log/custom_prev",
1005 Transport: ConfigLogStreamShellTransport{
1006 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1007 Host: ConfigHost{
1008 Addr: "host-foo-from-nerdlog-config-02.com:2002",
1009 User: "user-foo-from-nerdlog-config-02",
1010 },
1011 },
1012 },
1013 LogFiles: []string{"/var/log/custom", "/var/log/custom_prev"},
1014 },
1015 },
1016 wantStreamsSSHBin: map[string]LogStream{
1017 "foo-01::/var/log/custom:/var/log/custom_prev": {
1018 Name: "foo-01::/var/log/custom:/var/log/custom_prev",
1019 Transport: ConfigLogStreamShellTransport{
1020 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1021 Host: "host-foo-from-nerdlog-config-01.com",
1022 Port: "2001",
1023 User: "user-foo-from-nerdlog-config-01",
1024 },
1025 },
1026 LogFiles: []string{"/var/log/custom", "/var/log/custom_prev"},
1027 },
1028 "foo-02::/var/log/custom:/var/log/custom_prev": {
1029 Name: "foo-02::/var/log/custom:/var/log/custom_prev",
1030 Transport: ConfigLogStreamShellTransport{
1031 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1032 Host: "host-foo-from-nerdlog-config-02.com",
1033 Port: "2002",
1034 User: "user-foo-from-nerdlog-config-02",
1035 },
1036 },
1037 LogFiles: []string{"/var/log/custom", "/var/log/custom_prev"},
1038 },
1039 },
1040 },
1041
1042 {
1043 name: "one glob, everything is overridden by the input",
1044 osUser: "osuser",
1045
1046 configLogStreams: testConfigLogStreams1,
1047 input: "customuser@foo-*:444:/var/log/custom:/var/log/custom_prev",
1048
1049 wantStreams: map[string]LogStream{
1050 "customuser@foo-01:444:/var/log/custom:/var/log/custom_prev": {
1051 Name: "customuser@foo-01:444:/var/log/custom:/var/log/custom_prev",
1052 Transport: ConfigLogStreamShellTransport{
1053 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1054 Host: ConfigHost{
1055 Addr: "host-foo-from-nerdlog-config-01.com:444",
1056 User: "customuser",
1057 },
1058 },
1059 },
1060 LogFiles: []string{"/var/log/custom", "/var/log/custom_prev"},
1061 },
1062 "customuser@foo-02:444:/var/log/custom:/var/log/custom_prev": {
1063 Name: "customuser@foo-02:444:/var/log/custom:/var/log/custom_prev",
1064 Transport: ConfigLogStreamShellTransport{
1065 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1066 Host: ConfigHost{
1067 Addr: "host-foo-from-nerdlog-config-02.com:444",
1068 User: "customuser",
1069 },
1070 },
1071 },
1072 LogFiles: []string{"/var/log/custom", "/var/log/custom_prev"},
1073 },
1074 },
1075 wantStreamsSSHBin: map[string]LogStream{
1076 "customuser@foo-01:444:/var/log/custom:/var/log/custom_prev": {
1077 Name: "customuser@foo-01:444:/var/log/custom:/var/log/custom_prev",
1078 Transport: ConfigLogStreamShellTransport{
1079 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1080 Host: "host-foo-from-nerdlog-config-01.com",
1081 Port: "444",
1082 User: "customuser",
1083 },
1084 },
1085 LogFiles: []string{"/var/log/custom", "/var/log/custom_prev"},
1086 },
1087 "customuser@foo-02:444:/var/log/custom:/var/log/custom_prev": {
1088 Name: "customuser@foo-02:444:/var/log/custom:/var/log/custom_prev",
1089 Transport: ConfigLogStreamShellTransport{
1090 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1091 Host: "host-foo-from-nerdlog-config-02.com",
1092 Port: "444",
1093 User: "customuser",
1094 },
1095 },
1096 LogFiles: []string{"/var/log/custom", "/var/log/custom_prev"},
1097 },
1098 },
1099 },
1100
1101 {
1102 name: "exact match without globs",
1103 osUser: "osuser",
1104
1105 configLogStreams: testConfigLogStreams1,
1106 input: "foo-01",
1107
1108 wantStreams: map[string]LogStream{
1109 "foo-01": {
1110 Name: "foo-01",
1111 Transport: ConfigLogStreamShellTransport{
1112 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1113 Host: ConfigHost{
1114 Addr: "host-foo-from-nerdlog-config-01.com:2001",
1115 User: "user-foo-from-nerdlog-config-01",
1116 },
1117 },
1118 },
1119 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
1120 },
1121 },
1122 wantStreamsSSHBin: map[string]LogStream{
1123 "foo-01": {
1124 Name: "foo-01",
1125 Transport: ConfigLogStreamShellTransport{
1126 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1127 Host: "host-foo-from-nerdlog-config-01.com",
1128 Port: "2001",
1129 User: "user-foo-from-nerdlog-config-01",
1130 },
1131 },
1132 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
1133 },
1134 },
1135 },
1136
1137 {
1138 name: "exact match without globs, user is taken from the input",
1139 osUser: "osuser",
1140
1141 configLogStreams: testConfigLogStreams1,
1142 input: "customuser@foo-01",
1143
1144 wantStreams: map[string]LogStream{
1145 "customuser@foo-01": {
1146 Name: "customuser@foo-01",
1147 Transport: ConfigLogStreamShellTransport{
1148 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1149 Host: ConfigHost{
1150 Addr: "host-foo-from-nerdlog-config-01.com:2001",
1151 User: "customuser",
1152 },
1153 },
1154 },
1155 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
1156 },
1157 },
1158 wantStreamsSSHBin: map[string]LogStream{
1159 "customuser@foo-01": {
1160 Name: "customuser@foo-01",
1161 Transport: ConfigLogStreamShellTransport{
1162 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1163 Host: "host-foo-from-nerdlog-config-01.com",
1164 Port: "2001",
1165 User: "customuser",
1166 },
1167 },
1168 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
1169 },
1170 },
1171 },
1172
1173 {
1174 name: "different files from the same hosts",
1175 osUser: "osuser",
1176
1177 configLogStreams: testConfigLogStreams1,
1178 input: "foo-*, foo-*::/var/log/custom",
1179
1180 wantStreams: map[string]LogStream{
1181 "foo-01": {
1182 Name: "foo-01",
1183 Transport: ConfigLogStreamShellTransport{
1184 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1185 Host: ConfigHost{
1186 Addr: "host-foo-from-nerdlog-config-01.com:2001",
1187 User: "user-foo-from-nerdlog-config-01",
1188 },
1189 },
1190 },
1191 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
1192 },
1193 "foo-02": {
1194 Name: "foo-02",
1195 Transport: ConfigLogStreamShellTransport{
1196 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1197 Host: ConfigHost{
1198 Addr: "host-foo-from-nerdlog-config-02.com:2002",
1199 User: "user-foo-from-nerdlog-config-02",
1200 },
1201 },
1202 },
1203 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
1204 },
1205
1206 "foo-01::/var/log/custom": {
1207 Name: "foo-01::/var/log/custom",
1208 Transport: ConfigLogStreamShellTransport{
1209 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1210 Host: ConfigHost{
1211 Addr: "host-foo-from-nerdlog-config-01.com:2001",
1212 User: "user-foo-from-nerdlog-config-01",
1213 },
1214 },
1215 },
1216 LogFiles: []string{"/var/log/custom", "auto"},
1217 },
1218 "foo-02::/var/log/custom": {
1219 Name: "foo-02::/var/log/custom",
1220 Transport: ConfigLogStreamShellTransport{
1221 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1222 Host: ConfigHost{
1223 Addr: "host-foo-from-nerdlog-config-02.com:2002",
1224 User: "user-foo-from-nerdlog-config-02",
1225 },
1226 },
1227 },
1228 LogFiles: []string{"/var/log/custom", "auto"},
1229 },
1230 },
1231 wantStreamsSSHBin: map[string]LogStream{
1232 "foo-01": {
1233 Name: "foo-01",
1234 Transport: ConfigLogStreamShellTransport{
1235 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1236 Host: "host-foo-from-nerdlog-config-01.com",
1237 Port: "2001",
1238 User: "user-foo-from-nerdlog-config-01",
1239 },
1240 },
1241 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
1242 },
1243 "foo-02": {
1244 Name: "foo-02",
1245 Transport: ConfigLogStreamShellTransport{
1246 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1247 Host: "host-foo-from-nerdlog-config-02.com",
1248 Port: "2002",
1249 User: "user-foo-from-nerdlog-config-02",
1250 },
1251 },
1252 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
1253 },
1254
1255 "foo-01::/var/log/custom": {
1256 Name: "foo-01::/var/log/custom",
1257 Transport: ConfigLogStreamShellTransport{
1258 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1259 Host: "host-foo-from-nerdlog-config-01.com",
1260 Port: "2001",
1261 User: "user-foo-from-nerdlog-config-01",
1262 },
1263 },
1264 LogFiles: []string{"/var/log/custom", "auto"},
1265 },
1266 "foo-02::/var/log/custom": {
1267 Name: "foo-02::/var/log/custom",
1268 Transport: ConfigLogStreamShellTransport{
1269 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1270 Host: "host-foo-from-nerdlog-config-02.com",
1271 Port: "2002",
1272 User: "user-foo-from-nerdlog-config-02",
1273 },
1274 },
1275 LogFiles: []string{"/var/log/custom", "auto"},
1276 },
1277 },
1278 },
1279
1280 {
1281 name: "real host, hostname is not overridden",
1282 osUser: "osuser",
1283
1284 configLogStreams: testConfigLogStreams1,
1285 input: "realhost.com",
1286
1287 wantStreams: map[string]LogStream{
1288 "realhost.com": {
1289 Name: "realhost.com",
1290 Transport: ConfigLogStreamShellTransport{
1291 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1292 Host: ConfigHost{
1293 Addr: "realhost.com:22",
1294 User: "user-from-nerdlog-config",
1295 },
1296 },
1297 },
1298 LogFiles: []string{"auto", "auto"},
1299 },
1300 },
1301 wantStreamsSSHBin: map[string]LogStream{
1302 "realhost.com": {
1303 Name: "realhost.com",
1304 Transport: ConfigLogStreamShellTransport{
1305 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1306 Host: "realhost.com",
1307 User: "user-from-nerdlog-config",
1308 },
1309 },
1310 LogFiles: []string{"auto", "auto"},
1311 },
1312 },
1313 },
1314
1315 {
1316 name: "single glob, logfiles from nerdlog config",
1317 osUser: "osuser",
1318
1319 configLogStreams: testConfigLogStreams1,
1320
1321 input: "baz-*",
1322
1323 wantStreams: map[string]LogStream{
1324 "baz-01": {
1325 Name: "baz-01",
1326 Transport: ConfigLogStreamShellTransport{
1327 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1328 Host: ConfigHost{
1329 Addr: "baz-01:22",
1330 User: "osuser",
1331 },
1332 },
1333 },
1334 LogFiles: []string{"/from/nerdlog/config/bazlog", "auto"},
1335 },
1336 "baz-02": {
1337 Name: "baz-02",
1338 Transport: ConfigLogStreamShellTransport{
1339 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1340 Host: ConfigHost{
1341 Addr: "baz-02:22",
1342 User: "osuser",
1343 },
1344 },
1345 },
1346 LogFiles: []string{"/from/nerdlog/config/bazlog", "auto"},
1347 },
1348 },
1349 wantStreamsSSHBin: map[string]LogStream{
1350 "baz-01": {
1351 Name: "baz-01",
1352 Transport: ConfigLogStreamShellTransport{
1353 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1354 Host: "baz-01",
1355 },
1356 },
1357 LogFiles: []string{"/from/nerdlog/config/bazlog", "auto"},
1358 },
1359 "baz-02": {
1360 Name: "baz-02",
1361 Transport: ConfigLogStreamShellTransport{
1362 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1363 Host: "baz-02",
1364 },
1365 },
1366 LogFiles: []string{"/from/nerdlog/config/bazlog", "auto"},
1367 },
1368 },
1369 },
1370
1371 {
1372 name: "glob doesn't match anything",
1373 osUser: "osuser",
1374
1375 configLogStreams: testConfigLogStreams1,
1376 input: "mismatching-*",
1377
1378 wantErr: "parsing entry #1 (mismatching-*): glob \"mismatching-*\" didn't match anything (having address \"mismatching-*:22\")",
1379 wantErrSSHBin: "parsing entry #1 (mismatching-*): glob \"mismatching-*\" didn't match anything (having address \"mismatching-*:\")",
1380 },
1381 }
1382
1383 for _, tt := range tests {
1384 t.Run(tt.name, func(t *testing.T) {
1385 runResolverTestCase(t, tt)
1386 })
1387 }
1388 }
1389
1390 func TestLStreamsResolverGlobOnlySSHConfig(t *testing.T) {
1391 tests := []resolverTestCase{
1392 {
1393 name: "single glob, everything is taken from ssh config",
1394 osUser: "osuser",
1395
1396 sshConfig: testSSHConfig1,
1397 input: "sshfoo-*",
1398
1399 wantStreams: map[string]LogStream{
1400 "sshfoo-01": {
1401 Name: "sshfoo-01",
1402 Transport: ConfigLogStreamShellTransport{
1403 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1404 Host: ConfigHost{
1405 Addr: "host-foo-from-ssh-config-01.com:3001",
1406 User: "user-foo-from-ssh-config-01",
1407 },
1408 },
1409 },
1410 LogFiles: []string{"auto", "auto"},
1411 },
1412 "sshfoo-02": {
1413 Name: "sshfoo-02",
1414 Transport: ConfigLogStreamShellTransport{
1415 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1416 Host: ConfigHost{
1417 Addr: "host-foo-from-ssh-config-02.com:3002",
1418 User: "user-foo-from-ssh-config-02",
1419 },
1420 },
1421 },
1422 LogFiles: []string{"auto", "auto"},
1423 },
1424 },
1425 wantStreamsSSHBin: map[string]LogStream{
1426 "sshfoo-01": {
1427 Name: "sshfoo-01",
1428 Transport: ConfigLogStreamShellTransport{
1429 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1430 Host: "sshfoo-01",
1431 },
1432 },
1433 LogFiles: []string{"auto", "auto"},
1434 },
1435 "sshfoo-02": {
1436 Name: "sshfoo-02",
1437 Transport: ConfigLogStreamShellTransport{
1438 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1439 Host: "sshfoo-02",
1440 },
1441 },
1442 LogFiles: []string{"auto", "auto"},
1443 },
1444 },
1445 },
1446
1447 {
1448 name: "two globs, everything is taken from ssh config",
1449 osUser: "osuser",
1450
1451 sshConfig: testSSHConfig1,
1452 input: "sshfoo-*, sshbar-*",
1453
1454 wantStreams: map[string]LogStream{
1455 "sshfoo-01": {
1456 Name: "sshfoo-01",
1457 Transport: ConfigLogStreamShellTransport{
1458 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1459 Host: ConfigHost{
1460 Addr: "host-foo-from-ssh-config-01.com:3001",
1461 User: "user-foo-from-ssh-config-01",
1462 },
1463 },
1464 },
1465 LogFiles: []string{"auto", "auto"},
1466 },
1467 "sshfoo-02": {
1468 Name: "sshfoo-02",
1469 Transport: ConfigLogStreamShellTransport{
1470 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1471 Host: ConfigHost{
1472 Addr: "host-foo-from-ssh-config-02.com:3002",
1473 User: "user-foo-from-ssh-config-02",
1474 },
1475 },
1476 },
1477 LogFiles: []string{"auto", "auto"},
1478 },
1479 "sshbar-01": {
1480 Name: "sshbar-01",
1481 Transport: ConfigLogStreamShellTransport{
1482 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1483 Host: ConfigHost{
1484 Addr: "host-bar-from-ssh-config-01.com:3001",
1485 User: "user-bar-from-ssh-config-01",
1486 },
1487 },
1488 },
1489 LogFiles: []string{"auto", "auto"},
1490 },
1491 "sshbar-02": {
1492 Name: "sshbar-02",
1493 Transport: ConfigLogStreamShellTransport{
1494 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1495 Host: ConfigHost{
1496 Addr: "host-bar-from-ssh-config-02.com:3002",
1497 User: "user-bar-from-ssh-config-02",
1498 },
1499 },
1500 },
1501 LogFiles: []string{"auto", "auto"},
1502 },
1503 },
1504 wantStreamsSSHBin: map[string]LogStream{
1505 "sshfoo-01": {
1506 Name: "sshfoo-01",
1507 Transport: ConfigLogStreamShellTransport{
1508 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1509 Host: "sshfoo-01",
1510 },
1511 },
1512 LogFiles: []string{"auto", "auto"},
1513 },
1514 "sshfoo-02": {
1515 Name: "sshfoo-02",
1516 Transport: ConfigLogStreamShellTransport{
1517 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1518 Host: "sshfoo-02",
1519 },
1520 },
1521 LogFiles: []string{"auto", "auto"},
1522 },
1523
1524 "sshbar-01": {
1525 Name: "sshbar-01",
1526 Transport: ConfigLogStreamShellTransport{
1527 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1528 Host: "sshbar-01",
1529 },
1530 },
1531 LogFiles: []string{"auto", "auto"},
1532 },
1533 "sshbar-02": {
1534 Name: "sshbar-02",
1535 Transport: ConfigLogStreamShellTransport{
1536 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1537 Host: "sshbar-02",
1538 },
1539 },
1540 LogFiles: []string{"auto", "auto"},
1541 },
1542 },
1543 },
1544
1545 {
1546 name: "single glob, log file is from the input, everything else is from ssh config",
1547 osUser: "osuser",
1548
1549 sshConfig: testSSHConfig1,
1550 input: "sshfoo-*::/var/log/auth.log",
1551
1552 wantStreams: map[string]LogStream{
1553 "sshfoo-01::/var/log/auth.log": {
1554 Name: "sshfoo-01::/var/log/auth.log",
1555 Transport: ConfigLogStreamShellTransport{
1556 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1557 Host: ConfigHost{
1558 Addr: "host-foo-from-ssh-config-01.com:3001",
1559 User: "user-foo-from-ssh-config-01",
1560 },
1561 },
1562 },
1563 LogFiles: []string{"/var/log/auth.log", "auto"},
1564 },
1565 "sshfoo-02::/var/log/auth.log": {
1566 Name: "sshfoo-02::/var/log/auth.log",
1567 Transport: ConfigLogStreamShellTransport{
1568 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1569 Host: ConfigHost{
1570 Addr: "host-foo-from-ssh-config-02.com:3002",
1571 User: "user-foo-from-ssh-config-02",
1572 },
1573 },
1574 },
1575 LogFiles: []string{"/var/log/auth.log", "auto"},
1576 },
1577 },
1578 wantStreamsSSHBin: map[string]LogStream{
1579 "sshfoo-01::/var/log/auth.log": {
1580 Name: "sshfoo-01::/var/log/auth.log",
1581 Transport: ConfigLogStreamShellTransport{
1582 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1583 Host: "sshfoo-01",
1584 },
1585 },
1586 LogFiles: []string{"/var/log/auth.log", "auto"},
1587 },
1588 "sshfoo-02::/var/log/auth.log": {
1589 Name: "sshfoo-02::/var/log/auth.log",
1590 Transport: ConfigLogStreamShellTransport{
1591 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1592 Host: "sshfoo-02",
1593 },
1594 },
1595 LogFiles: []string{"/var/log/auth.log", "auto"},
1596 },
1597 },
1598 },
1599
1600 {
1601 name: "single glob, exact match",
1602 osUser: "osuser",
1603
1604 sshConfig: testSSHConfig1,
1605 input: "sshfoo-02",
1606
1607 wantStreams: map[string]LogStream{
1608 "sshfoo-02": {
1609 Name: "sshfoo-02",
1610 Transport: ConfigLogStreamShellTransport{
1611 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1612 Host: ConfigHost{
1613 Addr: "host-foo-from-ssh-config-02.com:3002",
1614 User: "user-foo-from-ssh-config-02",
1615 },
1616 },
1617 },
1618 LogFiles: []string{"auto", "auto"},
1619 },
1620 },
1621 wantStreamsSSHBin: map[string]LogStream{
1622 "sshfoo-02": {
1623 Name: "sshfoo-02",
1624 Transport: ConfigLogStreamShellTransport{
1625 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1626 Host: "sshfoo-02",
1627 },
1628 },
1629 LogFiles: []string{"auto", "auto"},
1630 },
1631 },
1632 },
1633
1634 {
1635 name: "single glob, exact match, host is the same",
1636 osUser: "osuser",
1637
1638 sshConfig: testSSHConfig1,
1639 input: "sshrealhost.com",
1640
1641 wantStreams: map[string]LogStream{
1642 "sshrealhost.com": {
1643 Name: "sshrealhost.com",
1644 Transport: ConfigLogStreamShellTransport{
1645 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1646 Host: ConfigHost{
1647 Addr: "sshrealhost.com:4001",
1648 User: "user-from-ssh-config",
1649 },
1650 },
1651 },
1652 LogFiles: []string{"auto", "auto"},
1653 },
1654 },
1655 wantStreamsSSHBin: map[string]LogStream{
1656 "sshrealhost.com": {
1657 Name: "sshrealhost.com",
1658 Transport: ConfigLogStreamShellTransport{
1659 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1660 Host: "sshrealhost.com",
1661 },
1662 },
1663 LogFiles: []string{"auto", "auto"},
1664 },
1665 },
1666 },
1667
1668 {
1669 name: "single glob, no port in ssh config",
1670 osUser: "osuser",
1671
1672 sshConfig: testSSHConfig1,
1673 input: "sshnoport-*",
1674
1675 wantStreams: map[string]LogStream{
1676 "sshnoport-01": {
1677 Name: "sshnoport-01",
1678 Transport: ConfigLogStreamShellTransport{
1679 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1680 Host: ConfigHost{
1681 Addr: "host-noport-from-ssh-config-01.com:22",
1682 User: "user-noport-from-ssh-config-01",
1683 },
1684 },
1685 },
1686 LogFiles: []string{"auto", "auto"},
1687 },
1688 },
1689 wantStreamsSSHBin: map[string]LogStream{
1690 "sshnoport-01": {
1691 Name: "sshnoport-01",
1692 Transport: ConfigLogStreamShellTransport{
1693 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1694 Host: "sshnoport-01",
1695 },
1696 },
1697 LogFiles: []string{"auto", "auto"},
1698 },
1699 },
1700 },
1701 }
1702
1703 for _, tt := range tests {
1704 t.Run(tt.name, func(t *testing.T) {
1705 runResolverTestCase(t, tt)
1706 })
1707 }
1708 }
1709
1710 func TestLStreamsResolverGlobBothNerdlogAndSSHConfigs(t *testing.T) {
1711 tests := []resolverTestCase{
1712 {
1713 name: "single glob, everything is taken from nerdlog config, even though it exists in ssh too",
1714 osUser: "osuser",
1715
1716 configLogStreams: testConfigLogStreams1,
1717 sshConfig: testSSHConfig1,
1718
1719 input: "foo-*",
1720
1721 wantStreams: map[string]LogStream{
1722 "foo-01": {
1723 Name: "foo-01",
1724 Transport: ConfigLogStreamShellTransport{
1725 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1726 Host: ConfigHost{
1727 Addr: "host-foo-from-nerdlog-config-01.com:2001",
1728 User: "user-foo-from-nerdlog-config-01",
1729 },
1730 },
1731 },
1732 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
1733 },
1734 "foo-02": {
1735 Name: "foo-02",
1736 Transport: ConfigLogStreamShellTransport{
1737 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1738 Host: ConfigHost{
1739 Addr: "host-foo-from-nerdlog-config-02.com:2002",
1740 User: "user-foo-from-nerdlog-config-02",
1741 },
1742 },
1743 },
1744 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
1745 },
1746 },
1747 wantStreamsSSHBin: map[string]LogStream{
1748 "foo-01": {
1749 Name: "foo-01",
1750 Transport: ConfigLogStreamShellTransport{
1751 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1752 Host: "host-foo-from-nerdlog-config-01.com",
1753 Port: "2001",
1754 User: "user-foo-from-nerdlog-config-01",
1755 },
1756 },
1757 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
1758 },
1759 "foo-02": {
1760 Name: "foo-02",
1761 Transport: ConfigLogStreamShellTransport{
1762 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1763 Host: "host-foo-from-nerdlog-config-02.com",
1764 Port: "2002",
1765 User: "user-foo-from-nerdlog-config-02",
1766 },
1767 },
1768 LogFiles: []string{"/from/nerdlog/config/foolog", "auto"},
1769 },
1770 },
1771 },
1772
1773 {
1774 name: "single glob, taken most taken from nerdlog config, port from ssh config",
1775 osUser: "osuser",
1776
1777 configLogStreams: testConfigLogStreams1,
1778 sshConfig: testSSHConfig1,
1779
1780 input: "bar-*",
1781
1782 wantStreams: map[string]LogStream{
1783 "bar-01": {
1784 Name: "bar-01",
1785 Transport: ConfigLogStreamShellTransport{
1786 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1787 Host: ConfigHost{
1788 Addr: "host-bar-from-nerdlog-config-01.com:6001",
1789 User: "user-bar-from-nerdlog-config-01",
1790 },
1791 },
1792 },
1793 LogFiles: []string{"auto", "auto"},
1794 },
1795 "bar-02": {
1796 Name: "bar-02",
1797 Transport: ConfigLogStreamShellTransport{
1798 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1799 Host: ConfigHost{
1800 Addr: "host-bar-from-nerdlog-config-02.com:6002",
1801 User: "user-bar-from-nerdlog-config-02",
1802 },
1803 },
1804 },
1805 LogFiles: []string{"auto", "auto"},
1806 },
1807 },
1808 wantStreamsSSHBin: map[string]LogStream{
1809 "bar-01": {
1810 Name: "bar-01",
1811 Transport: ConfigLogStreamShellTransport{
1812 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1813 Host: "host-bar-from-nerdlog-config-01.com",
1814 User: "user-bar-from-nerdlog-config-01",
1815 },
1816 },
1817 LogFiles: []string{"auto", "auto"},
1818 },
1819 "bar-02": {
1820 Name: "bar-02",
1821 Transport: ConfigLogStreamShellTransport{
1822 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1823 Host: "host-bar-from-nerdlog-config-02.com",
1824 User: "user-bar-from-nerdlog-config-02",
1825 },
1826 },
1827 LogFiles: []string{"auto", "auto"},
1828 },
1829 },
1830 },
1831
1832 {
1833 name: "single glob, logfiles from nerdlog config, everything else from ssh config",
1834 osUser: "osuser",
1835
1836 configLogStreams: testConfigLogStreams1,
1837 sshConfig: testSSHConfig1,
1838
1839 input: "baz-*",
1840
1841 wantStreams: map[string]LogStream{
1842 "baz-01": {
1843 Name: "baz-01",
1844 Transport: ConfigLogStreamShellTransport{
1845 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1846 Host: ConfigHost{
1847 Addr: "host-baz-from-ssh-config-01.com:7001",
1848 User: "user-baz-from-ssh-config-01",
1849 },
1850 },
1851 },
1852 LogFiles: []string{"/from/nerdlog/config/bazlog", "auto"},
1853 },
1854 "baz-02": {
1855 Name: "baz-02",
1856 Transport: ConfigLogStreamShellTransport{
1857 SSHLib: &ConfigLogStreamShellTransportSSHLib{
1858 Host: ConfigHost{
1859 Addr: "host-baz-from-ssh-config-02.com:7002",
1860 User: "user-baz-from-ssh-config-02",
1861 },
1862 },
1863 },
1864 LogFiles: []string{"/from/nerdlog/config/bazlog", "auto"},
1865 },
1866 },
1867 wantStreamsSSHBin: map[string]LogStream{
1868 "baz-01": {
1869 Name: "baz-01",
1870 Transport: ConfigLogStreamShellTransport{
1871 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1872 Host: "baz-01",
1873 },
1874 },
1875 LogFiles: []string{"/from/nerdlog/config/bazlog", "auto"},
1876 },
1877 "baz-02": {
1878 Name: "baz-02",
1879 Transport: ConfigLogStreamShellTransport{
1880 SSHBin: &ConfigLogStreamShellTransportSSHBin{
1881 Host: "baz-02",
1882 },
1883 },
1884 LogFiles: []string{"/from/nerdlog/config/bazlog", "auto"},
1885 },
1886 },
1887 },
1888 }
1889
1890 for _, tt := range tests {
1891 t.Run(tt.name, func(t *testing.T) {
1892 runResolverTestCase(t, tt)
1893 })
1894 }
1895 }
1896
1897 func TestLStreamsResolverLocalhost(t *testing.T) {
1898 tests := []resolverTestCase{
1899 {
1900 name: "single localhost entry",
1901 osUser: "osuser",
1902 input: "localhost",
1903 wantStreams: map[string]LogStream{
1904 "localhost": {
1905 Name: "localhost",
1906 Transport: ConfigLogStreamShellTransport{
1907 Localhost: &ConfigLogStreamShellTransportLocalhost{},
1908 },
1909 LogFiles: []string{"auto", "auto"},
1910 },
1911 },
1912 },
1913 {
1914 name: "localhost with user, which is ignored",
1915 osUser: "osuser",
1916 input: "myuser@localhost",
1917 wantStreams: map[string]LogStream{
1918 "myuser@localhost": {
1919 Name: "myuser@localhost",
1920 Transport: ConfigLogStreamShellTransport{
1921 Localhost: &ConfigLogStreamShellTransportLocalhost{},
1922 },
1923 LogFiles: []string{"auto", "auto"},
1924 },
1925 },
1926 },
1927 {
1928 name: "hostname with user and port, which are ignored",
1929 osUser: "osuser",
1930 input: "myuser@localhost:777",
1931 wantStreams: map[string]LogStream{
1932 "myuser@localhost:777": {
1933 Name: "myuser@localhost:777",
1934 Transport: ConfigLogStreamShellTransport{
1935 Localhost: &ConfigLogStreamShellTransportLocalhost{},
1936 },
1937 LogFiles: []string{"auto", "auto"},
1938 },
1939 },
1940 },
1941 {
1942 name: "hostname with port, which is ignored",
1943 osUser: "osuser",
1944 input: "localhost:777",
1945 wantStreams: map[string]LogStream{
1946 "localhost:777": {
1947 Name: "localhost:777",
1948 Transport: ConfigLogStreamShellTransport{
1949 Localhost: &ConfigLogStreamShellTransportLocalhost{},
1950 },
1951 LogFiles: []string{"auto", "auto"},
1952 },
1953 },
1954 },
1955 {
1956 name: "hostname with user, port, and log file; user and port are ignored",
1957 osUser: "osuser",
1958 input: "myuser@localhost:22:/var/log/syslog",
1959 wantStreams: map[string]LogStream{
1960 "myuser@localhost:22:/var/log/syslog": {
1961 Name: "myuser@localhost:22:/var/log/syslog",
1962 Transport: ConfigLogStreamShellTransport{
1963 Localhost: &ConfigLogStreamShellTransportLocalhost{},
1964 },
1965 LogFiles: []string{"/var/log/syslog", "auto"},
1966 },
1967 },
1968 },
1969 {
1970 name: "hostname with user, port, and different log file; user and port are ignored",
1971 osUser: "osuser",
1972 input: "myuser@localhost:22:/var/log/auth.log",
1973 wantStreams: map[string]LogStream{
1974 "myuser@localhost:22:/var/log/auth.log": {
1975 Name: "myuser@localhost:22:/var/log/auth.log",
1976 Transport: ConfigLogStreamShellTransport{
1977 Localhost: &ConfigLogStreamShellTransportLocalhost{},
1978 },
1979 LogFiles: []string{"/var/log/auth.log", "auto"},
1980 },
1981 },
1982 },
1983 {
1984 name: "hostname with user, port, and two log files; user and port are ignored",
1985 osUser: "osuser",
1986 input: "myuser@localhost:22:/var/log/mylog_last:/var/log/mylog_prev",
1987 wantStreams: map[string]LogStream{
1988 "myuser@localhost:22:/var/log/mylog_last:/var/log/mylog_prev": {
1989 Name: "myuser@localhost:22:/var/log/mylog_last:/var/log/mylog_prev",
1990 Transport: ConfigLogStreamShellTransport{
1991 Localhost: &ConfigLogStreamShellTransportLocalhost{},
1992 },
1993 LogFiles: []string{"/var/log/mylog_last", "/var/log/mylog_prev"},
1994 },
1995 },
1996 },
1997 {
1998 name: "127.0.0.1 still goes via ssh",
1999 osUser: "osuser",
2000 input: "127.0.0.1",
2001 wantStreams: map[string]LogStream{
2002 "127.0.0.1": {
2003 Name: "127.0.0.1",
2004 Transport: ConfigLogStreamShellTransport{
2005 SSHLib: &ConfigLogStreamShellTransportSSHLib{
2006 Host: ConfigHost{
2007 Addr: "127.0.0.1:22",
2008 User: "osuser",
2009 },
2010 },
2011 },
2012 LogFiles: []string{"auto", "auto"},
2013 },
2014 },
2015 wantStreamsSSHBin: map[string]LogStream{
2016 "127.0.0.1": {
2017 Name: "127.0.0.1",
2018 Transport: ConfigLogStreamShellTransport{
2019 SSHBin: &ConfigLogStreamShellTransportSSHBin{
2020 Host: "127.0.0.1",
2021 },
2022 },
2023 LogFiles: []string{"auto", "auto"},
2024 },
2025 },
2026 },
2027 }
2028
2029 for _, tt := range tests {
2030 t.Run(tt.name, func(t *testing.T) {
2031 runResolverTestCase(t, tt)
2032 })
2033 }
2034 }
2035
2036 func TestLStreamsResolverShellInit(t *testing.T) {
2037 tests := []resolverTestCase{
2038 {
2039 name: "simple ",
2040 osUser: "osuser",
2041
2042 configLogStreams: testConfigLogStreams1,
2043 sshConfig: testSSHConfig1,
2044
2045 input: "my-with-shell-init",
2046
2047 wantStreams: map[string]LogStream{
2048 "my-with-shell-init": {
2049 Name: "my-with-shell-init",
2050 Transport: ConfigLogStreamShellTransport{
2051 SSHLib: &ConfigLogStreamShellTransportSSHLib{
2052 Host: ConfigHost{
2053 Addr: "host-with-shell-init.com:22",
2054 User: "osuser",
2055 },
2056 },
2057 },
2058 LogFiles: []string{"auto", "auto"},
2059 Options: LogStreamOptions{
2060 ShellInit: []string{
2061 "export TZ=UTC",
2062 },
2063 },
2064 },
2065 },
2066 wantStreamsSSHBin: map[string]LogStream{
2067 "my-with-shell-init": {
2068 Name: "my-with-shell-init",
2069 Transport: ConfigLogStreamShellTransport{
2070 SSHBin: &ConfigLogStreamShellTransportSSHBin{
2071 Host: "host-with-shell-init.com",
2072 },
2073 },
2074 LogFiles: []string{"auto", "auto"},
2075 Options: LogStreamOptions{
2076 ShellInit: []string{
2077 "export TZ=UTC",
2078 },
2079 },
2080 },
2081 },
2082 },
2083 }
2084
2085 for _, tt := range tests {
2086 t.Run(tt.name, func(t *testing.T) {
2087 runResolverTestCase(t, tt)
2088 })
2089 }
2090 }