package functional

import (
	"fmt"

	. "github.com/clearcontainers/tests"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/ginkgo/extensions/table"
	. "github.com/onsi/gomega"
)

func withoutID(command string) TableEntry {
	cmd := NewCommand(Runtime, command)
	return Entry(fmt.Sprintf("command '%s'", command), cmd)
}

func withInexistentID(command string) TableEntry {
	cmd := NewCommand(Runtime, command, RandID(30))
	return Entry(fmt.Sprintf("command '%s'", command), cmd)
}

var _ = Describe("commands", func() {
	var exitCode int

	DescribeTable("without a container ID should fail",
		func(cmd *Command) {
			exitCode = cmd.Run()

			Ω(exitCode).ShouldNot(Equal(0))
			Ω(cmd.Stderr.String()).ShouldNot(BeEmpty())
		},
		withoutID("kill"),
		withoutID("delete"),
		withoutID("start"),
		withoutID("state"),
	)

	DescribeTable("with a inexistent container ID should fail",
		func(cmd *Command) {
			exitCode = cmd.Run()

			Ω(exitCode).ShouldNot(Equal(0))
			Ω(cmd.Stderr.String()).ShouldNot(BeEmpty())
		},
		withInexistentID("kill"),
		withInexistentID("delete"),
		withInexistentID("start"),
		withInexistentID("state"),
	)
})
