forked from flyteorg/flyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Share demo/sandbox status command logic (flyteorg#364)
Signed-off-by: Daniel Shuy <[email protected]> Signed-off-by: Daniel Shuy <[email protected]>
- Loading branch information
1 parent
1464792
commit 8954d97
Showing
4 changed files
with
65 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package sandbox | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/enescakir/emoji" | ||
"github.com/flyteorg/flytectl/pkg/docker" | ||
) | ||
|
||
func PrintStatus(ctx context.Context, cli docker.Docker) error { | ||
c, err := docker.GetSandbox(ctx, cli) | ||
if err != nil { | ||
return err | ||
} | ||
if c == nil { | ||
fmt.Printf("%v no Sandbox found \n", emoji.StopSign) | ||
return nil | ||
} | ||
fmt.Printf("Flyte local sandbox container image [%s] with status [%s] is in state [%s]", c.Image, c.Status, c.State) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package sandbox | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/flyteorg/flytectl/cmd/testutils" | ||
|
||
"github.com/docker/docker/api/types" | ||
"github.com/flyteorg/flytectl/pkg/docker" | ||
"github.com/flyteorg/flytectl/pkg/docker/mocks" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSandboxStatus(t *testing.T) { | ||
t.Run("Sandbox status with zero result", func(t *testing.T) { | ||
mockDocker := &mocks.Docker{} | ||
s := testutils.Setup() | ||
mockDocker.OnContainerList(s.Ctx, types.ContainerListOptions{All: true}).Return([]types.Container{}, nil) | ||
err := PrintStatus(s.Ctx, mockDocker) | ||
assert.Nil(t, err) | ||
}) | ||
t.Run("Sandbox status with running sandbox", func(t *testing.T) { | ||
s := testutils.Setup() | ||
ctx := s.Ctx | ||
mockDocker := &mocks.Docker{} | ||
mockDocker.OnContainerList(ctx, types.ContainerListOptions{All: true}).Return([]types.Container{ | ||
{ | ||
ID: docker.FlyteSandboxClusterName, | ||
Names: []string{ | ||
docker.FlyteSandboxClusterName, | ||
}, | ||
}, | ||
}, nil) | ||
err := PrintStatus(ctx, mockDocker) | ||
assert.Nil(t, err) | ||
}) | ||
} |