-
Notifications
You must be signed in to change notification settings - Fork 90
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
Setup integration tests #619
base: main
Are you sure you want to change the base?
Setup integration tests #619
Conversation
Without this we can't create a token configuration from outside the crate. Signed-off-by: Tobin Feldman-Fitzthum <[email protected]>
@@ -129,6 +129,51 @@ impl ApiServer { | |||
.await | |||
.map_err(|e| Error::HTTPFailed { source: e.into() }) | |||
} | |||
|
|||
/// Setup API server | |||
pub fn server(self) -> Result<actix_web::dev::Server> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems to share a lot of logic with serve()
in the same file, can we share the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I don't like this duplication. I tried a bunch of things to reduce it but I could not get any of them to work. The actix crate is a bit fiddly. For instance I tried having just one function with a flag, but that doesn't work since the function needs to be async in one case but not in the other. Then I tried making serve
a wrapper of server
. I thought I could just return the actix HttpServer
from server
and then run it either in the test or in serve
. This didn't work for reasons that are sort of hard to describe quickly. Anyway I ran out of ideas here (I'll skip over my other, worse, attempts), but if anyone else has any I would like to avoid duplicating this. Maybe we could get rid of one if we reworked the kbs.rs
binary main.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I tried a bunch more things and I finally have something that seems to work and avoids the duplication. PTAL
Looks great! One question before getting into the code: why not we directly have an A quick glance is that way we need to add This way, we could avoid another sub crate. |
I think this would work. I see the integration tests as having a broader scope than just the KBS, so I made a new package, but if that adds overhead I could move it. Generally I think that since the repo merge, we've had some stuff in individual packages that should really be in the top of the repo (like configs and docs, perhaps). |
1adf56a
to
b311ab0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make sense to have a separate crate if we want to add more tests. One question is that we are having some e2e test
- docker-compose ci
- e2e test here
- this PR
Do we need to delete some duplicated ones?
allow = false | ||
"; | ||
|
||
#[allow(dead_code)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this lint macro?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Custom
and DenyAll
variants are never instantiated. I could move the dead code thing just to those variants but then I'd have to use it twice.
b311ab0
to
5d3767a
Compare
Since these integration tests use the crate directly, they don't test the binaries or the docker-compose configuration or the k8s configuration. I think it's fine to keep some simple tests around that make sure that those interfaces still work. We should do a little bit of cleanup and organization with our existing tests, but I think that's for another PR. |
669f8e6
to
75dee21
Compare
The existing serve function returns a future that must be awaited on for the server to run. This causes the caller to block and does not allow the server to be halted unless the process is terminated. This is not ideal when using the server as a crate (or in a test). Instead, add a function that returns a server which can then be awaited on or run in the background. Signed-off-by: Tobin Feldman-Fitzthum <[email protected]>
To support integration tests written in rust, let's add a new package (which will only be used internally) called integration-tests. Inside the package, we have a tests repo where we can put tests. The package imports other trustee packages using a local path, so it should always have the most recent version of things. Now integration tests will run simply by doing cargo test at the top of the repo. Signed-off-by: Tobin Feldman-Fitzthum <[email protected]>
Let the make check target (which maybe should be renamed?) also run the integration tests. Signed-off-by: Tobin Feldman-Fitzthum <[email protected]>
89754d0
to
fb4069f
Compare
The OPA linter seems to have updated and now complains if we don't use an if before our blocks. This is unrelated to the rest of this PR. Signed-off-by: Tobin Feldman-Fitzthum <[email protected]>
fb4069f
to
ce92336
Compare
Creates a framework for writing Trustee integration tests in Rust.
Put your tests in
integration-tests/tests/integration.rs
(or a similar file) and they will run when you docargo test
at the top level.I've added two simple integration tests. They aren't anything beyond what we already have in other tests, but they add a structure that should help us to create a lot more. Before I get too carried away, please take a look at the setup.
Note that running the KBS in the background was trickier than expected. I think I found a pretty good way to do it in the end.