-
Notifications
You must be signed in to change notification settings - Fork 0
Posixtests #2
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
base: gemini
Are you sure you want to change the base?
Posixtests #2
Conversation
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.
Hello @phbnf, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request introduces several changes to the internal/scti/handlers_test.go
file, primarily focusing on refactoring the testing setup and adding a new test case for the get-roots
endpoint. It replaces the previous mock-based testing approach with a more integrated approach using a POSIX backend for the TesseraCT log. Additionally, a new issuer storage implementation based on the POSIX filesystem is introduced in internal/testonly/storage/posix/issuers.go
and internal/testonly/storage/posix/issuers_test.go
. The changes also involve updating the test functions to use the new testing setup and removing some unnecessary code.
Highlights
- Refactor Testing Setup: The pull request refactors the testing setup in
internal/scti/handlers_test.go
by replacing the mock-based approach with a more integrated approach using a POSIX backend for the TesseraCT log. This involves creating asetupTestLog
function to create a test TesseraCT log using a POSIX backend, and asetupTestServer
function to create a test server with a specified endpoint. - Add GetRoots Test Case: A new test case,
TestGetRoots
, is added tointernal/scti/handlers_test.go
to verify the functionality of theget-roots
endpoint. This test case sets up a test server, makes a GET request to the endpoint, and verifies the response status code and content. - Introduce POSIX Issuer Storage: The pull request introduces a new issuer storage implementation based on the POSIX filesystem in
internal/testonly/storage/posix/issuers.go
andinternal/testonly/storage/posix/issuers_test.go
. This implementation provides a way to store and retrieve issuer certificates using the local filesystem. - Update Test Functions: The test functions in
internal/scti/handlers_test.go
are updated to use the new testing setup and the POSIX backend. This involves removing the mock-related code and updating the test assertions to reflect the new testing environment. - Remove Unnecessary Code: The pull request removes some unnecessary code from
internal/scti/handlers_test.go
, such as thehandlerTestInfo
struct, thefixedTimeSource
struct, and some unused variables.
Changelog
Click here to see the changelog
- internal/scti/handlers_test.go
- Refactors testing setup to use POSIX backend instead of mocks.
- Adds
TestGetRoots
test case for theget-roots
endpoint. - Updates test functions to use the new testing setup.
- Removes unnecessary code and variables.
- Removes dependency on
github.com/golang/mock/gomock
andgoogle.golang.org/grpc/*
- internal/testonly/storage/posix/issuers.go
- Introduces a new issuer storage implementation based on the POSIX filesystem.
- Implements the
AddIssuersIfNotExist
method to store issuer certificates.
- internal/testonly/storage/posix/issuers_test.go
- Adds tests for the POSIX issuer storage implementation.
- Tests the
NewIssuerStorage
,keyToObjName
, andAddIssuersIfNotExist
methods.
- internal/types/rfc6962.go
- Adds
GetRootsResponse
struct to represent the JSON response to the get-roots GET method.
- Adds
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
In halls of code, where tests reside,
Mocks fade, POSIX takes the stride.
Roots sought, servers rise,
A new test paradigm applies.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
The pull request introduces POSIX tests for the static-ct project, enhancing the testing infrastructure by incorporating a POSIX backend for TesseraCT log and issuer storage. The changes include refactoring existing test setups, adding new test functions, and integrating POSIX storage functionalities. Overall, the changes seem well-structured and contribute positively to the project's robustness.
Summary of Findings
- Removal of mock objects: The removal of mock objects and the introduction of real POSIX-based storage for testing is a significant change. While it improves the fidelity of the tests, it's crucial to ensure that the POSIX storage is properly cleaned up and doesn't leave any lingering state that could affect other tests.
- TODO comments: There are a few TODO comments in the code, specifically regarding additional options for
tessera.NewAppendOptions()
and aparseBodyJSONChain
test. Addressing these would improve the completeness and maintainability of the code. - Test Coverage: While the changes introduce new tests, it's important to ensure that all critical code paths are covered, especially those related to error handling and edge cases in the POSIX storage implementation.
Merge Readiness
The pull request introduces significant improvements to the testing infrastructure by integrating POSIX-based storage. However, there are a few issues that should be addressed before merging. Specifically, the TODO comments should be resolved, and test coverage should be thoroughly reviewed to ensure all critical code paths are covered. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging. Given the medium
severity comments, I recommend that the pull request not be merged until those are addressed (at a minimum).
// TODO(phboneff): add other options like MaxBatchSize of 1 when implementing | ||
// additional tests |
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.
Consider adding other options like MaxBatchSize
of 1 when implementing additional tests.
// TODO(phboneff): add other options like MaxBatchSize of 1 when implementing | |
// additional tests | |
// TODO(phboneff): add other options like MaxBatchSize of 1 when implementing | |
// additional tests |
98f0e28
to
25d3ff2
Compare
# Conflicts: # internal/scti/handlers_test.go
# Conflicts: # internal/scti/handlers_test.go # Conflicts: # internal/scti/handlers_test.go
# Conflicts: # internal/scti/handlers_test.go # Conflicts: # internal/scti/handlers_test.go # Conflicts: # internal/scti/handlers_test.go
# Conflicts: # internal/scti/handlers_test.go
# Conflicts: # internal/scti/handlers_test.go
/gemini review |
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.
Code Review
The pull request introduces several changes to the handlers_test.go file, including refactoring test setup, adding tests for get-roots, add-chain, and add-pre-chain endpoints, and updating dependencies. The new tests use a POSIX backend for the TesseraCT log. Overall, the changes seem to improve the test coverage and clarity of the scti package.
Summary of Findings
- Missing error check: In
TestAddChain
andTestAddPreChain
, the error returned byhttp.Post
is not checked before accessing theresp.StatusCode
. This could lead to a panic if the request fails andresp
is nil. - Inconsistent path joining: In
TestGetRoots
,TestAddChainWhitespace
,TestAddChain
, andTestAddPreChain
, the path is joined usingpath.Join
and then concatenated with/ct/v1/...
. This is redundant and can be simplified. - TODO comments: There are several TODO comments in
TestAddChain
andTestAddPreChain
that indicate missing test cases or functionality. These should be addressed to ensure complete test coverage. - Removal of mock-based tests: The removal of mock-based tests and introduction of POSIX backend tests is a good step towards integration tests, but it's important to ensure that the new tests cover all the scenarios previously covered by the mock tests.
Merge Readiness
The pull request introduces significant improvements to the test suite. However, the missing error check in TestAddChain
and TestAddPreChain
is a critical issue that must be addressed before merging. Additionally, the TODO comments indicate incomplete test coverage, which should be improved before merging. I am unable to directly approve this pull request, and users should have others review and approve this code before merging. I recommend addressing the critical issue and the TODO comments before merging.
internal/scti/handlers_test.go
Outdated
t.Fatalf("%q path not registered", types.AddChainStr) | ||
} | ||
req, err := http.NewRequest(http.MethodPost, "http://example.com/ct/v1/add-chain", strings.NewReader(test.body)) | ||
resp, err := http.Post(server.URL+"/ct/v1/add-chain", "application/json", strings.NewReader(test.body)) |
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 error returned by http.Post
is not checked before accessing resp.StatusCode
. This could lead to a panic if the request fails and resp
is nil. It's important to handle potential errors to ensure the stability of the test.
resp, err := http.Post(server.URL+"/ct/v1/add-chain", "application/json", strings.NewReader(test.body)) | |
resp, err := http.Post(server.URL+"/ct/v1/add-chain", "application/json", strings.NewReader(test.body)) | |
if err != nil { | |
t.Fatalf("http.Post(%s)=(_,%q); want (_,nil)", types.AddChainPath, err) | |
} |
internal/scti/handlers_test.go
Outdated
recorder := makeAddChainRequest(t, info.handlers, chain) | ||
if recorder.Code != test.want { | ||
t.Fatalf("addChain()=%d (body:%v); want %dv", recorder.Code, recorder.Body, test.want) | ||
resp, err := http.Post(server.URL+"/ct/v1/add-chain", "application/json", chain) |
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 error returned by http.Post
is not checked before accessing resp.StatusCode
. This could lead to a panic if the request fails and resp
is nil. It's important to handle potential errors to ensure the stability of the test.
resp, err := http.Post(server.URL+"/ct/v1/add-chain", "application/json", chain) | |
resp, err := http.Post(server.URL+"/ct/v1/add-chain", "application/json", chain) | |
if err != nil { | |
t.Fatalf("http.Post(%s)=(_,%q); want (_,nil)", types.AddChainPath, err) | |
} |
internal/scti/handlers_test.go
Outdated
recorder := makeAddPrechainRequest(t, info.handlers, chain) | ||
if recorder.Code != test.want { | ||
t.Fatalf("addPrechain()=%d (body:%v); want %d", recorder.Code, recorder.Body, test.want) | ||
resp, err := http.Post(server.URL+"/ct/v1/add-pre-chain", "application/json", chain) |
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 error returned by http.Post
is not checked before accessing resp.StatusCode
. This could lead to a panic if the request fails and resp
is nil. It's important to handle potential errors to ensure the stability of the test.
resp, err := http.Post(server.URL+"/ct/v1/add-pre-chain", "application/json", chain) | |
resp, err := http.Post(server.URL+"/ct/v1/add-pre-chain", "application/json", chain) | |
if err != nil { | |
t.Fatalf("http.Post(%s)=(_,%q); want (_,nil)", types.AddPreChainPath, err) | |
} |
internal/scti/handlers_test.go
Outdated
t.Fatalf("%q path not registered", types.AddChainStr) | ||
} | ||
req, err := http.NewRequest(http.MethodPost, "http://example.com/ct/v1/add-chain", strings.NewReader(test.body)) | ||
resp, err := http.Post(server.URL+"/ct/v1/add-chain", "application/json", strings.NewReader(test.body)) |
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 path is joined using path.Join
and then concatenated with /ct/v1/...
. This is redundant and can be simplified by directly using the server.URL
which already contains the base path.
resp, err := http.Post(server.URL+"/ct/v1/add-chain", "application/json", strings.NewReader(test.body)) | |
resp, err := http.Post(server.URL, "application/json", strings.NewReader(test.body)) |
internal/scti/handlers_test.go
Outdated
// TODO(phboneff): read from the log and compare values | ||
// TODO(phboneff): add a test with a backend write failure | ||
// TODO(phboneff): check that the index is in the SCT | ||
// TODO(phboneff): add a test with a not after range | ||
// TODO(phboneff): add a test with a start date only | ||
// TODO(phboneff): add duplicate tests |
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.
internal/scti/handlers_test.go
Outdated
recorder := makeAddChainRequest(t, info.handlers, chain) | ||
if recorder.Code != test.want { | ||
t.Fatalf("addChain()=%d (body:%v); want %dv", recorder.Code, recorder.Body, test.want) | ||
resp, err := http.Post(server.URL+"/ct/v1/add-chain", "application/json", chain) |
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 path is joined using path.Join
and then concatenated with /ct/v1/...
. This is redundant and can be simplified by directly using the server.URL
which already contains the base path.
resp, err := http.Post(server.URL+"/ct/v1/add-chain", "application/json", chain) | |
resp, err := http.Post(server.URL, "application/json", chain) |
internal/scti/handlers_test.go
Outdated
// TODO(phboneff): read from the log and compare values | ||
// TODO(phboneff): add a test with a backend write failure | ||
// TODO(phboneff): check that the index is in the SCT | ||
// TODO(phboneff): add a test with a not after range | ||
// TODO(phboneff): add a test with a start date only | ||
// TODO(phboneff): add duplicate tests |
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.
internal/scti/handlers_test.go
Outdated
recorder := makeAddPrechainRequest(t, info.handlers, chain) | ||
if recorder.Code != test.want { | ||
t.Fatalf("addPrechain()=%d (body:%v); want %d", recorder.Code, recorder.Body, test.want) | ||
resp, err := http.Post(server.URL+"/ct/v1/add-pre-chain", "application/json", chain) |
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 path is joined using path.Join
and then concatenated with /ct/v1/...
. This is redundant and can be simplified by directly using the server.URL
which already contains the base path.
resp, err := http.Post(server.URL+"/ct/v1/add-pre-chain", "application/json", chain) | |
resp, err := http.Post(server.URL, "application/json", chain) |
031df30
to
2dde1f2
Compare
a0eb3d2
to
a64805e
Compare
No description provided.