Skip to content

Commit

Permalink
Add attribute to ensure same eol handling on all systems, change path…
Browse files Browse the repository at this point in the history
… to filepath for proper filepath handling.
  • Loading branch information
quintush committed Mar 18, 2024
1 parent 449412c commit 7f86d8b
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ensure lf on all machines to ensure identical snapshot outputs
* text eol=lf
8 changes: 4 additions & 4 deletions pkg/unittest/formatter/junit_report_xml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/xml"
"fmt"
"os"
"path"
"path/filepath"
"testing"

. "github.com/helm-unittest/helm-unittest/pkg/unittest/formatter"
Expand Down Expand Up @@ -117,7 +117,7 @@ func assertJUnitProperty(assert *assert.Assertions, expected, actual []JUnitProp

func TestWriteTestOutputAsJUnitMinimalSuccess(t *testing.T) {
assert := assert.New(t)
outputFile := path.Join(tmpJUnitTestDir, "JUnit_Test_Output.xml")
outputFile := filepath.Join(tmpJUnitTestDir, "JUnit_Test_Output.xml")
testSuiteDisplayName := "TestingSuite"
testCaseDisplayName := "TestCaseSucces"

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

func TestWriteTestOutputAsJUnitWithFailures(t *testing.T) {
assert := assert.New(t)
outputFile := path.Join(tmpJUnitTestDir, "JUnit_Test_Failure_Output.xml")
outputFile := filepath.Join(tmpJUnitTestDir, "JUnit_Test_Failure_Output.xml")
testSuiteDisplayName := "TestingSuite"
testCaseSuccessDisplayName := "TestCaseSuccess"
testCaseFailureDisplayName := "TestCaseFailure"
Expand Down Expand Up @@ -212,7 +212,7 @@ func TestWriteTestOutputAsJUnitWithFailures(t *testing.T) {

func TestWriteTestOutputAsJUnitWithFailuresAndErrors(t *testing.T) {
assert := assert.New(t)
outputFile := path.Join(tmpJUnitTestDir, "JUnit_Test_FailureError_Output.xml")
outputFile := filepath.Join(tmpJUnitTestDir, "JUnit_Test_FailureError_Output.xml")
testSuiteDisplayName := "TestingSuite"
testCaseSuccessDisplayName := "TestCaseSuccess"
testCaseFailureDisplayName := "TestCaseFailure"
Expand Down
10 changes: 5 additions & 5 deletions pkg/unittest/formatter/nunit_report_xml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/xml"
"fmt"
"os"
"path"
"path/filepath"
"testing"

. "github.com/helm-unittest/helm-unittest/pkg/unittest/formatter"
Expand Down Expand Up @@ -97,7 +97,7 @@ func validatNUnitTestCase(assert *assert.Assertions, expected, actual []NUnitTes

func TestWriteTestOutputAsNUnitMinimalSuccess(t *testing.T) {
assert := assert.New(t)
outputFile := path.Join(tmpNunitTestDir, "NUnit_Test_Output.xml")
outputFile := filepath.Join(tmpNunitTestDir, "NUnit_Test_Output.xml")
testSuiteDisplayName := "TestingSuite"
testCaseDisplayName := "TestCaseSucces"

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

func TestWriteTestOutputAsNUnitWithFailures(t *testing.T) {
assert := assert.New(t)
outputFile := path.Join(tmpNunitTestDir, "NUnit_Test_Failure_Output.xml")
outputFile := filepath.Join(tmpNunitTestDir, "NUnit_Test_Failure_Output.xml")
testSuiteDisplayName := "TestingSuite"
testCaseSuccessDisplayName := "TestCaseSuccess"
testCaseFailureDisplayName := "TestCaseFailure"
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestWriteTestOutputAsNUnitWithFailures(t *testing.T) {

func TestWriteTestOutputAsNUnitWithFailuresAndErrors(t *testing.T) {
assert := assert.New(t)
outputFile := path.Join(tmpNunitTestDir, "NUnit_Test_Failure_And_Errors_Output.xml")
outputFile := filepath.Join(tmpNunitTestDir, "NUnit_Test_Failure_And_Errors_Output.xml")
testSuiteDisplayName := "TestingSuite"
testCaseSuccessDisplayName := "TestCaseSuccess"
testCaseFailureDisplayName := "TestCaseFailure"
Expand Down Expand Up @@ -306,7 +306,7 @@ func TestWriteTestOutputAsNUnitWithFailuresAndErrors(t *testing.T) {

func TestWriteTestOutputAsNUnitWithErrors(t *testing.T) {
assert := assert.New(t)
outputFile := path.Join(tmpNunitTestDir, "NUnit_Test_Errors_Output.xml")
outputFile := filepath.Join(tmpNunitTestDir, "NUnit_Test_Errors_Output.xml")
testSuiteDisplayName := "TestingSuite"
errorMessage := "Throw an error."

Expand Down
13 changes: 7 additions & 6 deletions pkg/unittest/formatter/sonar_report_xml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package formatter_test

import (
"encoding/xml"
"path/filepath"
"testing"
"time"

. "github.com/helm-unittest/helm-unittest/pkg/unittest/formatter"
"github.com/helm-unittest/helm-unittest/pkg/unittest/results"
"github.com/stretchr/testify/assert"
"path"
"testing"
"time"
)

func createSonarTestCase(name string, duration string, isError bool, isFailed bool) SonarTestCase {
Expand Down Expand Up @@ -48,7 +49,7 @@ func validateSonarTestCases(assert *assert.Assertions, expected, actual []SonarT

func TestWriteTestOutputAsSonarNoTests(t *testing.T) {
_assert := assert.New(t)
outputFile := path.Join(tmpNunitTestDir, "Sonar_Test_Output.xml")
outputFile := filepath.Join(tmpNunitTestDir, "Sonar_Test_Output.xml")

expected := SonarTestExecutions{
Version: 1,
Expand All @@ -72,7 +73,7 @@ func TestWriteTestOutputAsSonarNoTests(t *testing.T) {

func TestWriteTestOutputAsSonarMinimalSuccess(t *testing.T) {
_assert := assert.New(t)
outputFile := path.Join(tmpNunitTestDir, "Sonar_Test_Output.xml")
outputFile := filepath.Join(tmpNunitTestDir, "Sonar_Test_Output.xml")
testSuiteDisplayName := "TestingSuiteSuccess"
testCaseDisplayName := "TestCaseSuccessSuccess"

Expand Down Expand Up @@ -120,7 +121,7 @@ func TestWriteTestOutputAsSonarMinimalSuccess(t *testing.T) {

func TestWriteTestOutputAsSonarWithErrorsAndFailures(t *testing.T) {
_assert := assert.New(t)
outputFile := path.Join(tmpNunitTestDir, "Sonar_Test_Output.xml")
outputFile := filepath.Join(tmpNunitTestDir, "Sonar_Test_Output.xml")
testSuiteDisplayName := "TestingSuiteFailuresAndErrors"
testCaseDisplayNameError := "TestCaseError"
testCaseDisplayNameFailure := "TestCaseFailure"
Expand Down
10 changes: 5 additions & 5 deletions pkg/unittest/formatter/xunit_report_xml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/xml"
"fmt"
"os"
"path"
"path/filepath"
"testing"

. "github.com/helm-unittest/helm-unittest/pkg/unittest/formatter"
Expand Down Expand Up @@ -117,7 +117,7 @@ func assertXUnitTestCase(assert *assert.Assertions, expected, actual []XUnitTest

func TestWriteTestOutputAsXUnitMinimalSuccess(t *testing.T) {
assert := assert.New(t)
outputFile := path.Join(tmpXunitTestDir, "XUnit_Test_Output.xml")
outputFile := filepath.Join(tmpXunitTestDir, "XUnit_Test_Output.xml")
testSuiteDisplayName := "TestingSuite"
testCaseDisplayName := "TestCaseSucces"
totalTests := 1
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestWriteTestOutputAsXUnitMinimalSuccess(t *testing.T) {

func TestWriteTestOutputAsXUnitWithFailures(t *testing.T) {
assert := assert.New(t)
outputFile := path.Join(tmpXunitTestDir, "XUnit_Test_Failure_Output.xml")
outputFile := filepath.Join(tmpXunitTestDir, "XUnit_Test_Failure_Output.xml")
testSuiteDisplayName := "TestingSuite"
testCaseSuccessDisplayName := "TestCaseSuccess"
testCaseFailureDisplayName := "TestCaseFailure"
Expand Down Expand Up @@ -242,7 +242,7 @@ func TestWriteTestOutputAsXUnitWithFailures(t *testing.T) {

func TestWriteTestOutputAsXUnitWithFailuresAndErrors(t *testing.T) {
assert := assert.New(t)
outputFile := path.Join(tmpXunitTestDir, "XUnit_Test_Failure_And_Error_Output.xml")
outputFile := filepath.Join(tmpXunitTestDir, "XUnit_Test_Failure_And_Error_Output.xml")
testSuiteDisplayName := "TestingSuite"
testCaseSuccessDisplayName := "TestCaseSuccess"
testCaseFailureDisplayName := "TestCaseFailure"
Expand Down Expand Up @@ -315,7 +315,7 @@ func TestWriteTestOutputAsXUnitWithFailuresAndErrors(t *testing.T) {

func TestWriteTestOutputAsXUnitWithErrors(t *testing.T) {
assert := assert.New(t)
outputFile := path.Join(tmpXunitTestDir, "XUnit_Test_Error_Output.xml")
outputFile := filepath.Join(tmpXunitTestDir, "XUnit_Test_Error_Output.xml")
testSuiteDisplayName := "TestingSuite"
errorMessage := "An Error Occurred."
totalTests := 1
Expand Down
3 changes: 1 addition & 2 deletions pkg/unittest/test_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"io"
"os"
"path"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -247,7 +246,7 @@ func (t *TestJob) getUserValues() ([]byte, error) {
for _, specifiedPath := range t.Values {
value := map[string]interface{}{}
var valueFilePath string
if path.IsAbs(specifiedPath) {
if filepath.IsAbs(specifiedPath) {
valueFilePath = specifiedPath
} else {
valueFilePath = filepath.Join(filepath.Dir(t.definitionFile), specifiedPath)
Expand Down
7 changes: 6 additions & 1 deletion pkg/unittest/test_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,10 @@ asserts:
documentIndex: 0
template: templates/deployment.yaml
`
file, _ := os.CreateTemp("", "testjob_test_TestRunJobWithValuesFile.yaml")

file, _ := os.Create("testjob_test_TestRunJobWithValuesFile.yaml")
file.WriteString("nameOverride: mary-jane")
file.Close()

var tj TestJob
yaml.Unmarshal([]byte(fmt.Sprintf(manifest, file.Name())), &tj)
Expand All @@ -347,9 +349,12 @@ asserts:
a := assert.New(t)
cupaloy.SnapshotT(t, makeTestJobResultSnapshotable(testResult))

a.FileExists(file.Name())
a.Nil(testResult.ExecError)
a.True(testResult.Passed)
a.Equal(1, len(testResult.AssertsResult))

os.Remove(file.Name())
}

func TestV3RunJobWithReleaseSettings(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/unittest/test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"time"

Expand Down Expand Up @@ -155,7 +154,7 @@ func (tr *TestRunner) getTestSuites(chartPath, chartRoute string) ([]*TestSuite,

var renderedTestSuites []*TestSuite
if len(tr.ChartTestsPath) > 0 {
helmTestsPath := path.Join(chartPath, tr.ChartTestsPath)
helmTestsPath := filepath.Join(chartPath, tr.ChartTestsPath)
// Verify that there is a tests path - in the event of mixed testing environments
if _, err := os.Stat(helmTestsPath); errors.Is(err, nil) {
var renderErr error
Expand Down
5 changes: 2 additions & 3 deletions pkg/unittest/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io"
"log"
"os"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -63,7 +62,7 @@ func createTestSuite(suiteFilePath string, chartRoute string, content string, st

// RenderTestSuiteFiles renders a helm suite of test files and returns their TestSuites
func RenderTestSuiteFiles(helmTestSuiteDir string, chartRoute string, strict bool, valueFilesSet []string, renderValues map[string]interface{}) ([]*TestSuite, error) {
testChartPath := path.Join(helmTestSuiteDir, "Chart.yaml")
testChartPath := filepath.Join(helmTestSuiteDir, "Chart.yaml")

// Ensure there's a helm file
if _, err := os.Stat(testChartPath); err != nil {
Expand Down Expand Up @@ -117,7 +116,7 @@ func iterateAllKeys(renderedFiles map[string]string, chartName, helmTestSuiteDir
}

templateFilePath := strings.Replace(templateName, chartName, "", 1)
absPath := path.Join(helmTestSuiteDir, templateFilePath)
absPath := filepath.Join(helmTestSuiteDir, templateFilePath)

var subYamlErrs []error
var previousSuitesLen int
Expand Down

0 comments on commit 7f86d8b

Please sign in to comment.