Skip to content

Commit

Permalink
comments and test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ktkenny committed Apr 23, 2024
1 parent b6040d1 commit fba0177
Show file tree
Hide file tree
Showing 10 changed files with 3,545 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func NewSenderWithNewDeviceWithErrors(dev *api.DeviceCreate, cfg *Config) (*Send
return cfg.startWithInternalErrors(client, d)
}

// NewSenderWithNewSiteAndDevice creates a new device and site then returns a flow Sender for that newly created device
func NewSenderWithNewSiteAndDevice(siteAndDevice *api.SiteAndDeviceCreate, errors chan<- error, cfg *Config) (*Sender, error) {
client := cfg.client()
d, err := client.CreateDeviceAndSite(siteAndDevice)
Expand All @@ -114,6 +115,9 @@ func NewSenderWithNewSiteAndDevice(siteAndDevice *api.SiteAndDeviceCreate, error
return cfg.start(client, d, errors)
}

// NewSenderWithNewSiteAndDeviceWithErrors is the same as NewSenderWithNewSiteAndDeviceWithErrors except rather than
// passing in a channel to receive errors, a channel is returned by the function. The channel is closed after Sender.Stop is called
// and all flow has been dispatched
func NewSenderWithNewSiteAndDeviceWithErrors(siteAndDevice *api.SiteAndDeviceCreate, cfg *Config) (*Sender, <-chan error, error) {
client := cfg.client()
d, err := client.CreateDeviceAndSite(siteAndDevice)
Expand All @@ -124,6 +128,7 @@ func NewSenderWithNewSiteAndDeviceWithErrors(siteAndDevice *api.SiteAndDeviceCre
return cfg.startWithInternalErrors(client, d)
}

// NewSenderFromDevice returns a Sender for an existing Device
func NewSenderFromDevice(d *api.Device, errors chan<- error, cfg *Config) (*Sender, error) {
client := cfg.client()
return cfg.start(client, d, errors)
Expand Down
9 changes: 5 additions & 4 deletions lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/kentik/libkflow/flow"
metrics2 "github.com/kentik/libkflow/metrics"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
)

Expand Down Expand Up @@ -309,8 +310,8 @@ func TestNewSenderFromDeviceWithErrors(t *testing.T) {

s, errors, err := libkflow.NewSenderFromDeviceWithErrors(device, config)

assert.NotNil(t, s)
assert.Nil(t, err)
require.NotNil(t, s)
require.Nil(t, err)

errorsFromChan := make([]error, 0)

Expand Down Expand Up @@ -373,8 +374,8 @@ func TestNewSenderWithNewSiteAndDeviceWithErrors(t *testing.T) {
},
}, config)

assert.NotNil(t, s)
assert.Nil(t, err)
require.NotNil(t, s)
require.Nil(t, err)

errorsFromChan := make([]error, 0)

Expand Down
28 changes: 28 additions & 0 deletions vendor/github.com/stretchr/testify/require/doc.go

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

16 changes: 16 additions & 0 deletions vendor/github.com/stretchr/testify/require/forward_requirements.go

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

Loading

0 comments on commit fba0177

Please sign in to comment.