-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add e2e test helper for container use spec #640
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0ef6a90
WIP: add remove image in docker client
aseaday a4487e2
WIP chore: Add e2e test
aseaday f940ec7
WIP: move the e2e tests
aseaday ac6e351
WIP: move the quick start
aseaday 0e7e480
WIP: fix lint
aseaday 2a28b73
WIP: Merge branch 'main' into chore/add_e2e_test
aseaday de55149
WIP: fix e2e test script
aseaday a27bff0
WIP: spec location adjust
aseaday 554bf54
WIP: spec location adjust
aseaday 7847070
WIP: spec location adjust
aseaday a3310b2
WIP: fix ci
aseaday 3b7c3cc
WIP: fix ci
aseaday 5b3488f
WIP: fix ci
aseaday e68464b
WIP: fix ci
aseaday 37bad88
WIP: fix ci
aseaday File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,140 @@ | ||
// Copyright 2022 The envd Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package e2e | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/tensorchord/envd/pkg/app" | ||
"github.com/tensorchord/envd/pkg/docker" | ||
"github.com/tensorchord/envd/pkg/ssh" | ||
sshconfig "github.com/tensorchord/envd/pkg/ssh/config" | ||
) | ||
|
||
func BuildImage(exampleName string) func() { | ||
return func() { | ||
logrus.Info("building quick-start image") | ||
err := BuildExampleImage(exampleName, app.New()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} | ||
|
||
func RemoveImage(exampleName string) func() { | ||
return func() { | ||
err := RemoveExampleImage(exampleName) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} | ||
|
||
func RunContainer(exampleName string) func() { | ||
return func() { | ||
err := RunExampleContainer(exampleName, app.New()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} | ||
|
||
func DestoryContainer(exampleName string) func() { | ||
return func() { | ||
err := DestroyExampleContainer(exampleName, app.New()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} | ||
|
||
type Example struct { | ||
Name string | ||
} | ||
|
||
func example(name string) *Example { | ||
return &Example{ | ||
Name: name, | ||
} | ||
} | ||
|
||
func (e *Example) Exec(cmd string) string { | ||
sshClient := getSSHClient(e.Name) | ||
ret, err := sshClient.ExecWithOutput(cmd) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return strings.Trim(string(ret), "\n") | ||
} | ||
|
||
func BuildExampleImage(exampleName string, app app.EnvdApp) error { | ||
buildContext := "testdata/" + exampleName | ||
tag := exampleName + ":e2etest" | ||
args := []string{ | ||
"envd.test", "--debug", "build", "--path", buildContext, "--tag", tag, "--force", | ||
} | ||
err := app.Run(args) | ||
return err | ||
} | ||
|
||
func RemoveExampleImage(exampleName string) error { | ||
ctx := context.TODO() | ||
dockerClient, err := docker.NewClient(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
err = dockerClient.RemoveImage(ctx, exampleName+":e2etest") | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func RunExampleContainer(exampleName string, app app.EnvdApp) error { | ||
buildContext := "testdata/" + exampleName | ||
tag := exampleName + ":e2etest" | ||
args := []string{ | ||
"envd.test", "--debug", "up", "--path", buildContext, "--tag", tag, "--detach", "--force", | ||
} | ||
err := app.Run(args) | ||
return err | ||
} | ||
|
||
func DestroyExampleContainer(exampleName string, app app.EnvdApp) error { | ||
buildContext := "testdata/" + exampleName | ||
args := []string{ | ||
"envd.test", "--debug", "destroy", "--path", buildContext, | ||
} | ||
err := app.Run(args) | ||
return err | ||
} | ||
|
||
func getSSHClient(exampleName string) ssh.Client { | ||
localhost := "127.0.0.1" | ||
port, err := sshconfig.GetPort(exampleName) | ||
if err != nil { | ||
panic(err) | ||
} | ||
priv_path := sshconfig.GetPrivateKey() | ||
sshClient, err := ssh.NewClient( | ||
localhost, "envd", port, true, priv_path, "") | ||
if err != nil { | ||
panic(err) | ||
} | ||
return sshClient | ||
} |
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,31 @@ | ||
// Copyright 2022 The envd Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package e2e | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("e2e quickstart", Ordered, func() { | ||
exampleName := "quick-start" | ||
BeforeAll(BuildImage(exampleName)) | ||
BeforeEach(RunContainer(exampleName)) | ||
It("execute python demo.py", func() { | ||
Expect(example(exampleName).Exec("python demo.py")).To(Equal("[2 3 4]")) | ||
}) | ||
AfterEach(DestoryContainer(exampleName)) | ||
AfterAll(RemoveImage(exampleName)) | ||
}) |
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
File renamed without changes.
File renamed without changes.
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,6 @@ | ||
def build(): | ||
base(os="ubuntu20.04", language="python3") | ||
install.python_packages(name = [ | ||
"numpy", | ||
]) | ||
shell("zsh") |
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,5 @@ | ||
import numpy as np | ||
|
||
a = np.array([2, 3, 4]) | ||
|
||
print(a) |
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should place the example in testdata/.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just want to test all examples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I could move the extra
envd-quick-start
to testdata. And other tests shoule be wrote to cover the examplesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
examples may be complex. Personally, I prefer to test different features in different test cases. WDYT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM