MCPcopy Create free account
hub / github.com/idank/explainshell / TestShouldShed

Function TestShouldShed

prod/botshed/module_test.go:52–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

50}
51
52func 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
99func TestUnmarshalCaddyfile(t *testing.T) {
100 t.Run("valid block", func(t *testing.T) {

Callers

nothing calls this directly

Calls 2

basenameSetFunction · 0.85
shouldShedFunction · 0.85

Tested by

no test coverage detected