MCPcopy Create free account
hub / github.com/dim-an/cod / TestListCommands

Function TestListCommands

datastore/sqlitedb_test.go:140–204  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

138}
139
140func TestListCommands(t *testing.T) {
141 db := newTestSqliteStorage(t)
142
143 makeHelpPage := func(c *Command) *HelpPage {
144 s := sha1.New()
145 _, err := s.Write([]byte(c.Dir))
146 util.VerifyPanic(err)
147 for _, arg := range c.Args {
148 _, err := s.Write([]byte(arg))
149 util.VerifyPanic(err)
150 }
151 for _, arg := range c.Env {
152 _, err = s.Write([]byte(arg))
153 util.VerifyPanic(err)
154 }
155
156 return &HelpPage{
157 ExecutablePath: c.Args[0],
158 Completions: nil,
159 CheckSum: fmt.Sprintf("%x", s.Sum(nil)),
160 Command: *c,
161 }
162 }
163
164 command1 := Command{
165 Args: []string{"/foo", "--help"},
166 Dir: "/tmp",
167 }
168
169 command2 := Command{
170 Args: []string{"/bar", "--help"},
171 Dir: "/tmp",
172 }
173
174 command3 := Command{
175 Args: []string{"/foo", "mode", "--help"},
176 Dir: "/tmp",
177 }
178
179 status, err := db.AddHelpPage(makeHelpPage(&command1), PolicyUnknown)
180 require.Nil(t, err)
181 require.Equal(t, status, AddHelpPageStatusNew)
182
183 status, err = db.AddHelpPage(makeHelpPage(&command2), PolicyUnknown)
184 require.Nil(t, err)
185 require.Equal(t, status, AddHelpPageStatusNew)
186
187 status, err = db.AddHelpPage(makeHelpPage(&command3), PolicyUnknown)
188 require.Nil(t, err)
189 require.Equal(t, status, AddHelpPageStatusNew)
190
191 commandMap, err := db.ListCommands()
192 require.Nil(t, err)
193
194 toValues := func(m *map[int64]*Command) []*Command {
195 var res []*Command
196 for _, v := range *m {
197 res = append(res, v)

Callers

nothing calls this directly

Calls 5

VerifyPanicFunction · 0.92
newTestSqliteStorageFunction · 0.85
SortableCommandsTypeAlias · 0.85
AddHelpPageMethod · 0.65
ListCommandsMethod · 0.65

Tested by

no test coverage detected