This is an automated email from the ASF dual-hosted git repository. msciabarra pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/openserverless-cli.git
commit 80a54f226a130487001636c10db16ce653694b0f Author: Michele Sciabarra <[email protected]> AuthorDate: Wed Aug 7 16:41:25 2024 +0200 fixed a few tests --- auth/login.go | 9 +++++++++ ops.go | 7 +++++-- tests/auto_setup.bats | 12 +++++------- tests/folders.bats | 2 +- tests/login.bats | 26 +++++++++++--------------- tests/update.bats | 8 +++++--- tools/extract.go | 5 ++++- 7 files changed, 40 insertions(+), 29 deletions(-) diff --git a/auth/login.go b/auth/login.go index 8af3a5b..de4a9ec 100644 --- a/auth/login.go +++ b/auth/login.go @@ -28,6 +28,7 @@ import ( "net/http" "os" "path/filepath" + "strings" "github.com/apache/openserverless-cli/config" "github.com/zalando/go-keyring" @@ -91,6 +92,14 @@ func LoginCmd() (*LoginResult, error) { } url := apihost + whiskLoginPath + if !strings.HasPrefix(apihost, "http://") && !strings.HasPrefix(apihost, "https://") { + if apihost == "localhost" { + apihost = "http://" + apihost + } else { + apihost = "https://" + apihost + } + } + // try to get the user from the environment user := os.Getenv("OPS_USER") if user == "" { diff --git a/ops.go b/ops.go index 23b56fe..6e4c470 100644 --- a/ops.go +++ b/ops.go @@ -224,8 +224,11 @@ func Ops(base string, args []string) error { // parsed args if os.Getenv("OPS_NO_DOCOPTS") == "" && exists(".", DOCOPTS) { - trace("PREPARSE:", rest) - parsedArgs := parseArgs(readfile(DOCOPTS), rest) + debug("PREPARSE:", rest) + opts := readfile(DOCOPTS) + trace("DOCOPTS: size=", len(opts)) + parsedArgs := parseArgs(opts, rest) + trace("DOCOPTS: parsedargs=", parsedArgs) prefix := []string{"-t", OPSFILE} if len(rest) > 0 && rest[0][0] != '-' { prefix = append(prefix, rest[0]) diff --git a/tests/auto_setup.bats b/tests/auto_setup.bats index bcc4e48..a1466af 100644 --- a/tests/auto_setup.bats +++ b/tests/auto_setup.bats @@ -20,33 +20,31 @@ setup() { load 'test_helper/bats-assert/load' export NO_COLOR=1 cd testdata + ops -reset force } @test "first run auto setups" { - run rm -rf ~/.ops run ops assert_success - assert_output --partial "Welcome to ops! Setting up..." + assert_output --partial "Welcome to ops" run ls ~/.ops assert_success } @test "wrong branch fails to setup" { - run rm -rf ~/.ops export OPS_BRANCH=wrong - run ops + run ops -info assert_failure assert_output --partial "Welcome to ops! Setting up..." assert_output --partial "failed to clone olaris on branch 'wrong'" } @test "correct branch setups" { - run rm -rf ~/.ops export OPS_BRANCH=0.1.0 - run ops + run ops -info assert_success assert_output --partial "Welcome to ops! Setting up..." + assert_output --partial "OPS_BRANCH: 0.1.0" run ls ~/.ops assert_success - assert_output --partial "0.1.0" } diff --git a/tests/folders.bats b/tests/folders.bats index e55df7a..d3d9b2a 100644 --- a/tests/folders.bats +++ b/tests/folders.bats @@ -22,7 +22,7 @@ setup() { } @test "welcome" { - run ops + run ops -t assert_line '* fail_then_succeed: fail then success' assert_line '* failing: failing' assert_line '* sub: sub command' diff --git a/tests/login.bats b/tests/login.bats index 974abc1..099721b 100644 --- a/tests/login.bats +++ b/tests/login.bats @@ -29,35 +29,39 @@ setup() { run ops -login -h assert_line "Usage:" - assert_line "ops login <apihost> [<user>]" + assert_line "ops -login <apihost> [<user>]" } @test "ops -login with OPS_PASSWORD env does not prompt for password" { export OPS_PASSWORD=1234 - run ops -login localhost + run ops -login nuvolaris.dev + assert_line --partial "Logging in https://nuvolaris.dev" refute_line "Enter Password:" } @test "ops -login with OPS_USER env defines username" { export OPS_PASSWORD=1234 export OPS_USER=foo - run ops -login localhost - assert_line "Logging in as foo to localhost" + run ops -login http://localhost + assert_failure + assert_line "Logging in http://localhost as foo" } @test "ops -login with OPS_USER and OPS_PASSWORD env" { export OPS_PASSWORD=1234 export OPS_USER=foo run ops -login localhost - assert_line "Logging in as foo to localhost" + assert_line "Logging in http://localhost as foo" refute_line "Enter Password:" } @test "ops -login with OPS_APIHOST env" { export OPS_APIHOST=localhost export OPS_PASSWORD=1234 + unset OPS_USER run ops -login - assert_line "Logging in as nuvolaris to localhost" + assert_failure + assert_line "Logging in http://localhost as nuvolaris" } @test "ops -login with OPS_APIHOST and OPS_USER env" { @@ -65,13 +69,5 @@ setup() { export OPS_USER=foo export OPS_PASSWORD=1234 run ops -login - assert_line "Logging in as foo to localhost" + assert_line "Logging in http://localhost as foo" } - -@test "ops -login with OPS_APIHOST, user is now first argument" { - export OPS_APIHOST=localhost - export OPS_PASSWORD=1234 - run ops -login hello - assert_line "Logging in as hello to localhost" - refute_line "Enter Password:" -} \ No newline at end of file diff --git a/tests/update.bats b/tests/update.bats index 727b0fd..d0c5ba2 100644 --- a/tests/update.bats +++ b/tests/update.bats @@ -19,7 +19,7 @@ setup() { load 'test_helper/bats-support/load' load 'test_helper/bats-assert/load' export NO_COLOR=1 - rm -rf ~/.ops + ops -reset force cd .. } @@ -29,10 +29,11 @@ setup() { assert_line "Tasks downloaded successfully" assert_line --partial "ensuring prerequisite coreutils" - OPS_VERSION=0.0.0 run ops -update + OPS_VERSION=0.0.0 OPS_SKIP_UPDATE_CLI=1 run ops -update assert_line --partial "Your ops version (0.0.0) is older than the required version" - assert_line "Trying to update ops..." assert_success + assert_line "Trying to update ops..." + assert_line --partial "skipping rename" OPS_VERSION=10.2.3 run ops -update assert_line "Tasks are already up to date!" @@ -48,5 +49,6 @@ setup() { @test "ops -update on branch" { OPS_BRANCH=main run ops -update assert_line "Tasks downloaded successfully" + assert test -d ~/.ops/main assert_success } diff --git a/tools/extract.go b/tools/extract.go index 005a7f1..94f322a 100644 --- a/tools/extract.go +++ b/tools/extract.go @@ -154,7 +154,10 @@ func Extract() (int, error) { fmt.Println("Usage: file.(zip|tgz|tar[.gz|.bz2|.xz]) target") return 0, nil } - var err error + _, err := os.Stat(os.Args[1]) + if os.IsNotExist(err) { + return 1, err + } if strings.HasSuffix(os.Args[1], ".zip") { err = ExtractFileFromZip(os.Args[1], os.Args[2]) } else {
