Skip to content

Commit

Permalink
More oc plugin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianofranz committed Aug 9, 2017
1 parent 7550893 commit 34b3f36
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 0 deletions.
70 changes: 70 additions & 0 deletions test/cmd/plugins.sh
@@ -0,0 +1,70 @@
#!/bin/bash
source "$(dirname "${BASH_SOURCE}")/../../hack/lib/init.sh"
trap os::test::junit::reconcile_output EXIT

os::test::junit::declare_suite_start "cmd/plugin"

# top-level plugin command
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc -h 2>&1" 'Runs a command-line plugin'

# no plugins
os::cmd::expect_failure_and_text "oc plugin 2>&1" 'no plugins installed'

# single plugins path
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin 2>&1" 'Echoes for test-cmd'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin 2>&1" 'The wonderful new plugin-based get!'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin 2>&1" 'The tremendous plugin that always fails!'
os::cmd::expect_success_and_not_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin 2>&1" 'The hello plugin'
os::cmd::expect_success_and_not_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin 2>&1" 'Incomplete plugin'
os::cmd::expect_success_and_not_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin 2>&1" 'no plugins installed'

# multiple plugins path
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc plugin -h 2>&1" 'Echoes for test-cmd'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc plugin -h 2>&1" 'The wonderful new plugin-based get!'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc plugin -h 2>&1" 'The tremendous plugin that always fails!'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc plugin -h 2>&1" 'The hello plugin'
os::cmd::expect_success_and_not_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc plugin -h 2>&1" 'Incomplete plugin'

# don't override existing commands
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc get -h 2>&1" 'Display one or many resources'
os::cmd::expect_success_and_not_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc get -h 2>&1" 'The wonderful new plugin-based get'

# plugin help
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc plugin hello -h 2>&1" 'The hello plugin is a new plugin used by test-cmd to test multiple plugin locations.'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc plugin hello -h 2>&1" 'Usage:'

# run plugin
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc plugin hello 2>&1" '#hello#'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc plugin echo 2>&1" 'This plugin works!'
os::cmd::expect_failure_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin hello 2>&1" 'unknown command'
os::cmd::expect_failure_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin error 2>&1" 'error: exit status 1'

# plugin tree
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree 2>&1" 'Plugin with a tree of commands'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree 2>&1" 'The first child of a tree'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree 2>&1" 'The second child of a tree'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree 2>&1" 'The third child of a tree'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree child1 --help 2>&1" 'The first child of a tree'
os::cmd::expect_success_and_not_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree child1 --help 2>&1" 'The second child'
os::cmd::expect_success_and_not_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree child1 --help 2>&1" 'child2'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree child1 2>&1" 'child one'
os::cmd::expect_success_and_not_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree child1 2>&1" 'child1'
os::cmd::expect_success_and_not_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree child1 2>&1" 'The first child'

# plugin env
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env -h 2>&1" "This is a flag 1"
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env -h 2>&1" "This is a flag 2"
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env -h 2>&1" "This is a flag 3"
output_message=$()
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env --test1=value1 -t value2 2>&1" 'KUBECTL_PLUGINS_CURRENT_NAMESPACE'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env --test1=value1 -t value2 2>&1" 'KUBECTL_PLUGINS_CALLER'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env --test1=value1 -t value2 2>&1" 'KUBECTL_PLUGINS_DESCRIPTOR_COMMAND=./env.sh'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env --test1=value1 -t value2 2>&1" 'KUBECTL_PLUGINS_DESCRIPTOR_SHORT_DESC=The plugin envs plugin'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env --test1=value1 -t value2 2>&1" 'KUBECTL_PLUGINS_GLOBAL_FLAG_CONFIG'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env --test1=value1 -t value2 2>&1" 'KUBECTL_PLUGINS_GLOBAL_FLAG_REQUEST_TIMEOUT=0'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env --test1=value1 -t value2 2>&1" 'KUBECTL_PLUGINS_LOCAL_FLAG_TEST1=value1'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env --test1=value1 -t value2 2>&1" 'KUBECTL_PLUGINS_LOCAL_FLAG_TEST2=value2'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env --test1=value1 -t value2 2>&1" 'KUBECTL_PLUGINS_LOCAL_FLAG_TEST3=default'

echo "oc plugin: ok"
os::test::junit::declare_suite_end
4 changes: 4 additions & 0 deletions test/testdata/plugin/plugins/echo/plugin.yaml
@@ -0,0 +1,4 @@
name: "echo"
shortDesc: "Echoes for test-cmd"
longDesc: "Long description for the test-cmd echo plugin"
command: "echo This plugin works!"
17 changes: 17 additions & 0 deletions test/testdata/plugin/plugins/env/env.sh
@@ -0,0 +1,17 @@
#!/bin/bash

# Copyright 2017 The Kubernetes 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.

env | grep 'KUBECTL_PLUGINS' | sort
12 changes: 12 additions & 0 deletions test/testdata/plugin/plugins/env/plugin.yaml
@@ -0,0 +1,12 @@
name: env
shortDesc: "The plugin envs plugin"
command: "./env.sh"
flags:
- name: "test1"
desc: "This is a flag 1"
- name: "test2"
desc: "This is a flag 2"
shorthand: "t"
- name: "test3"
desc: "This is a flag 3"
defValue: "default"
3 changes: 3 additions & 0 deletions test/testdata/plugin/plugins/error/plugin.yaml
@@ -0,0 +1,3 @@
name: "error"
shortDesc: "The tremendous plugin that always fails!"
command: "false"
3 changes: 3 additions & 0 deletions test/testdata/plugin/plugins/get/plugin.yaml
@@ -0,0 +1,3 @@
name: "get"
shortDesc: "The wonderful new plugin-based get!"
command: "echo new-get"
2 changes: 2 additions & 0 deletions test/testdata/plugin/plugins/incomplete/plugin.yaml
@@ -0,0 +1,2 @@
name: "incomplete"
shortDesc: "Incomplete plugin"
13 changes: 13 additions & 0 deletions test/testdata/plugin/plugins/tree/plugin.yaml
@@ -0,0 +1,13 @@
name: "tree"
shortDesc: "Plugin with a tree of commands"
tree:
- name: "child1"
shortDesc: "The first child of a tree"
command: echo child one
- name: "child2"
shortDesc: "The second child of a tree"
command: echo child two
- name: "child3"
shortDesc: "The third child of a tree"
command: echo child three

19 changes: 19 additions & 0 deletions test/testdata/plugin/plugins2/hello/hello.sh
@@ -0,0 +1,19 @@
#!/bin/bash

# Copyright 2017 The Kubernetes 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.

echo "#######"
echo "#hello#"
echo "#######"
7 changes: 7 additions & 0 deletions test/testdata/plugin/plugins2/hello/plugin.yaml
@@ -0,0 +1,7 @@
name: hello
shortDesc: "The hello plugin"
longDesc: >
The hello plugin is a new
plugin used by test-cmd
to test multiple plugin locations.
command: ./hello.sh

0 comments on commit 34b3f36

Please sign in to comment.