mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add test case for docker ps -f health=starting
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
97b16aecf9
commit
f509a54bdd
2 changed files with 24 additions and 9 deletions
|
@ -102,15 +102,6 @@ func (s *State) String() string {
|
||||||
return fmt.Sprintf("Exited (%d) %s ago", s.ExitCodeValue, units.HumanDuration(time.Now().UTC().Sub(s.FinishedAt)))
|
return fmt.Sprintf("Exited (%d) %s ago", s.ExitCodeValue, units.HumanDuration(time.Now().UTC().Sub(s.FinishedAt)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// HealthString returns a single string to describe health status.
|
|
||||||
func (s *State) HealthString() string {
|
|
||||||
if s.Health == nil {
|
|
||||||
return types.NoHealthcheck
|
|
||||||
}
|
|
||||||
|
|
||||||
return s.Health.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsValidHealthString checks if the provided string is a valid container health status or not.
|
// IsValidHealthString checks if the provided string is a valid container health status or not.
|
||||||
func IsValidHealthString(s string) bool {
|
func IsValidHealthString(s string) bool {
|
||||||
return s == types.Starting ||
|
return s == types.Starting ||
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
containertypes "github.com/docker/docker/api/types/container"
|
containertypes "github.com/docker/docker/api/types/container"
|
||||||
"github.com/pborman/uuid"
|
"github.com/pborman/uuid"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -159,3 +160,26 @@ func TestNames(t *testing.T) {
|
||||||
view = db.Snapshot()
|
view = db.Snapshot()
|
||||||
assert.Equal(t, map[string][]string{"containerid4": {"name1", "name2"}}, view.GetAllNames())
|
assert.Equal(t, map[string][]string{"containerid4": {"name1", "name2"}}, view.GetAllNames())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test case for GitHub issue 35920
|
||||||
|
func TestViewWithHealthCheck(t *testing.T) {
|
||||||
|
var (
|
||||||
|
db, _ = NewViewDB()
|
||||||
|
one = newContainer(t)
|
||||||
|
)
|
||||||
|
one.Health = &Health{
|
||||||
|
Health: types.Health{
|
||||||
|
Status: "starting",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if err := one.CheckpointTo(db); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
s, err := db.Snapshot().Get(one.ID)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if s == nil || s.Health != "starting" {
|
||||||
|
t.Fatalf("expected Health=starting. Got: %+v", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue