Skip to content

Commit

Permalink
Feat: incorporated new spec.
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Kisler <[email protected]>
  • Loading branch information
kislerdm committed Mar 21, 2024
1 parent d2a2d9f commit b030423
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 296 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v0.4.8] - 2024-03-22

The release incorporates the up-to-date [API contract](openAPIDefinition.json) as of 2024-03-21 23:20:00 GMT.

### Added

- Added the method `GetConnectionURI` to retrieve the connection URI for the given role and database, see [details](https://api-docs.neon.tech/reference/getconnectionuri).
- The branch can be set as protected at creation, or update using the attribute `Protected`.

## [v0.4.7] - 2024-03-07

The release incorporates the up-to-date [API contract](openAPIDefinition.json) as of 2024-03-05 00:08:00 GMT.
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ build: ## Compiles the binary.
.PHONY: testacc
testacc: ## Runs smoke tests.
@ source .env && TF_ACC=1 go test acc_test.go

.PHONY: fetch-specs
fetch-specs: ## Downloads API specs.
@ curl -SLo openAPIDefinition_new.json https://neon.tech/api_spec/release/v2.json
3 changes: 2 additions & 1 deletion generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,8 @@ func (v field) routeElement(withPointer ...bool) string {
case "integer":
return "strconv.FormatInt(int64(" + r + "), 10)"
case "boolean":
return "func (" + r + ` bool) string { if r { return "true" }; return "false" } (` + r + ")"
varName := v.canonicalName()
return "func (" + varName + ` bool) string { if ` + varName + ` { return "true" }; return "false" } (` + r + ")"
}
return r
}
Expand Down
28 changes: 24 additions & 4 deletions generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,9 +777,10 @@ func Test_parameterPath_routeElement(t *testing.T) {
format string
}
tests := []struct {
name string
fields fields
want string
name string
fields fields
withPointer bool
want string
}{
{
name: "int64",
Expand Down Expand Up @@ -826,6 +827,25 @@ func Test_parameterPath_routeElement(t *testing.T) {
},
want: "quxID.Format(time.RFC3339)",
},
{
name: "boolean - pointer",
fields: fields{
k: "quxx_id",
v: "boolean",
format: "boolean",
},
withPointer: true,
want: `func (quxxID bool) string { if quxxID { return "true" }; return "false" } (*quxxID)`,
},
{
name: "boolean",
fields: fields{
k: "quxx_id",
v: "boolean",
format: "boolean",
},
want: `func (quxxID bool) string { if quxxID { return "true" }; return "false" } (quxxID)`,
},
}
for _, tt := range tests {
t.Run(
Expand All @@ -835,7 +855,7 @@ func Test_parameterPath_routeElement(t *testing.T) {
k: tt.fields.k,
v: tt.fields.v,
format: tt.fields.format,
}.routeElement(),
}.routeElement(tt.withPointer),
)
},
)
Expand Down
Empty file added go.sum
Empty file.
21 changes: 14 additions & 7 deletions mockhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ var endpointResponseExamples = map[string]map[string]mockResponse{

"/projects/{project_id}/branches": {
"GET": mockResponse{
Content: `{"branches":[{"active_time_seconds":100,"compute_time_seconds":100,"cpu_used_sec":100,"created_at":"2022-11-23T17:42:25Z","creation_source":"console","current_state":"ready","data_transfer_bytes":1000000,"id":"br-aged-salad-637688","logical_size":28,"name":"main","primary":true,"project_id":"shiny-wind-028834","updated_at":"2022-11-23T17:42:26Z","written_data_bytes":100800},{"active_time_seconds":100,"compute_time_seconds":100,"cpu_used_sec":100,"created_at":"2022-11-30T19:09:48Z","creation_source":"console","current_state":"ready","data_transfer_bytes":1000000,"id":"br-sweet-breeze-497520","logical_size":28,"name":"dev2","parent_id":"br-aged-salad-637688","parent_lsn":"0/1DE2850","primary":true,"project_id":"shiny-wind-028834","updated_at":"2022-11-30T19:09:49Z","written_data_bytes":100800},{"active_time_seconds":100,"compute_time_seconds":100,"cpu_used_sec":100,"created_at":"2022-11-30T17:36:57Z","creation_source":"console","current_state":"ready","data_transfer_bytes":1000000,"id":"br-raspy-hill-832856","logical_size":21,"name":"dev1","parent_id":"br-aged-salad-637688","parent_lsn":"0/19623D8","primary":true,"project_id":"shiny-wind-028834","updated_at":"2022-11-30T17:36:57Z","written_data_bytes":100800}]}`,
Content: `{"branches":[{"active_time_seconds":100,"compute_time_seconds":100,"cpu_used_sec":100,"created_at":"2022-11-23T17:42:25Z","creation_source":"console","current_state":"ready","data_transfer_bytes":1000000,"id":"br-aged-salad-637688","logical_size":28,"name":"main","primary":true,"project_id":"shiny-wind-028834","protected":false,"updated_at":"2022-11-23T17:42:26Z","written_data_bytes":100800},{"active_time_seconds":100,"compute_time_seconds":100,"cpu_used_sec":100,"created_at":"2022-11-30T19:09:48Z","creation_source":"console","current_state":"ready","data_transfer_bytes":1000000,"id":"br-sweet-breeze-497520","logical_size":28,"name":"dev2","parent_id":"br-aged-salad-637688","parent_lsn":"0/1DE2850","primary":true,"project_id":"shiny-wind-028834","protected":false,"updated_at":"2022-11-30T19:09:49Z","written_data_bytes":100800},{"active_time_seconds":100,"compute_time_seconds":100,"cpu_used_sec":100,"created_at":"2022-11-30T17:36:57Z","creation_source":"console","current_state":"ready","data_transfer_bytes":1000000,"id":"br-raspy-hill-832856","logical_size":21,"name":"dev1","parent_id":"br-aged-salad-637688","parent_lsn":"0/19623D8","primary":true,"project_id":"shiny-wind-028834","protected":false,"updated_at":"2022-11-30T17:36:57Z","written_data_bytes":100800}]}`,
Code: 200,
},
"POST": mockResponse{
Expand Down Expand Up @@ -252,15 +252,15 @@ var endpointResponseExamples = map[string]map[string]mockResponse{

"/projects/{project_id}/branches/{branch_id}": {
"DELETE": mockResponse{
Content: `{"branch":{"active_time_seconds":100,"compute_time_seconds":100,"cpu_used_sec":100,"created_at":"2022-11-23T17:42:25Z","creation_source":"console","current_state":"ready","data_transfer_bytes":1000000,"id":"br-aged-salad-637688","logical_size":28,"name":"main","primary":true,"project_id":"shiny-wind-028834","updated_at":"2022-11-23T17:42:26Z","written_data_bytes":100800},"operations":[{"action":"suspend_compute","branch_id":"br-sweet-breeze-497520","created_at":"2022-12-01T19:53:05Z","endpoint_id":"ep-soft-violet-752733","failures_count":0,"id":"b6afbc21-2990-4a76-980b-b57d8c2948f2","project_id":"shiny-wind-028834","status":"running","total_duration_ms":100,"updated_at":"2022-12-01T19:53:05Z"},{"action":"delete_timeline","branch_id":"br-sweet-breeze-497520","created_at":"2022-12-01T19:53:05Z","failures_count":0,"id":"b6afbc21-2990-4a76-980b-b57d8c2948f2","project_id":"shiny-wind-028834","status":"scheduling","total_duration_ms":100,"updated_at":"2022-12-01T19:53:05Z"}]}`,
Content: `{"branch":{"active_time_seconds":100,"compute_time_seconds":100,"cpu_used_sec":100,"created_at":"2022-11-23T17:42:25Z","creation_source":"console","current_state":"ready","data_transfer_bytes":1000000,"id":"br-aged-salad-637688","logical_size":28,"name":"main","primary":true,"project_id":"shiny-wind-028834","protected":false,"updated_at":"2022-11-23T17:42:26Z","written_data_bytes":100800},"operations":[{"action":"suspend_compute","branch_id":"br-sweet-breeze-497520","created_at":"2022-12-01T19:53:05Z","endpoint_id":"ep-soft-violet-752733","failures_count":0,"id":"b6afbc21-2990-4a76-980b-b57d8c2948f2","project_id":"shiny-wind-028834","status":"running","total_duration_ms":100,"updated_at":"2022-12-01T19:53:05Z"},{"action":"delete_timeline","branch_id":"br-sweet-breeze-497520","created_at":"2022-12-01T19:53:05Z","failures_count":0,"id":"b6afbc21-2990-4a76-980b-b57d8c2948f2","project_id":"shiny-wind-028834","status":"scheduling","total_duration_ms":100,"updated_at":"2022-12-01T19:53:05Z"}]}`,
Code: 200,
},
"GET": mockResponse{
Content: `{"branch":{"active_time_seconds":100,"compute_time_seconds":100,"cpu_used_sec":100,"created_at":"2022-11-23T17:42:25Z","creation_source":"console","current_state":"ready","data_transfer_bytes":1000000,"id":"br-aged-salad-637688","logical_size":28,"name":"main","primary":true,"project_id":"shiny-wind-028834","updated_at":"2022-11-23T17:42:26Z","written_data_bytes":100800}}`,
Content: `{"branch":{"active_time_seconds":100,"compute_time_seconds":100,"cpu_used_sec":100,"created_at":"2022-11-23T17:42:25Z","creation_source":"console","current_state":"ready","data_transfer_bytes":1000000,"id":"br-aged-salad-637688","logical_size":28,"name":"main","primary":true,"project_id":"shiny-wind-028834","protected":false,"updated_at":"2022-11-23T17:42:26Z","written_data_bytes":100800}}`,
Code: 200,
},
"PATCH": mockResponse{
Content: `{"branch":{"active_time_seconds":100,"compute_time_seconds":100,"cpu_used_sec":100,"created_at":"2022-11-23T17:42:25Z","creation_source":"console","current_state":"ready","data_transfer_bytes":1000000,"id":"br-icy-dream-250089","name":"mybranch","parent_id":"br-aged-salad-637688","parent_lsn":"0/1E19478","primary":true,"project_id":"shiny-wind-028834","updated_at":"2022-11-23T17:42:26Z","written_data_bytes":100800},"operations":[]}`,
Content: `{"branch":{"active_time_seconds":100,"compute_time_seconds":100,"cpu_used_sec":100,"created_at":"2022-11-23T17:42:25Z","creation_source":"console","current_state":"ready","data_transfer_bytes":1000000,"id":"br-icy-dream-250089","name":"mybranch","parent_id":"br-aged-salad-637688","parent_lsn":"0/1E19478","primary":true,"project_id":"shiny-wind-028834","protected":false,"updated_at":"2022-11-23T17:42:26Z","written_data_bytes":100800},"operations":[]}`,
Code: 200,
},
},
Expand Down Expand Up @@ -361,7 +361,14 @@ var endpointResponseExamples = map[string]map[string]mockResponse{

"/projects/{project_id}/branches/{branch_id}/set_as_primary": {
"POST": mockResponse{
Content: `{"branch":{"active_time_seconds":1,"compute_time_seconds":1,"cpu_used_sec":1,"created_at":"2022-11-23T17:42:25Z","creation_source":"console","current_state":"ready","data_transfer_bytes":100,"id":"br-icy-dream-250089","name":"mybranch","parent_id":"br-aged-salad-637688","parent_lsn":"0/1E19478","primary":true,"project_id":"shiny-wind-028834","updated_at":"2022-11-23T17:42:26Z","written_data_bytes":100},"operations":[]}`,
Content: `{"branch":{"active_time_seconds":1,"compute_time_seconds":1,"cpu_used_sec":1,"created_at":"2022-11-23T17:42:25Z","creation_source":"console","current_state":"ready","data_transfer_bytes":100,"id":"br-icy-dream-250089","name":"mybranch","parent_id":"br-aged-salad-637688","parent_lsn":"0/1E19478","primary":true,"project_id":"shiny-wind-028834","protected":false,"updated_at":"2022-11-23T17:42:26Z","written_data_bytes":100},"operations":[]}`,
Code: 200,
},
},

"/projects/{project_id}/connection_uri": {
"GET": mockResponse{
Content: `null`,
Code: 200,
},
},
Expand Down Expand Up @@ -494,8 +501,8 @@ var endpointResponseExamples = map[string]map[string]mockResponse{
// Mock client return the response as per API spec, except for the errors: 404 and 401 status codes are covered only.
// - 401 is returned when the string `invalidApiKey` is used as the API key;
// - 404 is returned if either of the following:
// - the string value `notFound` is used as the string argument, e.g. projectID
// - a negative int/float value is used as the int/float argument, e.g. database ID
// - the string value `notFound` is used as the string argument, e.g. projectID
// - a negative int/float value is used as the int/float argument, e.g. database ID
func NewMockHTTPClient() HTTPClient {
u, _ := url.Parse(baseURL)
return mockHTTPClient{
Expand Down
Loading

0 comments on commit b030423

Please sign in to comment.