diff --git a/init.go b/init.go index 7b57377..3c9f618 100644 --- a/init.go +++ b/init.go @@ -1,8 +1,9 @@ package allure import ( - "github.com/jtolds/gls" "sync" + + "github.com/jtolds/gls" ) var ( @@ -11,7 +12,7 @@ var ( resultsPath string createFolderOnce sync.Once copyEnvFileOnce sync.Once - testPhaseObjects map[string]*testPhaseContainer + testPhaseObjects sync.Map ) const ( @@ -25,5 +26,5 @@ const ( func init() { ctxMgr = gls.NewContextManager() - testPhaseObjects = make(map[string]*testPhaseContainer) + testPhaseObjects = sync.Map{} } diff --git a/test_phase_container.go b/test_phase_container.go index 023e438..73f1409 100644 --- a/test_phase_container.go +++ b/test_phase_container.go @@ -112,18 +112,11 @@ func (sc *subContainer) getStatus() string { } func getCurrentTestPhaseObject(t *testing.T) *testPhaseContainer { - var currentPhaseObject *testPhaseContainer - if phaseContainer, ok := testPhaseObjects[t.Name()]; ok { - currentPhaseObject = phaseContainer - } else { - currentPhaseObject = &testPhaseContainer{ - Befores: make([]*container, 0), - Afters: make([]*container, 0), - } - testPhaseObjects[t.Name()] = currentPhaseObject - } - - return currentPhaseObject + phaseContainer, _ := testPhaseObjects.LoadOrStore(t.Name(), &testPhaseContainer{ + Befores: make([]*container, 0), + Afters: make([]*container, 0), + }) + return phaseContainer.(*testPhaseContainer) } func (c container) writeResultsFile() error {