-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f05d91
commit 08e9dd7
Showing
6 changed files
with
197 additions
and
6 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
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,34 @@ | ||
package version | ||
|
||
import ( | ||
"reflect" | ||
|
||
"github.com/newrelic/newrelic-client-go/v2/pkg/agent" | ||
"golang.org/x/text/cases" | ||
"golang.org/x/text/language" | ||
) | ||
|
||
func AgentNameTitleCase(agentName agent.AgentReleasesFilter) string { | ||
caser := cases.Title(language.AmericanEnglish) | ||
|
||
switch agentName { | ||
case agent.AgentReleasesFilterTypes.DOTNET: | ||
return ".NET" | ||
case agent.AgentReleasesFilterTypes.IOS: | ||
return "iOS" | ||
case agent.AgentReleasesFilterTypes.NODEJS: | ||
return "Node.js" | ||
case agent.AgentReleasesFilterTypes.PHP: | ||
return "PHP" | ||
case agent.AgentReleasesFilterTypes.SDK: | ||
return "C SDK" | ||
default: | ||
return caser.String(string(agentName)) | ||
} | ||
} | ||
|
||
func IsValidAgentName(agentName string) bool { | ||
a := reflect.ValueOf(agent.AgentReleasesFilterTypes) | ||
|
||
return a.FieldByName(agentName).String() == agentName | ||
} |
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,105 @@ | ||
package version_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/newrelic/newrelic-cli/internal/agent/version" | ||
"github.com/newrelic/newrelic-client-go/v2/pkg/agent" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAgentNameTitleCase(t *testing.T) { | ||
t.Parallel() | ||
|
||
expected := "Android" | ||
agentName := agent.AgentReleasesFilterTypes.ANDROID | ||
actual := version.AgentNameTitleCase(agentName) | ||
|
||
assert.Equal(t, expected, actual) | ||
|
||
expected = "Browser" | ||
agentName = agent.AgentReleasesFilterTypes.BROWSER | ||
actual = version.AgentNameTitleCase(agentName) | ||
|
||
assert.Equal(t, expected, actual) | ||
|
||
expected = ".NET" | ||
agentName = agent.AgentReleasesFilterTypes.DOTNET | ||
actual = version.AgentNameTitleCase(agentName) | ||
|
||
assert.Equal(t, expected, actual) | ||
|
||
expected = "Elixir" | ||
agentName = agent.AgentReleasesFilterTypes.ELIXIR | ||
actual = version.AgentNameTitleCase(agentName) | ||
|
||
assert.Equal(t, expected, actual) | ||
|
||
expected = "Go" | ||
agentName = agent.AgentReleasesFilterTypes.GO | ||
actual = version.AgentNameTitleCase(agentName) | ||
|
||
assert.Equal(t, expected, actual) | ||
|
||
expected = "Infrastructure" | ||
agentName = agent.AgentReleasesFilterTypes.INFRASTRUCTURE | ||
actual = version.AgentNameTitleCase(agentName) | ||
|
||
assert.Equal(t, expected, actual) | ||
|
||
expected = "iOS" | ||
agentName = agent.AgentReleasesFilterTypes.IOS | ||
actual = version.AgentNameTitleCase(agentName) | ||
|
||
assert.Equal(t, expected, actual) | ||
|
||
expected = "Java" | ||
agentName = agent.AgentReleasesFilterTypes.JAVA | ||
actual = version.AgentNameTitleCase(agentName) | ||
|
||
assert.Equal(t, expected, actual) | ||
|
||
expected = "Node.js" | ||
agentName = agent.AgentReleasesFilterTypes.NODEJS | ||
actual = version.AgentNameTitleCase(agentName) | ||
|
||
assert.Equal(t, expected, actual) | ||
|
||
expected = "PHP" | ||
agentName = agent.AgentReleasesFilterTypes.PHP | ||
actual = version.AgentNameTitleCase(agentName) | ||
|
||
assert.Equal(t, expected, actual) | ||
|
||
expected = "Python" | ||
agentName = agent.AgentReleasesFilterTypes.PYTHON | ||
actual = version.AgentNameTitleCase(agentName) | ||
|
||
assert.Equal(t, expected, actual) | ||
|
||
expected = "Ruby" | ||
agentName = agent.AgentReleasesFilterTypes.RUBY | ||
actual = version.AgentNameTitleCase(agentName) | ||
|
||
assert.Equal(t, expected, actual) | ||
|
||
expected = "C SDK" | ||
agentName = agent.AgentReleasesFilterTypes.SDK | ||
actual = version.AgentNameTitleCase(agentName) | ||
|
||
assert.Equal(t, expected, actual) | ||
} | ||
|
||
func TestIsValidAgentName(t *testing.T) { | ||
t.Parallel() | ||
|
||
agentName := "PYTHON" | ||
actual := version.IsValidAgentName(agentName) | ||
|
||
assert.True(t, actual) | ||
|
||
agentName = "ASDF" | ||
actual = version.IsValidAgentName(agentName) | ||
|
||
assert.False(t, actual) | ||
} |