Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion pkg/allure/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package allure

import (
"fmt"
"strconv"
"strings"
)

Expand All @@ -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.
Expand Down
35 changes: 35 additions & 0 deletions pkg/allure/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
}
18 changes: 17 additions & 1 deletion pkg/allure/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package allure
import (
//"encoding/json"
"fmt"
"strconv"
"strings"
)

Expand Down Expand Up @@ -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 {
Expand Down