diff --git a/pkg/allure/label.go b/pkg/allure/label.go index 8b7d7d8..3660fb9 100644 --- a/pkg/allure/label.go +++ b/pkg/allure/label.go @@ -2,6 +2,7 @@ package allure import ( "fmt" + "strconv" "strings" ) @@ -14,7 +15,22 @@ type Label struct { // GetValue returns label value as string func (l *Label) GetValue() string { - return strings.Trim(fmt.Sprintf("%s", l.Value), "\"") + switch v := l.Value.(type) { + case string: + return strings.Trim(v, "\"") + case int64: + return strconv.FormatInt(v, 10) + case float64: + return strconv.FormatFloat(v, 'f', -1, 64) + case bool: + return strconv.FormatBool(v) + case int: + return strconv.Itoa(v) + case float32: + return strconv.FormatFloat(float64(v), 'f', -1, 32) + default: + return strings.Trim(fmt.Sprintf("%v", v), "\"") + } } // NewLabel - builds and returns a new allure.Label. The label key depends on the passed LabelType. diff --git a/pkg/allure/label_test.go b/pkg/allure/label_test.go index 8b341c0..b4bdf50 100644 --- a/pkg/allure/label_test.go +++ b/pkg/allure/label_test.go @@ -79,6 +79,34 @@ func TestLabelCreation(t *testing.T) { owner := OwnerLabel("ownerTest") lead := LeadLabel("leadTest") idAllure := IDAllureLabel("idAllureTest") + newLabel := &Label{ + Name: "as_id", + Value: float64(4444.0), + } + newLabel2 := &Label{ + Name: "as_id", + Value: float32(4444.0), + } + newLabel3 := &Label{ + Name: "as_id", + Value: 4444.0, + } + newLabel4 := &Label{ + Name: "boolLabel", + Value: true, + } + newLabel5 := &Label{ + Name: "as_id", + Value: int64(2), + } + newLabel6 := &Label{ + Name: "as_id", + Value: int32(2), + } + newLabel7 := &Label{ + Name: "as_id", + Value: 2, + } require.Equal(t, epic.Name, Epic.ToString()) require.Equal(t, layer.Name, Layer.ToString()) @@ -116,4 +144,11 @@ func TestLabelCreation(t *testing.T) { require.Equal(t, "ownerTest", owner.GetValue()) require.Equal(t, "leadTest", lead.GetValue()) require.Equal(t, "idAllureTest", idAllure.GetValue()) + require.Equal(t, "4444", newLabel.GetValue()) + require.Equal(t, "4444", newLabel2.GetValue()) + require.Equal(t, "4444", newLabel3.GetValue()) + require.Equal(t, "true", newLabel4.GetValue()) + require.Equal(t, "2", newLabel5.GetValue()) + require.Equal(t, "2", newLabel6.GetValue()) + require.Equal(t, "2", newLabel7.GetValue()) } diff --git a/pkg/allure/parameter.go b/pkg/allure/parameter.go index a539571..8481e44 100644 --- a/pkg/allure/parameter.go +++ b/pkg/allure/parameter.go @@ -3,6 +3,7 @@ package allure import ( //"encoding/json" "fmt" + "strconv" "strings" ) @@ -42,7 +43,22 @@ func NewParameters(kv ...interface{}) []*Parameter { // GetValue returns param value as string func (p *Parameter) GetValue() string { - return strings.Trim(fmt.Sprintf("%s", p.Value), "\"") + switch v := p.Value.(type) { + case string: + return strings.Trim(v, "\"") + case int64: + return strconv.FormatInt(v, 10) + case float64: + return strconv.FormatFloat(v, 'f', -1, 64) + case bool: + return strconv.FormatBool(v) + case int: + return strconv.Itoa(v) + case float32: + return strconv.FormatFloat(float64(v), 'f', -1, 32) + default: + return strings.Trim(fmt.Sprintf("%v", v), "\"") + } } func trimBrackets(val string) string {