Comments (18)
I think this now can be closed. Thanks a lot @feloy and @doodlesbykumbi.
from kubectx.
I would be happy to try and work at this
from kubectx.
@doodlesbykumbi probably the kubectl command only, outputting a list of namespaces ("kubectl get namespaces" seems to be the only command used)
from kubectx.
@feloy @ahmetb here's my attempt #117
from kubectx.
@feloy sounds great!
I've developed CLI tests with bats some time ago at https://github.com/Azure/run-command-extension-linux/tree/master/integration-test/test, so my knowledge is limited.
Please feel free to fork & set up travis on your own fork to iterate, happy to answer any questions!
from kubectx.
Also if you have a test plan (i.e. test cases you're planning to cover), please summarize here to discuss.
from kubectx.
Feel free to edit this
Test framework
- Based on bats
- Runs in Travis CI
Test plan
It looks like @feloy has covered some of these but based on the help text of kubectx
:
Public interface TCs
- no kubectl detected (non-zero exitcode)
- list the contexts
- list the contexts when no kubeconfig exists
- switch to context
- switch to the previous context
- switch to the previous context, but there's no previous context
- switch to non-existing context (non-zero exitcode)
- rename context
- rename current-context
- delete context
- delete current-context
- delete non-existing context
- help
kubens
:
- TODO ADD MORE HERE
- fails to retrieve list of namespaces (non-zero exitcode)
Unit TCs
- Enumerate all the functions in ./kubectx
from kubectx.
I edited a bit. I think you entirely omitted the kubens, so if you can fill out that would be great!
Here's the kinds of things I added (mostly negative/edge cases):
- no kubectl detected (non-zero exitcode)
- list the contexts when no kubeconfig exists
- switch to the previous context, but there's no previous context
- delete non-existing context
- switch to non-existing context (non-zero exitcode)
- fails to retrieve list of namespaces (non-zero exitcode) (for
kubens
)
I hope this gives a good idea about what I'm mainly looking for.
from kubectx.
Hi @ahmetb @doodlesbykumbi
This test plan sounds good to me.
About unit-testing the internal functions of kubectx and kubens, a problem is that the test script won't be able to source the kubectx/kubens scripts (to get the functions definitions) without executing the main part. A solution would be to cut these scripts to have a library one and a main one, but I'm not sure that would be a good experience for the user: having, as today, a single file for each command is very convenient
from kubectx.
@doodlesbykumbi on which tests do you prefer to work?
If you agree, you could work on the positive tests cases you listed in the plan, and I work on the negative/edge cases ones that Ahmet added.
from kubectx.
Let's set up the test infra first:
- can you create a PR with a test/ dir, with one or two simple tests?
- "kubectx -h" doesn't fail
- "kubens -h" doesn't fail
- I'll create a PR adding travis CI with bats.
a problem is that the test script won't be able to source the kubectx/kubens scripts
I'm not interested in unit-testing methods but rather the CLI tool itself. (I'll change the issue title.) So we should just invoke ../kubectx in the test.
from kubectx.
@ahmetb ok, i'll create aPR with 2 simple tests for kubectx / kubens
from kubectx.
BTW I looked at bats, last time I used it was around 2016. Around that time it was semi-maintained. Looks like it's entirely abandoned for now (last commit in 2016 and last release in 2014).
If you know more interesting alternatives, I'd love to consider those before going all in on bats.
from kubectx.
For studying how to write tests with bats, I have the following lengthy files still used after many years:
- https://github.com/Azure/custom-script-extension-linux/blob/master/integration-test/test/handler-commands.bats
- https://github.com/Azure/custom-script-extension-linux/blob/master/integration-test/test/basic.bats
One big recommendation is to do echo "$output"
after each cmd before testing anything –otherwise it'll just say test failed with no other indicator (like output) of failure. (If test doesn't fail, echo is suppressed.)
from kubectx.
As of #113 we now have 17 tests for kubectx
, which is a good place to begin. I intend to go through the code some time and see if we can add more around the "edge cases".
It's a good time to begin working on kubens
tests. It can be started by copy-pasting from the existing tests and modifying them.
from kubectx.
Happy to have a go at kubens :) Should have a PR in a couple hours
from kubectx.
Well, here's a wall. We'd need to mock the Kubernetes API to carry out any non-trivial tests :(
from kubectx.
Well, here's a wall. We'd need to mock the Kubernetes API to carry out any non-trivial tests :(
Saw that coming!
I think we will need to override the $KUBECTL variable from the environment, then we can write a small bash script named mock-kubectl for the parts we need.
This part will need refactoring to use the $KUBECTL if it exists in the environment.
Lines 176 to 183 in df557e4
from kubectx.
Related Issues (20)
- Are go versions still considered not stable? HOT 2
- kubie and kubens mixed cause kubeconfig syntax error HOT 12
- Can’t use `--height` in fzf options on Windows HOT 2
- blank issue HOT 1
- Add --selector option to kubens HOT 1
- Feature Request: Use kubectx to use right version of kubectl binary for a given K8s cluster HOT 1
- `kubens` fails with `invalid apiVersion "client.authentication.k8s.io/v1"` but `kubectl` works normally HOT 2
- Vulnerability of dependency "golang.org/x/net" HOT 1
- Add completions for Nushell
- Add kubectl plugin installation to Homebrew formula HOT 4
- [Go] kubens not working with in-cluster config HOT 1
- show all of NAME, CLUSTER and AUTHINFO in cluster selection list HOT 2
- Allow customizing path to KUBECTX and KUBENS_DIR
- Homebrew install makes kubectx slow HOT 6
- Shell completions (for zsh) fail for kubectx if its binary is renamed to kx HOT 1
- Autocomplete does not work when installed as Krew plugin HOT 2
- Autocomplete breaks when multiple longer contexts match HOT 2
- kubectl ctx outputs code lines start with plus sign + HOT 1
- error: open /home/myuser/.kube/config: permission denied HOT 1
- Consider open up internal packages HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kubectx.