Skip to content

Commit

Permalink
A fix for test cases that were not executed to bug in parallelism (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
ido-namely authored Aug 25, 2022
1 parent 1ac2e8b commit 8a171e9
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions all/test/all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ type FileExpectation struct {
expectedValue string
}

type TestCase struct {
lang string
protofileName string
expectedOutputDir string
fileExpectations []FileExpectation
expectedExitCode int
extraArgs []string
}

func (f *FileExpectation) Assert(filePath string) {
if f.assert != nil {
f.assert(filePath, f.expectedValue)
Expand All @@ -39,14 +48,7 @@ func TestTestSuite(t *testing.T) {
func (s *TestSuite) SetupTest() {}

func (s *TestSuite) TestAllCases() {
testCases := map[string]struct {
lang string
protofileName string
expectedOutputDir string
fileExpectations []FileExpectation
expectedExitCode int
extraArgs []string
}{
testCases := map[string]*TestCase{
"go": {
lang: "go",
protofileName: "all/test/test.proto",
Expand Down Expand Up @@ -600,26 +602,28 @@ func (s *TestSuite) TestAllCases() {
}
src := path.Join(wd, "all")
for name, testCase := range testCases {
s.Run(name, func() {
s.T().Parallel()
dir, err := ioutil.TempDir(wd, testCase.lang)
defer os.RemoveAll(dir)
s.Require().NoError(err)
err = copy.Copy(src, path.Join(dir, "all"), opt)
argsStr := fmt.Sprintf(DockerCmd,
dir,
container,
testCase.protofileName,
testCase.lang,
)
exitCode := s.executeDocker(argsStr, testCase.extraArgs...)
s.Require().Equal(testCase.expectedExitCode, exitCode)
for _, fileExpectation := range testCase.fileExpectations {
fileFullPath := path.Join(dir, testCase.expectedOutputDir, fileExpectation.fileName)
s.Assert().FileExists(fileFullPath)
fileExpectation.Assert(fileFullPath)
}
})
func(name string, testCase *TestCase) {
s.Run(name, func() {
s.T().Parallel()
dir, err := ioutil.TempDir(wd, strings.ReplaceAll(name, " ", "_")+"_")
defer os.RemoveAll(dir)
s.Require().NoError(err)
err = copy.Copy(src, path.Join(dir, "all"), opt)
argsStr := fmt.Sprintf(DockerCmd,
dir,
container,
testCase.protofileName,
testCase.lang,
)
exitCode := s.executeDocker(argsStr, testCase.extraArgs...)
s.Require().Equal(testCase.expectedExitCode, exitCode)
for _, fileExpectation := range testCase.fileExpectations {
fileFullPath := path.Join(dir, testCase.expectedOutputDir, fileExpectation.fileName)
s.Assert().FileExists(fileFullPath)
fileExpectation.Assert(fileFullPath)
}
})
}(name, testCase)
}
}

Expand Down

0 comments on commit 8a171e9

Please sign in to comment.