-
Notifications
You must be signed in to change notification settings - Fork 0
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
Use new API endpoint to fetch and create the test plan #63
Use new API endpoint to fetch and create the test plan #63
Conversation
2953f2f
to
411d14d
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.
Nice work! I just left a couple of questions.
Also wondering if we need the foo_spec.rb for this PR?
9df9fbc
to
9c2bf3d
Compare
| `BUILDKITE_SPLITTER_TEST_FILE_PATTERN` | `spec/**/*_spec.rb` | Optional, glob pattern for discovering test files that need to be executed. </br> *It accepts pattern syntax supported by [zzglob](https://github.com/DrJosh9000/zzglob?tab=readme-ov-file#pattern-syntax) library*. | | ||
| `BUILDKITE_SPLITTER_TEST_FILE_EXCLUDE_PATTERN` | - | Optional, glob pattern to use for excluding test files or directory. </br> *It accepts pattern syntax supported by [zzglob](https://github.com/DrJosh9000/zzglob?tab=readme-ov-file#pattern-syntax) library.* | | ||
| `BUILDKITE_SPLITTER_SUITE_SLUG` | - | Required, the slug of your test suite. | | ||
| `BUILDKITE_TEST_SPLITTER_CMD` | `bundle exec rspec {{testExamples}}` | Optional, test command for running your tests. Test splitter will fill in the `{{testExamples}}` placeholder with the test splitting results | | ||
|
||
For most use cases, Test Splitter should work out of the box due to the default values available from your Buildkite environment. |
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 don't think the authentication settings below this are valid any more, is that correct?
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.
Good catch! I have updated the readme, but don't want to change it too much for now. What do you think?
internal/api/fetch_test_plan.go
Outdated
switch { | ||
case resp.StatusCode == http.StatusOK: | ||
// happy path | ||
case resp.StatusCode >= 400 && resp.StatusCode <= 403: | ||
// treat 400-403 as an error because the request is invalid | ||
responseBody, _ := io.ReadAll(resp.Body) | ||
var errorResp errorResponse | ||
json.Unmarshal(responseBody, &errorResp) | ||
return nil, fmt.Errorf(errorResp.Message) | ||
default: | ||
// ignore other errors and treat them as cache miss | ||
return nil, nil | ||
} |
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.
@wooly @niceking I'm ignoring server error, except for 400 ~ 403, so the client can proceed and attempt to make POST request. Do you think this make sense? Or should we implement a retry mechanism for this as well?
The reason behind handling 400 ~ 403 is that we want to terminate the program if there is bad request (miss config), unauthorized, or not permitted (token doesn't have required scope)
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 haven't fully thought through the implications of falling back to cache-miss yet, but it probably makes sense to document the individual status codes that we respond to in the splitter and what they mean. At least to have as a point of reference, even if the code groups them all together.
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.
Good suggestion. I have improve the readability and the test. Let me know what you think.
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.
@nprizal and I reviewed the changes in this PR at today's team time. The changes look good to me
9c2bf3d
to
a5bd853
Compare
Removing the DO NOT MERGE tag from this as it's now suitable to be merged into the |
These changes introduced 3 required configs
BUILDKITE_API_ACCESS_TOKEN
. You now need Buildkite API access token that hasread_suites
,read_test_plan
, andwrite_test_plan
scopes.BUILDKITE_ORGANIZATION_SLUG
. This is available in your Buildkite Pipeline environment, so you don't need to set it manually.BUILDKITE_SPLITTER_SUITE_SLUG
. This replacesBUILDKITE_SPLITTER_SUITE_TOKEN
and need to be set manually.Description
As part of split by example implementation, we want to change how the client fetch and create test plan from the server. The new flow will look like this
This PR also replaced the endpoint to the new endpoint.
Changes
httpClient
toapi.client
struct that has Transport to attach access token to each requestFetchTestPlan
in theapi.client
structCreateTestPlan
to the new endpointBUILDKITE_SPLITTER_SUITE_TOKEN
from configTesting
As this is a breaking change, I suggest testing it manually against a local Buildkite server (or Prod). I tested it manually against my local Buildkite server.