Skip to content
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 more e2e test cases #330

Merged
merged 8 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ jobs:
${{ runner.OS }}-build-${{ env.cache-name }}-
${{ runner.OS }}-build-
${{ runner.OS }}-
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Verify mockgen
run: |
make generate && git add pkg &&
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ test-local:
@go test -v -race -coverprofile=coverage.out ./...

test: generate
@go test -race -coverprofile=coverage.out ./...
@go test -race -coverpkg=./pkg/... -coverprofile=coverage.out ./...
@go tool cover -func coverage.out | tail -n 1 | awk '{ print "Total coverage: " $$3 }'

clean:
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ deb https://mirror.sjtu.edu.cn/ubuntu focal-security main restricted universe mu
""")
config.pip_index(url = "https://mirror.sjtu.edu.cn/pypi/web/simple")
install.vscode_extensions([
"ms-python.python",
"github.copilot"
"ms-python.python"
])
```

Expand Down
2 changes: 1 addition & 1 deletion pkg/app/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

var _ = Describe("build command", func() {
buildContext := "testdata"
buildContext := "testdata/build-test"
args := []string{
"envd.test", "--debug", "build", "--path", buildContext,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"github.com/cockroachdb/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
cli "github.com/urfave/cli/v2"

"github.com/tensorchord/envd/pkg/docker"
sshconfig "github.com/tensorchord/envd/pkg/ssh/config"
Expand Down
41 changes: 41 additions & 0 deletions pkg/app/get_env_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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 app

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/tensorchord/envd/pkg/home"
)

var _ = Describe("get env command", func() {
args := []string{
"envd.test", "--debug", "get", "envs",
}
BeforeEach(func() {
Expect(home.Initialize()).NotTo(HaveOccurred())
app := New()
err := app.Run([]string{"envd.test", "--debug", "bootstrap"})
Expect(err).NotTo(HaveOccurred())
})
When("given the right arguments", func() {
It("should get the environments successfully", func() {
app := New()
err := app.Run(args)
Expect(err).NotTo(HaveOccurred())
})
})
})
2 changes: 2 additions & 0 deletions pkg/app/testdata/build-test/build.envd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def build():
base(os="ubuntu20.04", language="python3")
6 changes: 0 additions & 6 deletions pkg/app/testdata/build.envd

This file was deleted.

12 changes: 12 additions & 0 deletions pkg/app/testdata/up-test/build.envd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def build():
base(os="ubuntu20.04", language="python3")
install.python_packages(name = [
"ormb",
])
install.system_packages(name = ["screenfetch"])
shell("zsh")
config.pip_index(url = "https://pypi.tuna.tsinghua.edu.cn/simple")
git_config(name="envd", email="envd@envd", editor="vim")
install.vscode_extensions([
"ms-python.python"
])
28 changes: 20 additions & 8 deletions pkg/app/up_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,40 @@ import (
)

var _ = Describe("up command", func() {
buildContext := "testdata"
args := []string{
"envd.test", "--debug", "up", "--path", buildContext, "--detach",
buildContext := "testdata/up-test"
env := "up-test"
baseArgs := []string{
"envd.test", "--debug",
}
BeforeEach(func() {
Expect(home.Initialize()).NotTo(HaveOccurred())
app := New()
err := app.Run([]string{"envd.test", "--debug", "bootstrap"})
err := app.Run(append(baseArgs, "bootstrap"))
Expect(err).NotTo(HaveOccurred())
cli, err := docker.NewClient(context.TODO())
Expect(err).NotTo(HaveOccurred())
_, err = cli.Destroy(context.TODO(), buildContext)
_, err = cli.Destroy(context.TODO(), env)
Expect(err).NotTo(HaveOccurred())
})
When("given the right arguments", func() {
It("should up and destroy successfully", func() {
args := append(baseArgs, []string{
"up", "--path", buildContext, "--detach",
}...)
app := New()
err := app.Run(args)
Expect(err).NotTo(HaveOccurred())
destroyArgs := []string{
"envd.test", "--debug", "destroy", "--path", buildContext,
}

depsArgs := append(baseArgs, []string{
"get", "envs", "deps", "--env", env,
}...)

err = app.Run(depsArgs)
Expect(err).NotTo(HaveOccurred())

destroyArgs := append(baseArgs, []string{
"destroy", "--path", buildContext,
}...)
err = app.Run(destroyArgs)
Expect(err).NotTo(HaveOccurred())
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/editor/vscode/vscode.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/sirupsen/logrus"

"github.com/tensorchord/envd/pkg/home"
"github.com/tensorchord/envd/pkg/unzip"
"github.com/tensorchord/envd/pkg/util/ziputil"
)

const (
Expand Down Expand Up @@ -134,7 +134,7 @@ func (c generalClient) DownloadOrCache(p Plugin) (bool, error) {
return false, err
}

_, err = unzip.Unzip(filename, unzipPath(p))
_, err = ziputil.Unzip(filename, unzipPath(p))
if err != nil {
return false, errors.Wrap(err, "failed to unzip")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ssh/config/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package sshconfig
package config

import (
"crypto/rand"
Expand Down
Empty file added pkg/ssh/config/ssh_config
Empty file.
2 changes: 1 addition & 1 deletion pkg/ssh/config/ssh_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package sshconfig
package config

import (
"bufio"
Expand Down
27 changes: 27 additions & 0 deletions pkg/ssh/config/ssh_config_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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 config

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestMain(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "ssh config Suite")
}
40 changes: 40 additions & 0 deletions pkg/ssh/config/ssh_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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 config

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("ssh config", func() {
When("giving a empty ssh config", func() {
It("Should add/remove the config successfully", func() {
env := "test-ssh-config"
iface := "localhost"
port := 8888
keyPath := "key"
err := add(getSSHConfigPath(), buildHostname(env), iface, port, keyPath)
Expect(err).NotTo(HaveOccurred())

actual, err := GetPort(env)
Expect(err).NotTo(HaveOccurred())
Expect(actual).To(Equal(port))

err = remove(getSSHConfigPath(), env)
Expect(err).NotTo(HaveOccurred())
})
})
})
2 changes: 1 addition & 1 deletion pkg/unzip/unzip.go → pkg/util/ziputil/unzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package unzip
package ziputil

import (
"archive/zip"
Expand Down