Skip to content

Commit

Permalink
[v0.6.29] fix label parsing if label value is number
Browse files Browse the repository at this point in the history
  • Loading branch information
koodeex committed Oct 16, 2023
1 parent 9ab5c91 commit b0a00bd
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 79 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ replace (

require (
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733
github.com/ozontech/allure-go/pkg/allure v0.6.11
github.com/ozontech/allure-go/pkg/framework v0.6.28
github.com/ozontech/allure-go/pkg/allure v0.6.12
github.com/ozontech/allure-go/pkg/framework v0.6.29
)

require (
Expand Down
14 changes: 12 additions & 2 deletions pkg/allure/label.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
package allure

import (
"fmt"
"strings"
)

// Label is the implementation of the label.
// A label is an entity used by Allure to make metrics and grouping of tests.
type Label struct {
Name string `json:"name"` // Label's name
Value string `json:"value"` // Label's value
Name string `json:"name"` // Label's name
Value interface{} `json:"value"` // Label's value
}

// GetValue returns label value as string
func (l *Label) GetValue() string {
return strings.Trim(fmt.Sprintf("%s", l.Value), "\"")
}

// NewLabel - builds and returns a new allure.Label. The label key depends on the passed LabelType.
Expand Down
34 changes: 17 additions & 17 deletions pkg/allure/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,21 @@ func TestLabelCreation(t *testing.T) {
require.Equal(t, lead.Name, Lead.ToString())
require.Equal(t, idAllure.Name, AllureID.ToString())

require.Equal(t, "epicTest", epic.Value)
require.Equal(t, "featureTest", feature.Value)
require.Equal(t, "storyTest", story.Value)
require.Equal(t, "idTest", as_id.Value)
require.Equal(t, BLOCKER.ToString(), severity.Value)
require.Equal(t, "parentSuiteTest", parentSuite.Value)
require.Equal(t, "suiteTest", suite.Value)
require.Equal(t, "subSuiteTest", subsuite.Value)
require.Equal(t, "packageTest", _package.Value)
require.Equal(t, "threadTest", thread.Value)
require.Equal(t, "hostTest", host.Value)
require.Equal(t, "tagTest", tag.Value)
require.Equal(t, "frameWorkTest", framework.Value)
require.Equal(t, "languageTest", language.Value)
require.Equal(t, "ownerTest", owner.Value)
require.Equal(t, "leadTest", lead.Value)
require.Equal(t, "idAllureTest", idAllure.Value)
require.Equal(t, "epicTest", epic.GetValue())
require.Equal(t, "featureTest", feature.GetValue())
require.Equal(t, "storyTest", story.GetValue())
require.Equal(t, "idTest", as_id.GetValue())
require.Equal(t, BLOCKER.ToString(), severity.GetValue())
require.Equal(t, "parentSuiteTest", parentSuite.GetValue())
require.Equal(t, "suiteTest", suite.GetValue())
require.Equal(t, "subSuiteTest", subsuite.GetValue())
require.Equal(t, "packageTest", _package.GetValue())
require.Equal(t, "threadTest", thread.GetValue())
require.Equal(t, "hostTest", host.GetValue())
require.Equal(t, "tagTest", tag.GetValue())
require.Equal(t, "frameWorkTest", framework.GetValue())
require.Equal(t, "languageTest", language.GetValue())
require.Equal(t, "ownerTest", owner.GetValue())
require.Equal(t, "leadTest", lead.GetValue())
require.Equal(t, "idAllureTest", idAllure.GetValue())
}
44 changes: 22 additions & 22 deletions pkg/allure/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestNewResult(t *testing.T) {
require.Equal(t, getMD5Hash(getMD5Hash(testFullName)), result.HistoryID)
require.Len(t, result.Labels, 1)
require.Equal(t, Language.ToString(), result.Labels[0].Name)
require.Equal(t, runtime.Version(), result.Labels[0].Value)
require.Equal(t, runtime.Version(), result.Labels[0].GetValue())
require.Equal(t, now, result.Start)
}

Expand All @@ -43,7 +43,7 @@ func TestResult_GetLabel(t *testing.T) {
require.NotNil(t, langLabel)
require.Len(t, langLabel, 1)
require.Equal(t, Language.ToString(), langLabel[0].Name)
require.Equal(t, runtime.Version(), langLabel[0].Value)
require.Equal(t, runtime.Version(), langLabel[0].GetValue())
}

func TestResult_Begin(t *testing.T) {
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestResult_WithFrameWork(t *testing.T) {
require.NotNil(t, label)
require.Len(t, label, 1)
require.Equal(t, Framework.ToString(), label[0].Name)
require.Equal(t, labelValue, label[0].Value)
require.Equal(t, labelValue, label[0].GetValue())
}

func TestResult_WithHost(t *testing.T) {
Expand All @@ -89,7 +89,7 @@ func TestResult_WithHost(t *testing.T) {
require.NotNil(t, label)
require.Len(t, label, 1)
require.Equal(t, Host.ToString(), label[0].Name)
require.Equal(t, labelValue, label[0].Value)
require.Equal(t, labelValue, label[0].GetValue())
}

func TestResult_WithLanguage(t *testing.T) {
Expand All @@ -101,7 +101,7 @@ func TestResult_WithLanguage(t *testing.T) {
require.NotNil(t, label)
require.Len(t, label, 1)
require.Equal(t, Language.ToString(), label[0].Name)
require.Equal(t, labelValue, label[0].Value)
require.Equal(t, labelValue, label[0].GetValue())
}

func TestResult_WithPackage(t *testing.T) {
Expand All @@ -113,7 +113,7 @@ func TestResult_WithPackage(t *testing.T) {
require.NotNil(t, label)
require.Len(t, label, 1)
require.Equal(t, Package.ToString(), label[0].Name)
require.Equal(t, labelValue, label[0].Value)
require.Equal(t, labelValue, label[0].GetValue())
}

func TestResult_WithParentSuite(t *testing.T) {
Expand All @@ -125,7 +125,7 @@ func TestResult_WithParentSuite(t *testing.T) {
require.NotNil(t, label)
require.Len(t, label, 1)
require.Equal(t, ParentSuite.ToString(), label[0].Name)
require.Equal(t, labelValue, label[0].Value)
require.Equal(t, labelValue, label[0].GetValue())
}

func TestResult_WithSuite(t *testing.T) {
Expand All @@ -137,7 +137,7 @@ func TestResult_WithSuite(t *testing.T) {
require.NotNil(t, label)
require.Len(t, label, 1)
require.Equal(t, Suite.ToString(), label[0].Name)
require.Equal(t, labelValue, label[0].Value)
require.Equal(t, labelValue, label[0].GetValue())
}

func TestResult_WithSubSuites(t *testing.T) {
Expand All @@ -150,9 +150,9 @@ func TestResult_WithSubSuites(t *testing.T) {
require.NotNil(t, label)
require.Len(t, label, 2)
require.Equal(t, SubSuite.ToString(), label[0].Name)
require.Equal(t, labelValue1, label[0].Value)
require.Equal(t, labelValue1, label[0].GetValue())
require.Equal(t, SubSuite.ToString(), label[1].Name)
require.Equal(t, labelValue2, label[1].Value)
require.Equal(t, labelValue2, label[1].GetValue())
}

func TestResult_WithThread(t *testing.T) {
Expand All @@ -164,7 +164,7 @@ func TestResult_WithThread(t *testing.T) {
require.NotNil(t, label)
require.Len(t, label, 1)
require.Equal(t, Thread.ToString(), label[0].Name)
require.Equal(t, labelValue, label[0].Value)
require.Equal(t, labelValue, label[0].GetValue())
}

func TestResult_SetStatusMessage(t *testing.T) {
Expand Down Expand Up @@ -211,9 +211,9 @@ func TestResult_SetLabel(t *testing.T) {
require.NotNil(t, label)
require.Len(t, label, 2)
require.Equal(t, Framework.ToString(), label[0].Name)
require.Equal(t, labelValue1, label[0].Value)
require.Equal(t, labelValue1, label[0].GetValue())
require.Equal(t, Host.ToString(), label[1].Name)
require.Equal(t, labelValue2, label[1].Value)
require.Equal(t, labelValue2, label[1].GetValue())
}

func TestResult_SetNewLabelMap(t *testing.T) {
Expand All @@ -230,13 +230,13 @@ func TestResult_SetNewLabelMap(t *testing.T) {
require.NotNil(t, labelFramework)
require.Len(t, labelFramework, 1)
require.Equal(t, Framework.ToString(), labelFramework[0].Name)
require.Equal(t, labelValue1, labelFramework[0].Value)
require.Equal(t, labelValue1, labelFramework[0].GetValue())

labelHost := result.GetLabels(Host)
require.NotNil(t, labelFramework)
require.Len(t, labelFramework, 1)
require.Equal(t, Host.ToString(), labelHost[0].Name)
require.Equal(t, labelValue2, labelHost[0].Value)
require.Equal(t, labelValue2, labelHost[0].GetValue())
}

func TestResult_WithLaunchTags_noTags(t *testing.T) {
Expand All @@ -255,9 +255,9 @@ func TestResult_WithLaunchTags_withTags(t *testing.T) {
labels := result.GetLabels(Tag)
require.Len(t, labels, 2)
require.Equal(t, Tag.ToString(), labels[0].Name)
require.Equal(t, "tag1", labels[0].Value)
require.Equal(t, "tag1", labels[0].GetValue())
require.Equal(t, Tag.ToString(), labels[1].Name)
require.Equal(t, "tag2", labels[1].Value)
require.Equal(t, "tag2", labels[1].GetValue())
}

func TestResult_WithLabels(t *testing.T) {
Expand All @@ -272,9 +272,9 @@ func TestResult_WithLabels(t *testing.T) {
labels := result.Labels
require.Len(t, labels, 2)
require.Equal(t, Framework.ToString(), labels[0].Name)
require.Equal(t, labelValue1, labels[0].Value)
require.Equal(t, labelValue1, labels[0].GetValue())
require.Equal(t, Language.ToString(), labels[1].Name)
require.Equal(t, labelValue2, labels[1].Value)
require.Equal(t, labelValue2, labels[1].GetValue())
}

func TestResult_PrintAttachments(t *testing.T) {
Expand Down Expand Up @@ -333,7 +333,7 @@ func TestResult_Print(t *testing.T) {

require.Len(t, emptyResult.Labels, 1)
require.Equal(t, result.Labels[0].Name, emptyResult.Labels[0].Name)
require.Equal(t, result.Labels[0].Value, emptyResult.Labels[0].Value)
require.Equal(t, result.Labels[0].GetValue(), emptyResult.Labels[0].GetValue())
require.Equal(t, result.Start, emptyResult.Start)
}

Expand Down Expand Up @@ -385,7 +385,7 @@ func TestResult_Print_withAttachment(t *testing.T) {

require.Len(t, emptyResult.Labels, 1)
require.Equal(t, result.Labels[0].Name, emptyResult.Labels[0].Name)
require.Equal(t, result.Labels[0].Value, emptyResult.Labels[0].Value)
require.Equal(t, result.Labels[0].GetValue(), emptyResult.Labels[0].GetValue())
require.Equal(t, result.Start, emptyResult.Start)

attachFile, _ := os.Open(fmt.Sprintf("%s/%s", allureDir, attachByte.Name()))
Expand Down Expand Up @@ -441,7 +441,7 @@ func TestResult_Done(t *testing.T) {

require.Len(t, emptyResult.Labels, 1)
require.Equal(t, result.Labels[0].Name, emptyResult.Labels[0].Name)
require.Equal(t, result.Labels[0].Value, emptyResult.Labels[0].Value)
require.Equal(t, result.Labels[0].GetValue(), emptyResult.Labels[0].GetValue())
require.Equal(t, result.Start, emptyResult.Start)
require.Equal(t, now, emptyResult.Stop)

Expand Down
14 changes: 7 additions & 7 deletions pkg/framework/core/allure_manager/adapter/test_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ func TestNewTestMeta(t *testing.T) {
require.Equal(t, "fullName/testName", adapter.GetResult().FullName)

require.Len(t, adapter.GetResult().GetLabels(allure.Host), 1)
require.Equal(t, adapter.GetResult().GetLabels(allure.Host)[0].Value, host)
require.Equal(t, adapter.GetResult().GetLabels(allure.Host)[0].GetValue(), host)

require.Len(t, adapter.GetResult().GetLabels(allure.Framework), 1)
require.Equal(t, adapter.GetResult().GetLabels(allure.Framework)[0].Value, allure.DefaultVersion)
require.Equal(t, adapter.GetResult().GetLabels(allure.Framework)[0].GetValue(), allure.DefaultVersion)

require.Len(t, adapter.GetResult().GetLabels(allure.Thread), 1)
require.Equal(t, "fullName/testName", adapter.GetResult().GetLabels(allure.Thread)[0].Value)
require.Equal(t, "fullName/testName", adapter.GetResult().GetLabels(allure.Thread)[0].GetValue())

require.Len(t, adapter.GetResult().GetLabels(allure.Suite), 1)
require.Equal(t, "suiteName", adapter.GetResult().GetLabels(allure.Suite)[0].Value)
require.Equal(t, "suiteName", adapter.GetResult().GetLabels(allure.Suite)[0].GetValue())

require.Len(t, adapter.GetResult().GetLabels(allure.Package), 1)
require.Equal(t, "packageName", adapter.GetResult().GetLabels(allure.Package)[0].Value)
require.Equal(t, "packageName", adapter.GetResult().GetLabels(allure.Package)[0].GetValue())

require.Len(t, adapter.GetResult().GetLabels(allure.Tag), 2)
require.Equal(t, "tag1", adapter.GetResult().GetLabels(allure.Tag)[0].Value)
require.Equal(t, "tag2", adapter.GetResult().GetLabels(allure.Tag)[1].Value)
require.Equal(t, "tag1", adapter.GetResult().GetLabels(allure.Tag)[0].GetValue())
require.Equal(t, "tag2", adapter.GetResult().GetLabels(allure.Tag)[1].GetValue())

}

Expand Down
Loading

0 comments on commit b0a00bd

Please sign in to comment.