Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

feat: api schema tests #168

Merged
merged 3 commits into from
Oct 19, 2023
Merged

feat: api schema tests #168

merged 3 commits into from
Oct 19, 2023

Conversation

elijaharita
Copy link
Contributor

@elijaharita elijaharita commented Oct 18, 2023

closes #28

the test runs through an array of test cases for each endpoint, method, and status code. the test reads openapi.yaml and validates that all possible endpoint/method/status combination is covered, otherwise it will not pass.

writing the tests helped catch 1 bug - an anonymous error was returned instead of blob.ErrBlobNotFound on the Singularity Describe() implementation when an unknown ID was provided

@codecov-commenter
Copy link

codecov-commenter commented Oct 18, 2023

Codecov Report

Merging #168 (7cf3357) into main (7230d07) will increase coverage by 0.67%.
Report is 2 commits behind head on main.
The diff coverage is 0.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #168      +/-   ##
==========================================
+ Coverage   30.82%   31.49%   +0.67%     
==========================================
  Files           5        5              
  Lines         743      743              
==========================================
+ Hits          229      234       +5     
+ Misses        479      474       -5     
  Partials       35       35              
Files Coverage Δ
integration/singularity/store.go 36.36% <0.00%> (+1.08%) ⬆️

@elijaharita elijaharita changed the title feat: api schema tests (wip) feat: api schema tests Oct 18, 2023
@elijaharita elijaharita marked this pull request as ready for review October 18, 2023 23:10
resp.Body.Close()

// Status code must be as expected
require.Equal(t, test.expectStatus, resp.StatusCode, "Incorrect status code for test %#v (resp body: %v)", test, body)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend using
https://github.com/parnurzeal/gorequest
to simplify above code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid extra dependencies if we can help it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoiding extra dependencies was my thinking while writing this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think such dependency would greatly reduce the LOC for testing, plus, it won't be built into the binary.

}

// Find matching schema case and mark as covered
for i := range schemaCases {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do it differently

  1. use client generation tool such as github.com/deepmap/oapi-codegen to generate the client code, this also validates the yaml file against openapi spec
  2. Since we only have 3 APIs, it maybe overkill to check all API paths are covered so I would just rely on code coverage tool.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re 1. Do you think it's worth the increase in LOC? No one is asking for http client library for such simple api (yet) right?

Re 2. Either works. Considering the work is done already, and we want to focus on e2e tests first/more than vide coverage would it make sense to revisit this at later date and leave it as is for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

considering that everything works right now, and the code does and will continue to do its job for now, i'd say we can look at codegen client / coverage as a followup, as they are more heavy commitments compared to what i wrote so far

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good

@elijaharita elijaharita merged commit 2554da7 into main Oct 19, 2023
7 checks passed
@elijaharita elijaharita deleted the feat/api-schema-tests branch October 19, 2023 20:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add REST API tests
4 participants