(t *testing.T)
| 50 | } |
| 51 | |
| 52 | func TestShouldShed(t *testing.T) { |
| 53 | bn := basenameSet("cd.1posix", "plan9-rc.1", "rc.1plan9", "ls.1") |
| 54 | |
| 55 | pad := func(cmd string, n int) string { |
| 56 | if len(cmd) >= n { |
| 57 | return cmd |
| 58 | } |
| 59 | out := cmd + strings.Repeat(" x", (n-len(cmd))/2) |
| 60 | if len(out) < n { |
| 61 | out += "y" |
| 62 | } |
| 63 | return out |
| 64 | } |
| 65 | |
| 66 | cases := []struct { |
| 67 | name string |
| 68 | cmd string |
| 69 | wantShed bool |
| 70 | }{ |
| 71 | {"four hits short cmd", |
| 72 | "plan9-rc.1 rc.1plan9 cd.1posix ls.1", true}, |
| 73 | {"three hits short cmd not enough", |
| 74 | "plan9-rc.1 rc.1plan9 cd.1posix", false}, |
| 75 | {"two hits just over 250", |
| 76 | pad("ls.1 plan9-rc.1 ", 251), true}, |
| 77 | {"two hits at 250 boundary", |
| 78 | pad("ls.1 plan9-rc.1 ", 250), false}, |
| 79 | {"one hit long cmd", |
| 80 | pad("ls.1 ", 4000), false}, |
| 81 | {"zero hits long cmd", |
| 82 | pad("tar xzvf archive ", 5000), false}, |
| 83 | {"over 5000 cap not shed", |
| 84 | pad("plan9-rc.1 rc.1plan9 cd.1posix ls.1 ", 5001), false}, |
| 85 | {"empty not shed", |
| 86 | "", false}, |
| 87 | } |
| 88 | for _, tc := range cases { |
| 89 | t.Run(tc.name, func(t *testing.T) { |
| 90 | shed, _ := shouldShed(tc.cmd, bn) |
| 91 | if shed != tc.wantShed { |
| 92 | t.Fatalf("shouldShed(len=%d) = %v, want %v", |
| 93 | len(tc.cmd), shed, tc.wantShed) |
| 94 | } |
| 95 | }) |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | func TestUnmarshalCaddyfile(t *testing.T) { |
| 100 | t.Run("valid block", func(t *testing.T) { |
nothing calls this directly
no test coverage detected