diff --git a/snok.go b/snok.go index dcba08812bd917dd21dd60ff37a8bac1c3ae6cdf..09c419ea66aebc3a3c42a53aea36541b971f43af 100644 --- a/snok.go +++ b/snok.go @@ -73,14 +73,16 @@ func (ct *CommandTest) testCmd(t *testing.T, cmd *cobra.Command, args []string) containers, exists := cmd.Annotations["containers"] if exists { for _, container := range strings.Split(containers, ",") { - c := ct.containers[strings.TrimFunc(container, unicode.IsSpace)] - if !c.running { - t.Run("[Start "+container+"]", func(_ *testing.T) { - err := c.startFn(ct, t) - require.NoError(t, err, "Failed to start container: %s", container) - }) + key := strings.TrimFunc(container, unicode.IsSpace) + if c, ok := ct.containers[key]; ok { + if !c.running { + t.Run("[Start "+key+"]", func(_ *testing.T) { + err := c.startFn(ct, t) + require.NoError(t, err, "Failed to start container: %s", key) + }) + c.running = true + } } - c.running = true } } annotation, exists := cmd.Annotations["tests"]