Skip to content

Commit

Permalink
Convert to Slice if Project Tags are passed comma separated
Browse files Browse the repository at this point in the history
  • Loading branch information
takumakume committed Nov 22, 2023
1 parent 29ca9b7 commit a4e9260
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
9 changes: 8 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package config

import "errors"
import (
"errors"
"strings"
)

type Config struct {
BaseURL string
Expand All @@ -14,6 +17,10 @@ type Config struct {
var ErrAPIKeyIsRequired = errors.New("api-key is required")

func New(baseURL, apiKey, projectName, projectVersion string, projectTags []string) *Config {
if len(projectTags) == 1 && strings.Contains(projectTags[0], ",") {
projectTags = strings.Split(projectTags[0], ",")
}

return &Config{
BaseURL: baseURL,
APIKey: apiKey,
Expand Down
17 changes: 17 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ func TestNew(t *testing.T) {
ProjectTags: []string{"tag1", "tag2"},
},
},
{
name: "success tag separator is comma",
args: args{
baseURL: "https://example.com",
apiKey: "12345",
projectName: "test-project",
projectVersion: "1.0.0",
projectTags: []string{"tag1,tag2"},
},
want: &Config{
BaseURL: "https://example.com",
APIKey: "12345",
ProjectName: "test-project",
ProjectVersion: "1.0.0",
ProjectTags: []string{"tag1", "tag2"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit a4e9260

Please sign in to comment.