Skip to content

Commit 6e0e0da

Browse files
committed
feat(tools):
resolves apache/openserverless#44
1 parent 06e6c4b commit 6e0e0da

35 files changed

Lines changed: 292 additions & 168 deletions

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ func Main() {
341341
}
342342

343343
// setup the envvar for the embedded tools
344-
os.Setenv("OPS_TOOLS", strings.Join(append(mainTools, tools.ToolList...), " "))
344+
os.Setenv("OPS_TOOLS", strings.Join(tools.MergeToolsList(mainTools), " "))
345345

346346
// CLI: ops -v | --version | -h | --help | -reset
347347
// preliminanre processing not requiring to downloading anything

prepare_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ func Example_download() {
5858
// Updating tasks...
5959
// Tasks are already up to date!
6060
// 2 <nil> /home/.ops/0.1.0/olaris
61-
6261
}
6362

6463
func Example_locate_root() {

tests/datefmt.bats

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ setup() {
2121
export NO_COLOR=1
2222
}
2323

24-
@test "datefmt print usage" {
24+
@test "-datefmt help message" {
2525
run ops -datefmt -h
2626
assert_success
27-
assert_line "Usage:"
27+
assert_line --partial "ops -datefmt [options] [arguments]"
2828

2929
run ops -datefmt --help
3030
assert_success
31-
assert_line "Usage:"
31+
assert_line --partial "ops -datefmt [options] [arguments]"
3232
}
3333

34+
3435
@test "datefmt with input timestamp and output format" {
3536
run ops -datefmt -t 1577836800 -f DateOnly
3637
assert_success

tests/echoif.bats

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ setup() {
2323

2424
@test "-echoif help message" {
2525
run ops -echoif
26-
assert_line "Usage: echoif <a> <b>"
26+
assert_success
27+
assert_line --partial "ops -echoif <a> <b>"
2728

2829
run ops -echoif -h
29-
assert_line "Usage: echoif <a> <b>"
30+
assert_success
31+
assert_line --partial "ops -echoif <a> <b>"
3032
}
3133

3234
@test "-echoif echoes a with successful previous command" {
@@ -43,10 +45,12 @@ setup() {
4345

4446
@test "-echoifempty help message" {
4547
run ops -echoifempty
46-
assert_line "Usage: echoifempty <str> <a> <b>"
48+
assert_success
49+
assert_line --partial "ops -echoifempty <str> <a> <b>"
4750

4851
run ops -echoifempty -h
49-
assert_line "Usage: echoifempty <str> <a> <b>"
52+
assert_success
53+
assert_line --partial "ops -echoifempty <str> <a> <b>"
5054
}
5155

5256
@test "-echoifempty echoes a if string is empty" {
@@ -61,10 +65,12 @@ setup() {
6165

6266
@test "-echoifexists help message" {
6367
run ops -echoifexists
64-
assert_line "Usage: echoifexists <file> <a> <b>"
68+
assert_success
69+
assert_line --partial "ops -echoifexists <file> <a> <b>"
6570

6671
run ops -echoifexists -h
67-
assert_line "Usage: echoifexists <file> <a> <b>"
72+
assert_success
73+
assert_line --partial "ops -echoifexists <file> <a> <b>"
6874
}
6975

7076
@test "-echoifexists echoes a if file exists" {

tests/extract.bats

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ setup() {
2424

2525
@test "extract" {
2626
run ops -extract
27-
assert_line "Usage: file.(zip|tgz|tar[.gz|.bz2|.xz]) target"
27+
assert_success
28+
assert_line --partial "ops -extract file.(zip|tgz|tar[.gz|.bz2|.xz]) target"
2829
curl -sL -o7zip.tar.xz https://www.7-zip.org/a/7z2407-linux-x64.tar.xz
2930

3031
run ops -extract 7zip.tar.xz missing
@@ -54,17 +55,4 @@ setup() {
5455
run ops -extract coreutils.zip coreutils.exe
5556
assert_success
5657
assert test -e coreutils.exe
57-
}
58-
59-
@test "-empty" {
60-
run ops -empty
61-
assert_line "Usage: filename"
62-
run ops -empty empty_file
63-
assert test -f empty_file
64-
assert_success
65-
run ops -empty empty_file
66-
assert_failure
67-
assert_line "file already exists"
68-
rm empty_file
69-
70-
}
58+
}

tests/filetype.bats

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ setup() {
2323

2424
@test "filetype usage print" {
2525
run ops -filetype
26-
assert_line "Usage: filetype [-h] [-e] [-m] FILE"
26+
assert_success
27+
assert_line --partial "ops -filetype [-h] [-e] [-m] FILE"
2728

2829
run ops -filetype -h
29-
assert_line "Usage: filetype [-h] [-e] [-m] FILE"
30+
assert_success
31+
assert_line --partial "ops -filetype [-h] [-e] [-m] FILE"
3032
}
3133

3234
@test "filetype -e" {

tests/needupdate.bats

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ setup() {
2323

2424
@test "needupdate message" {
2525
run ops -needupdate
26-
assert_line "Usage:"
26+
assert_failure
27+
assert_line --partial "ops -needupdate <versionA> <versionB>"
2728

2829
run ops -needupdate -h
29-
assert_line "Usage:"
30+
assert_success
31+
assert_line --partial "ops -needupdate <versionA> <versionB>"
3032
}
3133

3234
@test "needupdate returns 0 if a > b" {

tests/random.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ setup() {
2424
@test "ops -random help" {
2525
run ops -random -h
2626
assert_success
27-
assert_line "Usage:"
27+
assert_line --partial "ops -random [options]"
2828

2929
run ops -random --help
3030
assert_success
31-
assert_line "Usage:"
31+
assert_line --partial "ops -random [options]"
3232
}
3333

3434
@test "ops -random" {

tests/retry.bats

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ setup() {
2424
@test "ops -retry help" {
2525
run ops -retry
2626
assert_success
27-
assert_line "Usage:"
27+
assert_line --partial "ops -retry [options] task [task options]"
2828

2929
run ops -retry -h
3030
assert_success
31-
assert_line "Usage:"
31+
assert_line --partial "ops -retry [options] task [task options]"
3232

3333
run ops -retry --help
3434
assert_success
35-
assert_line "Usage:"
35+
assert_line --partial "ops -retry [options] task [task options]"
3636
}
3737

3838
@test "ops -retry fail" {

tests/urlenc.bats

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
setup() {
19+
load 'test_helper/bats-support/load'
20+
load 'test_helper/bats-assert/load'
21+
export NO_COLOR=1
22+
}
23+
24+
@test "ops -urlenc help" {
25+
run ops -urlenc -h
26+
assert_success
27+
assert_line --partial "ops -urlenc [-e] [-s <string>] [parameters]"
28+
29+
run ops -urlenc --help
30+
assert_success
31+
assert_line --partial "ops -urlenc [-e] [-s <string>] [parameters]"
32+
}
33+
34+
@test "ops -urlenc" {
35+
run ops -urlenc
36+
assert_success
37+
refute_output
38+
39+
run ops -urlenc a=1 b=2
40+
assert_success
41+
assert_line "a%3D1&b%3D2"
42+
43+
run ops -urlenc -s "|" a=1 b=2
44+
assert_success
45+
assert_line "a%3D1|b%3D2"
46+
}
47+
48+
@test "ops -urlenc string from env" {
49+
run env TEST=ops ops -urlenc -e TEST
50+
assert_line "ops"
51+
}

0 commit comments

Comments
 (0)