| 1 | package ssh |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestParseScriptInterpreter(t *testing.T) { |
| 6 | type testCase struct { |
| 7 | script string |
| 8 | expected string |
| 9 | } |
| 10 | testCases := []testCase{ |
| 11 | { |
| 12 | script: `#!/bin/sh |
| 13 | echo "Hello world" |
| 14 | `, |
| 15 | expected: "/bin/sh", |
| 16 | }, |
| 17 | { |
| 18 | script: `echo "Hello world" |
| 19 | `, |
| 20 | expected: "", |
| 21 | }, |
| 22 | } |
| 23 | for i, tc := range testCases { |
| 24 | got, err := ParseScriptInterpreter(tc.script) |
| 25 | if tc.expected != "" { |
| 26 | if err != nil { |
| 27 | t.Errorf("#%d: %v", i, err) |
| 28 | } |
| 29 | if got != tc.expected { |
| 30 | t.Errorf("#%d: expected %q, got %q", i, tc.expected, got) |
| 31 | } |
| 32 | } else { |
| 33 | if err == nil { |
| 34 | t.Errorf("#%d: expected error", i) |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | } |