-
Notifications
You must be signed in to change notification settings - Fork 0
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
add new 'WithErrors' constructors #28
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -281,6 +281,123 @@ func TestNewSenderWithDeviceNameLeaks(t *testing.T) { | |
goleak.VerifyNone(t, ignore) | ||
} | ||
|
||
func TestNewSenderFromDeviceWithErrors(t *testing.T) { | ||
client, server, device, err := test.NewClientServer() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
flowServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(400) | ||
})) | ||
|
||
apiurl = server.URL(test.API) | ||
flowurl = server.URL(flowServer.URL) | ||
metricsurl = server.URL(test.TSDB) | ||
|
||
email = client.Email | ||
token = client.Token | ||
|
||
config := libkflow.NewConfig(email, token, "test", "0.0.1") | ||
config.OverrideURLs(apiurl, flowurl, metricsurl) | ||
|
||
l := stubLeveledLogger{} | ||
|
||
registry := metrics.NewRegistry() | ||
metrics2.StartWithSetConf(registry, &l, metricsurl.String(), email, token, "chf") | ||
config.WithRegistry(registry) | ||
|
||
s, errors, err := libkflow.NewSenderFromDeviceWithErrors(device, config) | ||
|
||
assert.NotNil(t, s) | ||
assert.Nil(t, err) | ||
|
||
errorsFromChan := make([]error, 0) | ||
|
||
wg := sync.WaitGroup{} | ||
wg.Add(1) | ||
go func() { | ||
for err := range errors { | ||
errorsFromChan = append(errorsFromChan, err) | ||
} | ||
wg.Done() | ||
}() | ||
|
||
s.Send(&flow.Flow{ | ||
TimestampNano: time.Now().UnixNano(), | ||
}) | ||
|
||
s.Stop(time.Second) | ||
|
||
wg.Wait() | ||
|
||
assert.Len(t, errorsFromChan, 1) | ||
} | ||
|
||
func TestNewSenderWithNewSiteAndDeviceWithErrors(t *testing.T) { | ||
client, server, device, err := test.NewClientServer() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
flowServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(400) | ||
})) | ||
|
||
apiurl = server.URL(test.API) | ||
flowurl = server.URL(flowServer.URL) | ||
metricsurl = server.URL(test.TSDB) | ||
|
||
email = client.Email | ||
token = client.Token | ||
|
||
config := libkflow.NewConfig(email, token, "test", "0.0.1") | ||
config.OverrideURLs(apiurl, flowurl, metricsurl) | ||
|
||
l := stubLeveledLogger{} | ||
|
||
registry := metrics.NewRegistry() | ||
metrics2.StartWithSetConf(registry, &l, metricsurl.String(), email, token, "chf") | ||
config.WithRegistry(registry) | ||
|
||
s, errors, err := libkflow.NewSenderWithNewSiteAndDeviceWithErrors(&api.SiteAndDeviceCreate{ | ||
Site: &api.SiteCreate{ | ||
Title: "", | ||
City: "", | ||
Region: "", | ||
Country: "", | ||
}, | ||
Device: &api.DeviceCreate{ | ||
AllowNoIP: true, | ||
Name: device.Name, | ||
}, | ||
}, config) | ||
|
||
assert.NotNil(t, s) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of my pet peeves is that You don't have to change it if you don't want to. Just trying to get the word out. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Funny you mention this. I first learned about I'll sharpen these tests up a bit. |
||
assert.Nil(t, err) | ||
|
||
errorsFromChan := make([]error, 0) | ||
|
||
wg := sync.WaitGroup{} | ||
wg.Add(1) | ||
go func() { | ||
for err := range errors { | ||
errorsFromChan = append(errorsFromChan, err) | ||
} | ||
wg.Done() | ||
}() | ||
|
||
s.Send(&flow.Flow{ | ||
TimestampNano: time.Now().UnixNano(), | ||
}) | ||
|
||
s.Stop(time.Second) | ||
|
||
wg.Wait() | ||
|
||
assert.Len(t, errorsFromChan, 1) | ||
} | ||
|
||
func TestNewSenderFromDevice(t *testing.T) { | ||
dev, assert := setupLibTest(t) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice if the other public constructors also got this documentation