Files
docker-cli/components/engine/graph/pools_test.go
T
Aaron Lehmann 4366d3278e Change poolAdd to return a boolean instead of an error
Previously, its other return value was used even when it returned an
error. This is awkward and goes against the convention. It also could
have resulted in a nil pointer dereference when an error was returned
because of an unknown pool type. This changes the unknown pool type
error to a panic (since the pool types are hardcoded at call sites and
must always be "push" or "pull"), and returns a "found" boolean instead
of an error.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
Upstream-commit: 80513d85cfc0e46f8202fc3030f11052bbfeea7a
Component: engine
2015-08-27 11:18:42 -07:00

45 lines
1.0 KiB
Go

package graph
import (
"testing"
"github.com/docker/docker/pkg/progressreader"
"github.com/docker/docker/pkg/reexec"
)
func init() {
reexec.Init()
}
func TestPools(t *testing.T) {
s := &TagStore{
pullingPool: make(map[string]*progressreader.ProgressStatus),
pushingPool: make(map[string]*progressreader.ProgressStatus),
}
if _, found := s.poolAdd("pull", "test1"); found {
t.Fatal("Expected pull test1 not to be in progress")
}
if _, found := s.poolAdd("pull", "test2"); found {
t.Fatal("Expected pull test2 not to be in progress")
}
if _, found := s.poolAdd("push", "test1"); !found {
t.Fatalf("Expected pull test1 to be in progress`")
}
if _, found := s.poolAdd("pull", "test1"); !found {
t.Fatalf("Expected pull test1 to be in progress`")
}
if err := s.poolRemove("pull", "test2"); err != nil {
t.Fatal(err)
}
if err := s.poolRemove("pull", "test2"); err != nil {
t.Fatal(err)
}
if err := s.poolRemove("pull", "test1"); err != nil {
t.Fatal(err)
}
if err := s.poolRemove("push", "test1"); err != nil {
t.Fatal(err)
}
}