|
| 1 | +package check |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "errors" |
| 6 | + "testing" |
| 7 | +) |
| 8 | + |
| 9 | +func TestComposeCheck_AllRunning(t *testing.T) { |
| 10 | + c := &ComposeCheck{runner: func() ([]byte, error) { |
| 11 | + return []byte(`{"Name":"app-db-1","State":"running"}` + "\n" + |
| 12 | + `{"Name":"app-web-1","State":"running"}` + "\n"), nil |
| 13 | + }} |
| 14 | + result := c.Run(context.Background()) |
| 15 | + if result.Status != StatusPass { |
| 16 | + t.Errorf("expected pass, got %v: %s", result.Status, result.Message) |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +func TestComposeCheck_SomeStopped(t *testing.T) { |
| 21 | + c := &ComposeCheck{runner: func() ([]byte, error) { |
| 22 | + return []byte(`{"Name":"app-db-1","State":"running"}` + "\n" + |
| 23 | + `{"Name":"app-web-1","State":"exited"}` + "\n"), nil |
| 24 | + }} |
| 25 | + result := c.Run(context.Background()) |
| 26 | + if result.Status != StatusFail { |
| 27 | + t.Errorf("expected fail, got %v", result.Status) |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +func TestComposeCheck_CommandFails(t *testing.T) { |
| 32 | + c := &ComposeCheck{runner: func() ([]byte, error) { |
| 33 | + return nil, errors.New("docker not found") |
| 34 | + }} |
| 35 | + result := c.Run(context.Background()) |
| 36 | + if result.Status != StatusFail { |
| 37 | + t.Errorf("expected fail, got %v", result.Status) |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +func TestComposeCheck_NoServices(t *testing.T) { |
| 42 | + c := &ComposeCheck{runner: func() ([]byte, error) { |
| 43 | + return []byte(""), nil |
| 44 | + }} |
| 45 | + result := c.Run(context.Background()) |
| 46 | + if result.Status != StatusPass { |
| 47 | + t.Errorf("expected pass, got %v: %s", result.Status, result.Message) |
| 48 | + } |
| 49 | +} |
0 commit comments