Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing #46

Closed
errordeveloper opened this issue Jun 6, 2018 · 25 comments
Closed

Testing #46

errordeveloper opened this issue Jun 6, 2018 · 25 comments
Labels
help wanted Extra attention is needed kind/bug

Comments

@errordeveloper
Copy link
Contributor

We could probably add some unit tests, but the critical code path is reliant on AWS APIs and mocking CloudFormation is going to involve a lot of effort due to its complex nature (unless there is something ready-made we can use). Also, we would also need to mock Kubernetes somehow, there is probably prior art, but that could be very specialised. Personally, I feel that integration test is what we need the most.

@errordeveloper errordeveloper added bug help wanted Extra attention is needed labels Jun 6, 2018
@errordeveloper
Copy link
Contributor Author

We might want to start on this before 0.1.0, but I wouldn't block 0.1.0 on lack of automated testing, unless others strongly object.

@Raffo
Copy link

Raffo commented Jun 17, 2018

I was having a look at the code today and I totally recommend having having a proper testing strategy in place before implementing other major features. I guess 0.1.0 can be released, but I would give priority to this before any other major changes.
There is a bunch that can be done even with the AWS SDK and even if you are using CloudFormation, we can test things like, for example, the use of the returned values (by mocking of course) and the other part of the code that call CF (i.e. the code that waits on the stack). That would help at least to figure in a better way if the code is well structured in terms of how the function are divided. IMO it is simple enough till now and that would be a pretty good investment if done right now.

I agree in also putting some focus on integration testing, if someone is sponsoring an AWS account for such tests it wouldn't be so hard to setup.

Please note that is only my opinion 😄

@richardcase
Copy link
Contributor

@errordeveloper - happy to look at this if you want?

@Raffo
Copy link

Raffo commented Jun 22, 2018

Happy to help with the review @richardcase 😉

@errordeveloper
Copy link
Contributor Author

errordeveloper commented Jun 22, 2018 via email

@Raffo
Copy link

Raffo commented Jun 23, 2018

Sounds good to me.

@richardcase what's your plan for that?

@richardcase
Copy link
Contributor

@Raffo - i will have a look and come up with a plan.

There are things like localstack and also the Go SDK has interfaces for the services to help build mocks, like this for CloudFormation (i haven't checked interfaces for the other dependent services like STS).

@Raffo
Copy link

Raffo commented Jun 26, 2018

I think the approach with interfaces would be good and that's what I've used in the past. We've used a similar approach while implementing testing for external DNS here: https://github.com/kubernetes-incubator/external-dns/blob/master/provider/aws.go#L79

richardcase added a commit to richardcase/eksctl that referenced this issue Jul 1, 2018
Changed `providerServices` to use the AWS service interfaces instead
of the service structs directly. This is an initial change to help with
implementing testing in the future.

Issue eksctl-io#46
@richardcase
Copy link
Contributor

@Raffo @errordeveloper - what about the following initially:

  • Add tests to each of the packages (like we've done with the kubeconfig change). The decision here is whether the tests for a package are contained within the package and have access to all the non-exported functions/structs/etc or if instead the tests site in a test package and test only via the exported functions/structs/etc (seeing only what the user of the package would see). I used the later for the kubeconfig tests.
  • We can mock the AWS services using the interfaces and inject these mocks where required for the unit tests (this may require some refactoring).
  • We create a separate integration test suite that tests against AWS (when we've worked out who can pay/sponsor). I quite like how minikube have done this. We'd have to perform operations with eksctl and then check its done what we expected using the AWS sdk directly (or something else).
  • Start with the get command
  • Add code coverage output

So just standard testing.

@Raffo
Copy link

Raffo commented Jul 6, 2018

I really like the plan 👍

I'd start with the basic unit testing inside the individual packages as this can guide some early refactoring of the code. I also totally agree with using the AWS service mocking for that as it should be just what we need for that job.

Absolutely let's have the coverage easy visible for contributors such that we makes sure that future contributors can also provide adeguate tests.

I would give the integration testing to a later step once we have the steps above done, but it's absolutely also very important.

EDIT: Additionally, do you feel okay with getting started with that or do you want me to take over a part of it? WDYT?

@errordeveloper
Copy link
Contributor Author

errordeveloper commented Jul 9, 2018

I would start by finding out what it takes to mock CloudFormation, as to me it seem kind of complex, but may I just don't know. In my mind integration tests (besides the question of who gets the bill) would buy as more for much less code, testing different code-path maybe be tricky, but starting by simply testing eksctl create cluster seems plausible to me. If you folks are quite comfortable with mocking CloudFormation, I won't oppose at all. Right now, I am just unable to imagine how it would work (seems like it would be a lot of code)...

@richardcase
Copy link
Contributor

richardcase commented Jul 13, 2018

I've started to look at this and using mockery to mock the AWS services. I've one test working now, not a lot i know but just to prove that the approach works.

You can see the WIP on the PR.

@Raffo
Copy link

Raffo commented Jul 21, 2018

Nice that the first tests are now merged. Now that we have a base for the tests in place we can probably go in parallel and add more.

@richardcase
Copy link
Contributor

I'll look at adding a base integration test now.

@errordeveloper errordeveloper added this to the 0.1.x – improvements milestone Jul 23, 2018
@errordeveloper
Copy link
Contributor Author

errordeveloper commented Aug 3, 2018

@richardcase should we make integration tests a requirement for one of the next patch releases?

Manual test would be okay for now, as long as it's well defined (not just "create a cluster and deploy some app, then check it works, run e2e suite if in doubt").

We might want to look into running conformance suite, but I think deploying some workloads would be just fine for now. My colleague @dlespiau wrote a very nice and simple library that should help with this, we are using it in a few projects already.

I think eventually it'd be nice to allow users to easily validate their clusters, so something like

eksctl validate [--workload-test] [--kubernetes-conformance-test] [--full-kubernetes-e2e-test] [--node-problem-detector]

should probably become a thing eventually, especially when we are gonna allow custom node AMIs etc.

@richardcase
Copy link
Contributor

should we make integration tests a requirement for one of the next patch releases?

Yes i think we should. I'll take a look at this next and will look at the package by @dlespiau. Also, what minikube do is quite good.

I really like the idea of validating clusters using eksctl and think this could come after the initial integration tests.

@richardcase
Copy link
Contributor

@errordeveloper - i've started work on the integration tests. Are you happy for us to use this issue or do we want a separate one for integration tests?

@errordeveloper
Copy link
Contributor Author

errordeveloper commented Aug 6, 2018 via email

richardcase added a commit to richardcase/eksctl that referenced this issue Aug 9, 2018
Added code coverage to the tests and setup coveralls to track the
coverage over time.

Issue eksctl-io#46

Signed-off-by: Richard Case <[email protected]>
@richardcase richardcase added kind/bug and removed p1 labels Aug 16, 2018
@richardcase
Copy link
Contributor

@errordeveloper - do you think we can close this now we have #151 for the integration tests?

@errordeveloper
Copy link
Contributor Author

@richardcase yes, but before we close this, I think it'd make sense to open another set a goal post for coverage - wdyt?

@richardcase
Copy link
Contributor

Sure. And this would be a coverage target for the unit tests only and it will not include the integration tests? If thats the case what do you think to 90% coverage?

@errordeveloper
Copy link
Contributor Author

errordeveloper commented Aug 17, 2018

I'd guess we start with unit tests for now. Integration coverage is harder to grasp, as you have to think of various flag combos, so I'm not sure how we would make that work in a way that doesn't require creating dozens of clusters...

90% could be a good one to aim for, but I'd also define a lower band (60%-70%?) that's more realistic near-term. So I guess 2 separate issues...

@richardcase
Copy link
Contributor

Closing this issus as we have defined the testing strategy and have started to add tests. We now have new issues to improve various aspects:

@Raffo
Copy link

Raffo commented Aug 20, 2018

We probably don't need to achieve 90% or a specific number, but I believe we should keep track of the coverage anyways as it is a good indication of where the efforts should go.

@richardcase
Copy link
Contributor

I agree. I have removed the 90% target issue and changed the other one to be more generic (#166). We can track coverage with coveralls.

torredil pushed a commit to torredil/eksctl that referenced this issue May 20, 2022
Disable build for go master branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed kind/bug
Projects
None yet
Development

No branches or pull requests

3 participants