Skip to content

Commit 80a54f2

Browse files
fixed a few tests
1 parent 1cbe7f8 commit 80a54f2

7 files changed

Lines changed: 40 additions & 29 deletions

File tree

auth/login.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"net/http"
2929
"os"
3030
"path/filepath"
31+
"strings"
3132

3233
"github.com/apache/openserverless-cli/config"
3334
"github.com/zalando/go-keyring"
@@ -91,6 +92,14 @@ func LoginCmd() (*LoginResult, error) {
9192
}
9293
url := apihost + whiskLoginPath
9394

95+
if !strings.HasPrefix(apihost, "http://") && !strings.HasPrefix(apihost, "https://") {
96+
if apihost == "localhost" {
97+
apihost = "http://" + apihost
98+
} else {
99+
apihost = "https://" + apihost
100+
}
101+
}
102+
94103
// try to get the user from the environment
95104
user := os.Getenv("OPS_USER")
96105
if user == "" {

ops.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,11 @@ func Ops(base string, args []string) error {
224224

225225
// parsed args
226226
if os.Getenv("OPS_NO_DOCOPTS") == "" && exists(".", DOCOPTS) {
227-
trace("PREPARSE:", rest)
228-
parsedArgs := parseArgs(readfile(DOCOPTS), rest)
227+
debug("PREPARSE:", rest)
228+
opts := readfile(DOCOPTS)
229+
trace("DOCOPTS: size=", len(opts))
230+
parsedArgs := parseArgs(opts, rest)
231+
trace("DOCOPTS: parsedargs=", parsedArgs)
229232
prefix := []string{"-t", OPSFILE}
230233
if len(rest) > 0 && rest[0][0] != '-' {
231234
prefix = append(prefix, rest[0])

tests/auto_setup.bats

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,31 @@ setup() {
2020
load 'test_helper/bats-assert/load'
2121
export NO_COLOR=1
2222
cd testdata
23+
ops -reset force
2324
}
2425

2526
@test "first run auto setups" {
26-
run rm -rf ~/.ops
2727
run ops
2828
assert_success
29-
assert_output --partial "Welcome to ops! Setting up..."
29+
assert_output --partial "Welcome to ops"
3030
run ls ~/.ops
3131
assert_success
3232
}
3333

3434
@test "wrong branch fails to setup" {
35-
run rm -rf ~/.ops
3635
export OPS_BRANCH=wrong
37-
run ops
36+
run ops -info
3837
assert_failure
3938
assert_output --partial "Welcome to ops! Setting up..."
4039
assert_output --partial "failed to clone olaris on branch 'wrong'"
4140
}
4241

4342
@test "correct branch setups" {
44-
run rm -rf ~/.ops
4543
export OPS_BRANCH=0.1.0
46-
run ops
44+
run ops -info
4745
assert_success
4846
assert_output --partial "Welcome to ops! Setting up..."
47+
assert_output --partial "OPS_BRANCH: 0.1.0"
4948
run ls ~/.ops
5049
assert_success
51-
assert_output --partial "0.1.0"
5250
}

tests/folders.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ setup() {
2222
}
2323

2424
@test "welcome" {
25-
run ops
25+
run ops -t
2626
assert_line '* fail_then_succeed: fail then success'
2727
assert_line '* failing: failing'
2828
assert_line '* sub: sub command'

tests/login.bats

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,49 +29,45 @@ setup() {
2929

3030
run ops -login -h
3131
assert_line "Usage:"
32-
assert_line "ops login <apihost> [<user>]"
32+
assert_line "ops -login <apihost> [<user>]"
3333
}
3434

3535
@test "ops -login with OPS_PASSWORD env does not prompt for password" {
3636
export OPS_PASSWORD=1234
37-
run ops -login localhost
37+
run ops -login nuvolaris.dev
38+
assert_line --partial "Logging in https://nuvolaris.dev"
3839
refute_line "Enter Password:"
3940
}
4041

4142
@test "ops -login with OPS_USER env defines username" {
4243
export OPS_PASSWORD=1234
4344
export OPS_USER=foo
44-
run ops -login localhost
45-
assert_line "Logging in as foo to localhost"
45+
run ops -login http://localhost
46+
assert_failure
47+
assert_line "Logging in http://localhost as foo"
4648
}
4749

4850
@test "ops -login with OPS_USER and OPS_PASSWORD env" {
4951
export OPS_PASSWORD=1234
5052
export OPS_USER=foo
5153
run ops -login localhost
52-
assert_line "Logging in as foo to localhost"
54+
assert_line "Logging in http://localhost as foo"
5355
refute_line "Enter Password:"
5456
}
5557

5658
@test "ops -login with OPS_APIHOST env" {
5759
export OPS_APIHOST=localhost
5860
export OPS_PASSWORD=1234
61+
unset OPS_USER
5962
run ops -login
60-
assert_line "Logging in as nuvolaris to localhost"
63+
assert_failure
64+
assert_line "Logging in http://localhost as nuvolaris"
6165
}
6266

6367
@test "ops -login with OPS_APIHOST and OPS_USER env" {
6468
export OPS_APIHOST=localhost
6569
export OPS_USER=foo
6670
export OPS_PASSWORD=1234
6771
run ops -login
68-
assert_line "Logging in as foo to localhost"
72+
assert_line "Logging in http://localhost as foo"
6973
}
70-
71-
@test "ops -login with OPS_APIHOST, user is now first argument" {
72-
export OPS_APIHOST=localhost
73-
export OPS_PASSWORD=1234
74-
run ops -login hello
75-
assert_line "Logging in as hello to localhost"
76-
refute_line "Enter Password:"
77-
}

tests/update.bats

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ setup() {
1919
load 'test_helper/bats-support/load'
2020
load 'test_helper/bats-assert/load'
2121
export NO_COLOR=1
22-
rm -rf ~/.ops
22+
ops -reset force
2323
cd ..
2424
}
2525

@@ -29,10 +29,11 @@ setup() {
2929
assert_line "Tasks downloaded successfully"
3030
assert_line --partial "ensuring prerequisite coreutils"
3131

32-
OPS_VERSION=0.0.0 run ops -update
32+
OPS_VERSION=0.0.0 OPS_SKIP_UPDATE_CLI=1 run ops -update
3333
assert_line --partial "Your ops version (0.0.0) is older than the required version"
34-
assert_line "Trying to update ops..."
3534
assert_success
35+
assert_line "Trying to update ops..."
36+
assert_line --partial "skipping rename"
3637

3738
OPS_VERSION=10.2.3 run ops -update
3839
assert_line "Tasks are already up to date!"
@@ -48,5 +49,6 @@ setup() {
4849
@test "ops -update on branch" {
4950
OPS_BRANCH=main run ops -update
5051
assert_line "Tasks downloaded successfully"
52+
assert test -d ~/.ops/main
5153
assert_success
5254
}

tools/extract.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ func Extract() (int, error) {
154154
fmt.Println("Usage: file.(zip|tgz|tar[.gz|.bz2|.xz]) target")
155155
return 0, nil
156156
}
157-
var err error
157+
_, err := os.Stat(os.Args[1])
158+
if os.IsNotExist(err) {
159+
return 1, err
160+
}
158161
if strings.HasSuffix(os.Args[1], ".zip") {
159162
err = ExtractFileFromZip(os.Args[1], os.Args[2])
160163
} else {

0 commit comments

Comments
 (0)