-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(application_setting): Added test cases for application settings pkg
- Loading branch information
1 parent
51c0f03
commit 342e4d7
Showing
8 changed files
with
220 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package applicationsettings | ||
|
||
import ( | ||
"github.com/newrelic/newrelic-client-go/v2/internal/http" | ||
"github.com/newrelic/newrelic-client-go/v2/pkg/config" | ||
"github.com/newrelic/newrelic-client-go/v2/pkg/entities" | ||
"github.com/newrelic/newrelic-client-go/v2/pkg/logging" | ||
mock "github.com/newrelic/newrelic-client-go/v2/pkg/testhelpers" | ||
"testing" | ||
) | ||
|
||
type ApplicationSettings struct { | ||
client http.Client | ||
logger logging.Logger | ||
config config.Config | ||
} | ||
|
||
func New(config config.Config) ApplicationSettings { | ||
client := http.NewClient(config) | ||
pkg := ApplicationSettings{ | ||
client: client, | ||
logger: config.GetLogger(), | ||
config: config, | ||
} | ||
return pkg | ||
} | ||
|
||
func newIntegrationTestClient(t *testing.T) ApplicationSettings { | ||
tc := mock.NewIntegrationTestConfig(t) | ||
return New(tc) | ||
} | ||
|
||
func newMockResponseApm(t *testing.T, mockJSONResponse string, statusCode int) ApplicationSettings { | ||
ts := mock.NewMockServer(t, mockJSONResponse, statusCode) | ||
tc := mock.NewTestConfig(t, ts) | ||
|
||
return New(tc) | ||
} | ||
|
||
// nolint | ||
func newMockResponse(t *testing.T, mockJSONResponse string, statusCode int) entities.Entities { | ||
ts := mock.NewMockServer(t, mockJSONResponse, statusCode) | ||
tc := mock.NewTestConfig(t, ts) | ||
|
||
return entities.New(tc) | ||
} |
10 changes: 4 additions & 6 deletions
10
pkg/apm/apm_api.go → ...cationSettings/applicationSettings_api.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
pkg/applicationSettings/applicationSettings_integration_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//go:build integration | ||
// +build integration | ||
|
||
package applicationsettings | ||
|
||
import ( | ||
"github.com/newrelic/newrelic-client-go/v2/pkg/testhelpers" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestIntegrationAgentApplicationSettings_All(t *testing.T) { | ||
t.Parallel() | ||
client := newIntegrationTestClient(t) | ||
|
||
aliasName := testhelpers.IntegrationTestApplicationEntityNameNew | ||
// updating an existing application setting | ||
// this is expected to throw no error, and successfully updating application setting | ||
applicationSettingTestResult, err := client.AgentApplicationSettingsUpdate( | ||
testhelpers.IntegrationTestApplicationEntityGUIDNew, | ||
AgentApplicationSettingsUpdateInput{ | ||
Alias: &aliasName, | ||
}, | ||
) | ||
|
||
require.NoError(t, err) | ||
require.NotNil(t, applicationSettingTestResult) | ||
require.Equal(t, aliasName, applicationSettingTestResult.Alias) | ||
|
||
// updating an existing application setting | ||
// this is expected to throw no error, and successfully updating application setting | ||
applicationSettingTestResult, err = client.AgentApplicationSettingsUpdate( | ||
testhelpers.IntegrationTestApplicationEntityGUIDNew, | ||
AgentApplicationSettingsUpdateInput{ | ||
ApmConfig: &AgentApplicationSettingsApmConfigInput{ | ||
ApdexTarget: 0.5, | ||
}, | ||
}, | ||
) | ||
|
||
require.NoError(t, err) | ||
require.NotNil(t, applicationSettingTestResult) | ||
require.Equal(t, aliasName, applicationSettingTestResult.Alias) | ||
require.Equal(t, applicationSettingTestResult.ApmSettings.ApmConfig.ApdexTarget, 0.5) | ||
|
||
} | ||
|
||
func TestIntegrationAgentApplicationSettingsError(t *testing.T) { | ||
t.Parallel() | ||
client := newIntegrationTestClient(t) | ||
|
||
TransactionValue := 0.5 | ||
// updating an existing application setting | ||
// this is expected to throw no error, and successfully updating application setting | ||
_, err := client.AgentApplicationSettingsUpdate( | ||
testhelpers.IntegrationTestApplicationEntityGUIDNew, | ||
AgentApplicationSettingsUpdateInput{ | ||
TransactionTracer: &AgentApplicationSettingsTransactionTracerInput{ | ||
TransactionThresholdValue: &TransactionValue, | ||
}, | ||
}, | ||
) | ||
|
||
require.Error(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
//go:build unit | ||
// +build unit | ||
|
||
package applicationsettings | ||
|
||
import ( | ||
"fmt" | ||
mock "github.com/newrelic/newrelic-client-go/v2/pkg/testhelpers" | ||
"github.com/stretchr/testify/assert" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
var ( | ||
testApplicationSettings = AgentApplicationSettingsUpdateInput{ | ||
Alias: func(s string) *string { return &s }("tf_test_updated"), | ||
ApmConfig: &AgentApplicationSettingsApmConfigInput{ | ||
ApdexTarget: 0, | ||
UseServerSideConfig: func(b bool) *bool { return &b }(false), | ||
}, | ||
ThreadProfiler: &AgentApplicationSettingsThreadProfilerInput{ | ||
Enabled: func(b bool) *bool { return &b }(false), | ||
}, | ||
ErrorCollector: &AgentApplicationSettingsErrorCollectorInput{ | ||
Enabled: func(b bool) *bool { return &b }(false), | ||
ExpectedErrorCodes: nil, | ||
ExpectedErrorClasses: nil, | ||
IgnoredErrorCodes: nil, | ||
IgnoredErrorClasses: nil, | ||
}, | ||
TransactionTracer: &AgentApplicationSettingsTransactionTracerInput{ | ||
Enabled: func(b bool) *bool { return &b }(false), | ||
TransactionThresholdValue: func(f float64) *float64 { return &f }(0), | ||
TransactionThresholdType: "", | ||
RecordSql: "", | ||
LogSql: func(b bool) *bool { return &b }(false), | ||
StackTraceThreshold: func(f float64) *float64 { return &f }(0), | ||
ExplainEnabled: func(b bool) *bool { return &b }(false), | ||
ExplainThresholdValue: func(f float64) *float64 { return &f }(0), | ||
ExplainThresholdType: "", | ||
}, | ||
TracerType: &AgentApplicationSettingsTracerTypeInput{"NONE"}, | ||
} | ||
|
||
testApplicationJson = `{ | ||
"apmSettings": { | ||
"Alias": "tf_test_updated", | ||
"ApmConfig": { | ||
"ApdexTarget": 0, | ||
"UseServerSideConfig": false | ||
}, | ||
"ThreadProfilerEnabled": false, | ||
"ErrorCollector": { | ||
"Enabled": false, | ||
"ExpectedErrorCodes": [], | ||
"ExpectedErrorClasses": [], | ||
"IgnoredErrorCodes": [], | ||
"IgnoredErrorClasses": [] | ||
}, | ||
"TransactionTracing": { | ||
"Enabled": false, | ||
"TransactionThresholdValue": 0, | ||
"TransactionThresholdType": "off", | ||
"RecordSql": "off", | ||
"LogSql": false, | ||
"StackTraceThresholdValue": 0, | ||
"ExplainQueryPlanEnabled": false, | ||
"ExplainQueryPlanThresholdValue": 0, | ||
"ExplainQueryPlanThresholdType": "off" | ||
}, | ||
"TracerType": "NONE" | ||
} | ||
}` | ||
) | ||
|
||
func TestGetApmApplicationDetails(t *testing.T) { | ||
t.Parallel() | ||
responseJSON := fmt.Sprintf(`{"application": %s}`, testApplicationJson) | ||
client := newMockResponse(t, responseJSON, http.StatusOK) | ||
|
||
actual, err := client.GetEntity(mock.IntegrationTestApplicationEntityGUIDNew) | ||
|
||
assert.NoError(t, err) | ||
assert.NotNil(t, actual) | ||
} | ||
|
||
func TestUpdateApmApplicationDetails(t *testing.T) { | ||
t.Parallel() | ||
responseJSON := fmt.Sprintf(`{ "application": %s}`, testApplicationJson) | ||
client := newMockResponseApm(t, responseJSON, http.StatusOK) | ||
|
||
actual, err := client.AgentApplicationSettingsUpdate(mock.IntegrationTestApplicationEntityGUIDNew, testApplicationSettings) | ||
|
||
assert.NoError(t, err) | ||
assert.NotNil(t, actual) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters