From a4e9260304bb2812bb048aeef67993af8907c3c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B9=85=E7=B1=B3=20=E6=8B=93=E9=A6=AC?= Date: Wed, 22 Nov 2023 23:43:21 +0900 Subject: [PATCH] Convert to Slice if Project Tags are passed comma separated --- config/config.go | 9 ++++++++- config/config_test.go | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 3d59e63..99a762e 100644 --- a/config/config.go +++ b/config/config.go @@ -1,6 +1,9 @@ package config -import "errors" +import ( + "errors" + "strings" +) type Config struct { BaseURL string @@ -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, diff --git a/config/config_test.go b/config/config_test.go index bf306f1..346b507 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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) {