From 8a171e9489276634e30a96c17c2b94fbad74bd77 Mon Sep 17 00:00:00 2001 From: Ido David <36866853+ido-namely@users.noreply.github.com> Date: Thu, 25 Aug 2022 12:28:18 -0400 Subject: [PATCH] A fix for test cases that were not executed to bug in parallelism (#324) --- all/test/all_test.go | 60 +++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/all/test/all_test.go b/all/test/all_test.go index 67dc3dc6..0eb5a864 100644 --- a/all/test/all_test.go +++ b/all/test/all_test.go @@ -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) @@ -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", @@ -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) } }