Skip to content

Commit

Permalink
Use Error instead of Fatal
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrytfleung committed Jan 17, 2024
1 parent ddd3881 commit 6088191
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions extension/solarwindsapmsettingsextension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func newSolarwindsApmSettingsExtension(extensionCfg *Config, logger *zap.Logger)
func Refresh(extension *solarwindsapmSettingsExtension) {
extension.logger.Info("Time to refresh from " + extension.config.Endpoint)
if hostname, err := os.Hostname(); err != nil {
extension.logger.Fatal("Unable to call os.Hostname() " + err.Error())
extension.logger.Error("Unable to call os.Hostname() " + err.Error())
} else {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
Expand All @@ -57,7 +57,7 @@ func Refresh(extension *solarwindsapmSettingsExtension) {
ClientVersion: "2",
}
if response, err := extension.client.GetSettings(ctx, request); err != nil {
extension.logger.Fatal("Unable to getSettings from " + extension.config.Endpoint + " " + err.Error())
extension.logger.Error("Unable to getSettings from " + extension.config.Endpoint + " " + err.Error())
} else {
switch result := response.GetResult(); result {
case collectorpb.ResultCode_OK:
Expand Down
20 changes: 20 additions & 0 deletions extension/solarwindsapmsettingsextension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@ func TestCreateExtension(t *testing.T) {
ex.Shutdown(context.TODO())
}

func TestCreateExtensionWrongEndpoint(t *testing.T) {
conf := &Config{
Endpoint: "apm.collector.cloud.solarwindsswoswoswo.com:443",
Key: "vlEW1JtimSH2LlBsNrPdeEjBxNl5z8Bp7gX55bNTk3_GIxHWedgj42GDFBWpRe2ne7TffHk:jerry_test",
Interval: "1s",
}
ex := createAnExtension(conf, t)
ex.Shutdown(context.TODO())
}

func TestCreateExtensionWrongKey(t *testing.T) {
conf := &Config{
Endpoint: "apm.collector.cloud.solarwinds.com:443",
Key: "IsItAKey:jerry_test",
Interval: "1s",
}
ex := createAnExtension(conf, t)
ex.Shutdown(context.TODO())
}

// create extension
func createAnExtension(c *Config, t *testing.T) extension.Extension {
logger, err := zap.NewProduction()
Expand Down

0 comments on commit 6088191

Please sign in to comment.