Skip to content
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

feat: alias deprecated field to deprecation info struct #371

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions hcloud/schema/iso.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package schema

import "time"

// ISO defines the schema of an ISO image.
type ISO struct {
ID int64 `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Type string `json:"type"`
Architecture *string `json:"architecture"`
Deprecated *time.Time `json:"deprecated"`
ID int64 `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Type string `json:"type"`
Architecture *string `json:"architecture"`
DeprecatableResource
}

Expand Down
6 changes: 6 additions & 0 deletions hcloud/schema_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ type converter interface {

ISOFromSchema(schema.ISO) *ISO

// We cannot use goverter settings when mapping a struct to a struct pointer
// See [converter.ISOFromSchema]
// See https://github.com/jmattheis/goverter/issues/114
// goverter:map DeprecatableResource.Deprecation.UnavailableAfter Deprecated
intISOFromSchema(schema.ISO) ISO

SchemaFromISO(*ISO) schema.ISO

LocationFromSchema(schema.Location) *Location
Expand Down
44 changes: 30 additions & 14 deletions hcloud/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,22 +249,38 @@ func TestPrimaryIPSchema(t *testing.T) {
}

func TestISOSchema(t *testing.T) {
data := []byte(`{
"id": 4711,
"name": "FreeBSD-11.0-RELEASE-amd64-dvd1",
"description": "FreeBSD 11.0 x64",
"type": "public",
"architecture": "x86",
"deprecated": "2018-02-28T00:00:00+00:00"
}`)

var s schema.ISO
assert.NoError(t, json.Unmarshal(data, &s))
for name, tc := range map[string]string{
"without deprecation": `{
"id": 4711,
"name": "FreeBSD-11.0-RELEASE-amd64-dvd1",
"description": "FreeBSD 11.0 x64",
"type": "public",
"architecture": "x86"
}`,
"with deprecation": `{
"id": 4711,
"name": "FreeBSD-11.0-RELEASE-amd64-dvd1",
"description": "FreeBSD 11.0 x64",
"type": "public",
"architecture": "x86",
"deprecation": {
"announced": "2018-01-28T00:00:00+00:00",
"unavailable_after": "2018-04-28T00:00:00+00:00"
},
"deprecated": "2018-04-28T00:00:00+00:00"
}`,
} {
t.Run(name, func(t *testing.T) {
data := []byte(tc)
var s schema.ISO
assert.NoError(t, json.Unmarshal(data, &s))

assert.Equal(t, s, SchemaFromISO(ISOFromSchema(s)))
assert.Equal(t, s, SchemaFromISO(ISOFromSchema(s)))

iso := ISOFromSchema(s)
assert.Equal(t, iso, ISOFromSchema(SchemaFromISO(iso)))
iso := ISOFromSchema(s)
assert.Equal(t, iso, ISOFromSchema(SchemaFromISO(iso)))
})
}
}

func TestDatacenterSchema(t *testing.T) {
Expand Down
50 changes: 22 additions & 28 deletions hcloud/zz_schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading