Skip to content

Commit

Permalink
test: add new cli test
Browse files Browse the repository at this point in the history
  • Loading branch information
soasurs committed Aug 6, 2020
1 parent 72dcdd0 commit 202ea14
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -61,7 +61,7 @@ install: resources
GOOS=$(GOOS) go install github.com/leancloud/lean-cli/lean

test:
sh test.sh
go test github.com/leancloud/lean-cli/lean -v

resources:
(cd console; $(MAKE))
Expand Down
64 changes: 64 additions & 0 deletions lean/main_test.go
@@ -0,0 +1,64 @@
package main

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"testing"
)

var testUsername, testPassword, testRegion, testGroup, testAppID, repoURL string

func TestMain(m *testing.M) {
testUsername, testPassword, testRegion = os.Getenv("TEST_USERNAME"), os.Getenv("TEST_PASSWORD"), os.Getenv("TEST_REGION")
repoURL, testGroup, testAppID = os.Getenv("REPO_URL"), os.Getenv("TEST_GROUP"), os.Getenv("TEST_APPID")

dir, err := ioutil.TempDir("", "*")
if err != nil {
fmt.Fprintln(os.Stderr, err)
panic(err)
}

if err := os.Chdir(dir); err != nil {
fmt.Fprintln(os.Stderr, err)
panic(err)
}

if err := exec.Command("git", "clone", repoURL, "lean-cli-deployment").Run(); err != nil {
fmt.Fprintln(os.Stderr, err)
panic(err)
}

gitDir := filepath.Join(dir, "lean-cli-deployment")
if err := os.Chdir(gitDir); err != nil {
fmt.Fprintln(os.Stderr, err)
panic(err)
}

os.Exit(m.Run())

defer os.RemoveAll(dir)

}

func TestLogin(t *testing.T) {
os.Args = []string{"lean", "login", "--username", testUsername, "--password", testPassword, "--region", testRegion}
main()
}

func TestSwitch(t *testing.T) {
os.Args = []string{"lean", "switch", "--region", testRegion, "--group", testGroup, testAppID}
main()
}

func TestDeploy(t *testing.T) {
os.Args = []string{"lean", "deploy", "--prod", "0"}
main()
}

func TestPublish(t *testing.T) {
os.Args = []string{"lean", "publish"}
main()
}
32 changes: 0 additions & 32 deletions tests/tests.py

This file was deleted.

0 comments on commit 202ea14

Please sign in to comment.