Skip to content
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
7 changes: 7 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ linters:
- perfsprint
- predeclared
- rowserrcheck
- revive
- sqlclosecheck
- staticcheck
- unconvert
Expand Down Expand Up @@ -159,6 +160,12 @@ linters:
perfsprint:
# modernize generates nicer fix code
concat-loop: false
revive:
rules:
- name: exported
arguments:
- checkPrivateReceivers
- disableChecksOnConstants
staticcheck:
dot-import-whitelist:
- github.com/majewsky/gg/option
Expand Down
5 changes: 5 additions & 0 deletions Makefile.maker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ metadata:

golangciLint:
createConfig: true
reviveRules:
- name: exported
arguments:
- checkPrivateReceivers
- disableChecksOnConstants

githubWorkflow:
ci:
Expand Down
2 changes: 1 addition & 1 deletion castellum/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type StandaloneOperation struct {
AssetID string `json:"asset_id,omitempty"`
}

// StandaloneOperation is the API representation for a pending or finished
// Operation is the API representation for a pending or finished
// resize operation when the operation appears within its respective asset.
type Operation struct {
State OperationState `json:"state"`
Expand Down
2 changes: 1 addition & 1 deletion deployevent/deployevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type HelmRelease struct {
DurationSeconds *uint64 `json:"duration,omitempty"`
}

// ActiveDirectory appears in type Event. It describes a deployment of Active
// ActiveDirectoryDeployment appears in type Event. It describes a deployment of Active
// Directory to one of our Windows servers.
type ActiveDirectoryDeployment struct {
Landscape string `json:"landscape"` // e.g. "dev" or "prod"
Expand Down
1 change: 1 addition & 0 deletions internal/clone/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Package clone contains helper functions for implementing deep clones.
package clone

// Cloneable is an interface for types that can be cloned by implementing a Clone() method.
type Cloneable[Self any] interface {
Clone() Self
}
Expand Down
7 changes: 7 additions & 0 deletions internal/testhelper/testhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import (
"testing"
)

// AssertNoErr fails the test if the provided error is not nil.
func AssertNoErr(t *testing.T, err error) {
t.Helper()
if err != nil {
t.Errorf("unexpected error: %s", err.Error())
}
}

// AssertErr fails the test if the provided error is nil.
func AssertErr(t *testing.T, expected string, actual error) {
t.Helper()
switch {
Expand All @@ -29,6 +31,7 @@ func AssertErr(t *testing.T, expected string, actual error) {
}
}

// CheckEquals fails the test if a simple equal check between expected and actual fails.
func CheckEquals[V comparable](t *testing.T, expected, actual V) {
t.Helper()
if expected != actual {
Expand All @@ -37,6 +40,7 @@ func CheckEquals[V comparable](t *testing.T, expected, actual V) {
}
}

// CheckDeepEquals fails the test if a reflect.DeepEqual check between expected and actual fails.
func CheckDeepEquals(t *testing.T, expected, actual any) {
t.Helper()
if !reflect.DeepEqual(expected, actual) {
Expand All @@ -45,6 +49,8 @@ func CheckDeepEquals(t *testing.T, expected, actual any) {
}
}

// CheckJSONEquals fails the test if a reflect.DeepEqual check between the marshalled actual value
// and the expectedJSON fails.
func CheckJSONEquals(t *testing.T, expectedJSON string, actual any) {
t.Helper()
actualJSON, err := json.Marshal(actual)
Expand All @@ -58,6 +64,7 @@ func CheckJSONEquals(t *testing.T, expectedJSON string, actual any) {
}
}

// decodeJSON is a convenience wrapper around json.Marshal and fails the test if an error occurs.
func decodeJSON(t *testing.T, buf []byte) (data any) {
t.Helper()
err := json.Unmarshal(buf, &data)
Expand Down
2 changes: 1 addition & 1 deletion limes/rates/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// This type is used to serialize JSON request bodies in PUT requests on projects.
type RateRequest map[limes.ServiceType]ServiceRequest

// ServiceQuotaRequest contains new rate limit values for rates in a single
// ServiceRequest contains new rate limit values for rates in a single
// service. This type appears in type RateRequest.
type ServiceRequest map[RateName]RateLimitRequest

Expand Down
18 changes: 16 additions & 2 deletions limes/rates/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,40 @@ import (
"github.com/sapcc/go-api-declarations/limes"
)

func (r ClusterRateReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(r) }
// MarshalJSON implements the json.Marshaler interface.
func (r ClusterRateReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(r) }

// MarshalJSON implements the json.Marshaler interface.
func (s ClusterServiceReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(s) }
func (r ProjectRateReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(r) }

// MarshalJSON implements the json.Marshaler interface.
func (r ProjectRateReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(r) }

// MarshalJSON implements the json.Marshaler interface.
func (s ProjectServiceReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(s) }

// UnmarshalJSON implements the json.Unmarshaler interface.
func (r *ClusterRateReports) UnmarshalJSON(buf []byte) error {
m, err := marshal.MapFromList(buf, func(r *ClusterRateReport) RateName { return r.Name })
*r = ClusterRateReports(m)
return err
}

// UnmarshalJSON implements the json.Unmarshaler interface.
func (s *ClusterServiceReports) UnmarshalJSON(buf []byte) error {
m, err := marshal.MapFromList(buf, func(s *ClusterServiceReport) limes.ServiceType { return s.Type })
*s = ClusterServiceReports(m)
return err
}

// UnmarshalJSON implements the json.Unmarshaler interface.
func (r *ProjectRateReports) UnmarshalJSON(buf []byte) error {
m, err := marshal.MapFromList(buf, func(r *ProjectRateReport) RateName { return r.Name })
*r = ProjectRateReports(m)
return err
}

// UnmarshalJSON implements the json.Unmarshaler interface.
func (s *ProjectServiceReports) UnmarshalJSON(buf []byte) error {
m, err := marshal.MapFromList(buf, func(s *ProjectServiceReport) limes.ServiceType { return s.Type })
*s = ProjectServiceReports(m)
Expand Down
38 changes: 32 additions & 6 deletions limes/resources/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,70 @@ import (
"github.com/sapcc/go-api-declarations/limes"
)

// MarshalJSON implements the json.Marshaler interface.
func (r ClusterAvailabilityZoneReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(r) }
func (r ClusterResourceReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(r) }
func (s ClusterServiceReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(s) }
func (r DomainResourceReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(r) }
func (s DomainServiceReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(s) }
func (r ProjectResourceReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(r) }
func (s ProjectServiceReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(s) }

// MarshalJSON implements the json.Marshaler interface.
func (r ClusterResourceReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(r) }

// MarshalJSON implements the json.Marshaler interface.
func (s ClusterServiceReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(s) }

// MarshalJSON implements the json.Marshaler interface.
func (r DomainResourceReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(r) }

// MarshalJSON implements the json.Marshaler interface.
func (s DomainServiceReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(s) }

// MarshalJSON implements the json.Marshaler interface.
func (r ProjectResourceReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(r) }

// MarshalJSON implements the json.Marshaler interface.
func (s ProjectServiceReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(s) }

// UnmarshalJSON implements the json.Unmarshaler interface.
func (r *ClusterAvailabilityZoneReports) UnmarshalJSON(buf []byte) error {
m, err := marshal.MapFromList(buf, func(r *ClusterAvailabilityZoneReport) limes.AvailabilityZone { return r.Name })
*r = ClusterAvailabilityZoneReports(m)
return err
}

// UnmarshalJSON implements the json.Unmarshaler interface.
func (r *ClusterResourceReports) UnmarshalJSON(buf []byte) error {
m, err := marshal.MapFromList(buf, func(r *ClusterResourceReport) ResourceName { return r.Name })
*r = ClusterResourceReports(m)
return err
}

// UnmarshalJSON implements the json.Unmarshaler interface.
func (s *ClusterServiceReports) UnmarshalJSON(buf []byte) error {
m, err := marshal.MapFromList(buf, func(s *ClusterServiceReport) limes.ServiceType { return s.Type })
*s = ClusterServiceReports(m)
return err
}

// UnmarshalJSON implements the json.Unmarshaler interface.
func (r *DomainResourceReports) UnmarshalJSON(buf []byte) error {
m, err := marshal.MapFromList(buf, func(r *DomainResourceReport) ResourceName { return r.Name })
*r = DomainResourceReports(m)
return err
}

// UnmarshalJSON implements the json.Unmarshaler interface.
func (s *DomainServiceReports) UnmarshalJSON(buf []byte) error {
m, err := marshal.MapFromList(buf, func(s *DomainServiceReport) limes.ServiceType { return s.Type })
*s = DomainServiceReports(m)
return err
}

// UnmarshalJSON implements the json.Unmarshaler interface.
func (r *ProjectResourceReports) UnmarshalJSON(buf []byte) error {
m, err := marshal.MapFromList(buf, func(r *ProjectResourceReport) ResourceName { return r.Name })
*r = ProjectResourceReports(m)
return err
}

// UnmarshalJSON implements the json.Unmarshaler interface.
func (s *ProjectServiceReports) UnmarshalJSON(buf []byte) error {
m, err := marshal.MapFromList(buf, func(s *ProjectServiceReport) limes.ServiceType { return s.Type })
*s = ProjectServiceReports(m)
Expand Down
2 changes: 1 addition & 1 deletion limes/resources/report_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ type ClusterResourceReports map[ResourceName]*ClusterResourceReport
// using a map, but serializes to JSON as a list.
type ClusterAvailabilityZoneReports map[limes.AvailabilityZone]*ClusterAvailabilityZoneReport

// ClusterAZResourceReport is a substructure of ClusterResourceReport that breaks
// ClusterAZResourceReports is a substructure of ClusterResourceReport that breaks
// down capacity and usage data for a single resource by availability zone.
type ClusterAZResourceReports map[limes.AvailabilityZone]*ClusterAZResourceReport
2 changes: 1 addition & 1 deletion limes/resources/report_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ type DomainServiceReports map[limes.ServiceType]*DomainServiceReport
// to JSON as a list.
type DomainResourceReports map[ResourceName]*DomainResourceReport

// DomainAZResourceReport is a substructure of DomainResourceReport that breaks
// DomainAZResourceReports is a substructure of DomainResourceReport that breaks
// down quota and usage data for a single resource by availability zone.
type DomainAZResourceReports map[limes.AvailabilityZone]*DomainAZResourceReport
4 changes: 3 additions & 1 deletion limes/resources/report_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type ProjectAZResourceReport struct {
Subresources json.RawMessage `json:"subresources,omitempty"`
}

// HistoricalReport provides information about historical data and
// appears in type ProjectAZResourceReport.
type HistoricalReport struct {
MinUsage uint64 `json:"min_usage,omitempty"`
MaxUsage uint64 `json:"max_usage,omitempty"`
Expand All @@ -74,6 +76,6 @@ type ProjectServiceReports map[limes.ServiceType]*ProjectServiceReport
// to JSON as a list.
type ProjectResourceReports map[ResourceName]*ProjectResourceReport

// ProjectAZResourceReport is a substructure of ProjectResourceReport that breaks
// ProjectAZResourceReports is a substructure of ProjectResourceReport that breaks
// down quota and usage data for a single resource by availability zone.
type ProjectAZResourceReports map[limes.AvailabilityZone]*ProjectAZResourceReport
Loading