Skip to content

Commit

Permalink
Merge pull request #39 from reubenmiller/ci-add-spellcheck
Browse files Browse the repository at this point in the history
fix: fix various typos in comments and public api
  • Loading branch information
reubenmiller authored Jan 17, 2024
2 parents 9c9c757 + 1320fad commit 5d62834
Show file tree
Hide file tree
Showing 20 changed files with 66 additions and 48 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: pr
on:
pull_request:
branches: [ main ]
jobs:
typos:
name: Spell Check with Typos
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check spelling
uses: crate-ci/typos@master
6 changes: 6 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
files.extend-exclude = [
"**/vendor/"
]

[default.extend-identifiers]
mosquitto = "mosquitto"
2 changes: 1 addition & 1 deletion examples/realtime-client-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func main() {
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, os.Interrupt)

log.Printf("Listenening to subscriptions")
log.Printf("Listening to subscriptions")

for {
select {
Expand Down
2 changes: 1 addition & 1 deletion pkg/c8y/alarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// AlarmService provides api to get/set/delete alarms in Cumulocity
type AlarmService service

// Cumulocity alarm Serverity types
// Cumulocity alarm Severity types
const (
AlarmSeverityCritical = "CRITICAL"
AlarmSeverityMajor = "MAJOR"
Expand Down
8 changes: 4 additions & 4 deletions pkg/c8y/alarmBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@ func (b AlarmBuilder) Severity() string {
return ""
}

// SetSeverityMajor sets the alarm serverity to Major
// SetSeverityMajor sets the alarm severity to Major
func (b *AlarmBuilder) SetSeverityMajor() *AlarmBuilder {
return b.Set("severity", AlarmSeverityMajor)
}

// SetSeverityMinor sets the alarm serverity to Minor
// SetSeverityMinor sets the alarm severity to Minor
func (b *AlarmBuilder) SetSeverityMinor() *AlarmBuilder {
return b.Set("severity", AlarmSeverityMinor)
}

// SetSeverityCritical sets the alarm serverity to Critical
// SetSeverityCritical sets the alarm severity to Critical
func (b *AlarmBuilder) SetSeverityCritical() *AlarmBuilder {
return b.Set("severity", AlarmSeverityCritical)
}

// SetSeverityWarning sets the alarm serverity to Warning
// SetSeverityWarning sets the alarm severity to Warning
func (b *AlarmBuilder) SetSeverityWarning() *AlarmBuilder {
return b.Set("severity", AlarmSeverityWarning)
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/c8y/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ import (

const TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"

type Cachable func(*http.Request) bool
type Cacheable func(*http.Request) bool

func NewCachedClient(httpClient *http.Client, cacheDir string, cacheTTL time.Duration, isCachable Cachable, opts CacheOptions) *http.Client {
func NewCachedClient(httpClient *http.Client, cacheDir string, cacheTTL time.Duration, isCacheable Cacheable, opts CacheOptions) *http.Client {
if cacheDir == "" {
cacheDir = filepath.Join(os.TempDir(), "go-c8y-cache")
}
if isCachable == nil {
isCachable = isCacheableRequest
if isCacheable == nil {
isCacheable = isCacheableRequest
}
return &http.Client{
Transport: CacheResponse(cacheTTL, cacheDir, isCachable, opts)(httpClient.Transport),
Transport: CacheResponse(cacheTTL, cacheDir, isCacheable, opts)(httpClient.Transport),
}
}

Expand All @@ -50,7 +50,7 @@ func isCacheableResponse(res *http.Response) bool {
}

// CacheResponse produces a RoundTripper that caches HTTP responses to disk for a specified amount of time
func CacheResponse(ttl time.Duration, dir string, isCachable Cachable, options CacheOptions) ClientOption {
func CacheResponse(ttl time.Duration, dir string, isCacheable Cacheable, options CacheOptions) ClientOption {
fs := fileStorage{
dir: dir,
ttl: ttl,
Expand All @@ -60,7 +60,7 @@ func CacheResponse(ttl time.Duration, dir string, isCachable Cachable, options C
return func(tr http.RoundTripper) http.RoundTripper {
return &funcTripper{roundTrip: func(req *http.Request) (*http.Response, error) {

if !isCachable(req) {
if !isCacheable(req) {
return tr.RoundTrip(req)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/c8y/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1217,9 +1217,9 @@ type ErrorResponse struct {

// Error details. Only available in DEBUG mode.
Details *struct {
ExpectionClass string `json:"expectionClass,omitempty"`
ExceptionClass string `json:"exceptionClass,omitempty"`
ExceptionMessage string `json:"exceptionMessage,omitempty"`
ExpectionStackTrace string `json:"expectionStackTrace,omitempty"`
ExceptionStackTrace string `json:"exceptionStackTrace,omitempty"`
} `json:"details,omitempty"`
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/c8y/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,9 @@ func (s *InventoryService) AddChildAddition(ctx context.Context, ID, childID str
}

// CreateChildAdditionWithBinary create a child addition with a child binary upload a binary and creates a software version referencing it
func (s *InventoryService) CreateChildAdditionWithBinary(ctx context.Context, parentID string, binaryFile binary.MultiPartReader, bodyFunc func(binaryURL string) interface{}, middlware ...RequestMiddleware) (*ManagedObject, *Response, error) {
func (s *InventoryService) CreateChildAdditionWithBinary(ctx context.Context, parentID string, binaryFile binary.MultiPartReader, bodyFunc func(binaryURL string) interface{}, middleware ...RequestMiddleware) (*ManagedObject, *Response, error) {
// Upload file
binary, resp, err := s.client.Inventory.CreateBinary(ctx, binaryFile, middlware...)
binary, resp, err := s.client.Inventory.CreateBinary(ctx, binaryFile, middleware...)
if err != nil {
return binary, resp, err
}
Expand All @@ -617,9 +617,9 @@ func (s *InventoryService) CreateChildAdditionWithBinary(ctx context.Context, pa
}

// CreateWithBinary create managed object which also has a binary linked as a child addition so that the binary is deleted when the parent maanaged object is deleted
func (s *InventoryService) CreateWithBinary(ctx context.Context, binaryFile binary.MultiPartReader, bodyFunc func(binaryURL string) interface{}, middlware ...RequestMiddleware) (*ManagedObject, *Response, error) {
func (s *InventoryService) CreateWithBinary(ctx context.Context, binaryFile binary.MultiPartReader, bodyFunc func(binaryURL string) interface{}, middleware ...RequestMiddleware) (*ManagedObject, *Response, error) {
// Upload file
binary, resp, err := s.client.Inventory.CreateBinary(ctx, binaryFile, middlware...)
binary, resp, err := s.client.Inventory.CreateBinary(ctx, binaryFile, middleware...)
if err != nil {
return binary, resp, err
}
Expand Down
28 changes: 14 additions & 14 deletions pkg/c8y/measurement.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func (s *MeasurementService) DeleteMeasurements(ctx context.Context, opt *Measur
})
}

// MeasurementSerieDefinition represents information about a serie
type MeasurementSerieDefinition struct {
// MeasurementSeriesDefinition represents information about a single series
type MeasurementSeriesDefinition struct {
Unit string `json:"unit"`
Name string `json:"name"`
Type string `json:"type"`
Expand All @@ -112,7 +112,7 @@ type MeasurementSeriesAggregateValueGroup struct {
// MeasurementSeriesGroup represents a group of series values (no aggregate values)
type MeasurementSeriesGroup struct {
DeviceID string `json:"deviceId"`
Series []MeasurementSerieDefinition `json:"series"`
Series []MeasurementSeriesDefinition `json:"series"`
Values []MeasurementSeriesValueGroup `json:"values"`
DateFrom time.Time `json:"dateFrom"`
DateTo time.Time `json:"dateTo"`
Expand All @@ -121,7 +121,7 @@ type MeasurementSeriesGroup struct {

// MeasurementSeriesAggregateGroup represents a group of aggregate series
type MeasurementSeriesAggregateGroup struct {
Series []MeasurementSerieDefinition `json:"series"`
Series []MeasurementSeriesDefinition `json:"series"`
Values []MeasurementSeriesAggregateValueGroup `json:"values"`
DateFrom time.Time `json:"dateFrom"`
DateTo time.Time `json:"dateTo"`
Expand Down Expand Up @@ -150,12 +150,12 @@ func (d *MeasurementSeriesGroup) UnmarshalJSON(data []byte) error {
c8ySeries := gjson.ParseBytes(data)

// Get the series definitions
var seriesDefinitions []MeasurementSerieDefinition
var seriesDefinitions []MeasurementSeriesDefinition

c8ySeries.Get("series").ForEach(func(_, serie gjson.Result) bool {
v := &MeasurementSerieDefinition{}
if err := json.Unmarshal([]byte(serie.String()), &v); err != nil {
Logger.Infof("Could not unmarshal series definition. %s", serie.String())
c8ySeries.Get("series").ForEach(func(_, item gjson.Result) bool {
v := &MeasurementSeriesDefinition{}
if err := json.Unmarshal([]byte(item.String()), &v); err != nil {
Logger.Infof("Could not unmarshal series definition. %s", item.String())
}

seriesDefinitions = append(seriesDefinitions, *v)
Expand Down Expand Up @@ -211,12 +211,12 @@ func (d *MeasurementSeriesAggregateGroup) UnmarshalJSON(data []byte) error {
c8ySeries := gjson.ParseBytes(data)

// Get the series definitions
var seriesDefinitions []MeasurementSerieDefinition
var seriesDefinitions []MeasurementSeriesDefinition

c8ySeries.Get("series").ForEach(func(_, serie gjson.Result) bool {
v := &MeasurementSerieDefinition{}
if err := json.Unmarshal([]byte(serie.String()), &v); err != nil {
Logger.Infof("Could not unmarshal series definition. %s", serie.String())
c8ySeries.Get("series").ForEach(func(_, item gjson.Result) bool {
v := &MeasurementSeriesDefinition{}
if err := json.Unmarshal([]byte(item.String()), &v); err != nil {
Logger.Infof("Could not unmarshal series definition. %s", item.String())
}

seriesDefinitions = append(seriesDefinitions, *v)
Expand Down
2 changes: 1 addition & 1 deletion pkg/microservice/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Configuration struct {
viper *viper.Viper
}

// InitConfiguration initiliases the configuration (i.e. reads from file / environment variables)
// InitConfiguration initializes the configuration (i.e. reads from file / environment variables)
func (c *Configuration) InitConfiguration() {
config := c.viper
config.SetConfigName("application")
Expand Down
2 changes: 1 addition & 1 deletion pkg/microservice/microservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func NewDefaultMicroservice(opts Options) *Microservice {
}

// NewMicroservice create a new microservice where the user can customize the http client and the host
// This function will not initiliase the logger (.InitializeLogger()) nor call .Config.InitConfiguration(), it
// This function will not initialize the logger (.InitializeLogger()) nor call .Config.InitConfiguration(), it
// is up to the user to call these functions
func NewMicroservice(httpClient *http.Client, host string, skipRealtimeClient bool) *Microservice {
return &Microservice{
Expand Down
2 changes: 1 addition & 1 deletion test/c8y_test/alarmBuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,6 @@ func TestAlarmBuilder_GetSet(t *testing.T) {
testingutils.Equals(t, true, ok)
testingutils.Equals(t, int64(2), val.(int64))

_, ok = builder.Get("c8y_NonExistantProp")
_, ok = builder.Get("c8y_NonExistentProp")
testingutils.Equals(t, false, ok)
}
2 changes: 1 addition & 1 deletion test/c8y_test/alarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestAlarmService_UpdateAlarm(t *testing.T) {
alarm = &c8y.Alarm{}
}

// Update serverity
// Update severity
updatedAlarm1, resp, err := client.Alarm.Update(
context.Background(),
alarm.ID,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/c8y_test/eventBuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ func TestEventBuilder_GetSet(t *testing.T) {
testingutils.Equals(t, true, ok)
testingutils.Equals(t, int64(2), val.(int64))

_, ok = builder.Get("c8y_NonExistantProp")
_, ok = builder.Get("c8y_NonExistentProp")
testingutils.Equals(t, false, ok)
}
2 changes: 1 addition & 1 deletion test/c8y_test/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestIdentityService_GetExternalID(t *testing.T) {

identity, resp, err := client.Identity.GetExternalID(
context.Background(),
"NoExistantType",
"NoExistentType",
"Value123",
)

Expand Down
6 changes: 3 additions & 3 deletions test/c8y_test/measurement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/reubenmiller/go-c8y/pkg/c8y"
)

func measurmentFactory(client *c8y.Client, deviceID string, valueFragmentType, ValueFragmentSeries string) func(float64) (*c8y.Measurement, *c8y.Response, error) {
func measurementFactory(client *c8y.Client, deviceID string, valueFragmentType, ValueFragmentSeries string) func(float64) (*c8y.Measurement, *c8y.Response, error) {
counter := 1
return func(value float64) (*c8y.Measurement, *c8y.Response, error) {
counter++
Expand Down Expand Up @@ -399,8 +399,8 @@ func TestMeasurementService_DeleteMeasurements(t *testing.T) {
testingutils.Ok(t, err)

valueFragmentType := "nx_Type1"
createMeasVariable1 := measurmentFactory(client, testDevice.ID, valueFragmentType, "Variable1")
createMeasVariable2 := measurmentFactory(client, testDevice.ID, valueFragmentType, "Variable2")
createMeasVariable1 := measurementFactory(client, testDevice.ID, valueFragmentType, "Variable1")
createMeasVariable2 := measurementFactory(client, testDevice.ID, valueFragmentType, "Variable2")

meas1, resp, err := createMeasVariable1(1.0)
testingutils.Ok(t, err)
Expand Down
2 changes: 1 addition & 1 deletion test/c8y_test/operationBuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ func TestOperationBuilder_GetSet(t *testing.T) {
testingutils.Equals(t, true, ok)
testingutils.Equals(t, int64(2), val.(int64))

_, ok = builder.Get("c8y_NonExistantProp")
_, ok = builder.Get("c8y_NonExistentProp")
testingutils.Equals(t, false, ok)
}
8 changes: 4 additions & 4 deletions test/c8y_test/realtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,19 +288,19 @@ func TestRealtimeSubscriptions_Unsubscribe(t *testing.T) {
}
}()

subcriptionPattern := c8y.RealtimeOperations(device.ID)
subscriptionPattern := c8y.RealtimeOperations(device.ID)

err = <-realtime.Subscribe(subcriptionPattern, ch)
err = <-realtime.Subscribe(subscriptionPattern, ch)
testingutils.Ok(t, err)

// Unsubscribe then resubscribe, this should not lead to duplicated messages
err = <-realtime.Unsubscribe(subcriptionPattern)
err = <-realtime.Unsubscribe(subscriptionPattern)
testingutils.Ok(t, err)

sendOperation() // Subscription should not count as the sub

time.Sleep(2 * time.Second)
err = <-realtime.Subscribe(subcriptionPattern, ch)
err = <-realtime.Subscribe(subscriptionPattern, ch)
testingutils.Ok(t, err)

sendOperation()
Expand Down
2 changes: 1 addition & 1 deletion test/c8y_test/tenant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,6 @@ func TestTenantService_GetTenantLoginOptions(t *testing.T) {

testingutils.Ok(t, err)
testingutils.Assert(t, resp != nil, "response should not be empty")
testingutils.Assert(t, len(loginOptions.LoginOptions) > 0, "Shoud have at least 1 login option")
testingutils.Assert(t, len(loginOptions.LoginOptions) > 0, "Should have at least 1 login option")
testingutils.Assert(t, loginOptions.Self != "", "self link should not be empty")
}

0 comments on commit 5d62834

Please sign in to comment.