From 192403407444183287faed04fe1df490fea28d6e Mon Sep 17 00:00:00 2001 From: Waciuma Wanjohi Date: Wed, 14 Jun 2023 13:37:17 -0400 Subject: [PATCH] Simplify language Cartesting tests are Test rather than TemplateTestCase Similarly Suite rather than TemplateTestSuite --- pkg/testing/case.go | 8 ++++---- pkg/testing/cli-case.go | 12 ++++++------ pkg/testing/cli-suite.go | 8 ++++---- pkg/testing/cli.go | 2 +- pkg/testing/compare.go | 2 +- pkg/testing/suite.go | 18 +++++++++--------- tests/templates/template_test.go | 2 +- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/pkg/testing/case.go b/pkg/testing/case.go index ceef1b777..07b7a5d9f 100644 --- a/pkg/testing/case.go +++ b/pkg/testing/case.go @@ -25,13 +25,13 @@ import ( "github.com/vmware-tanzu/cartographer/pkg/templates" ) -// TemplateTestCase is an individual template test. +// Test is an individual template test. // Given and Expect values must be provided. // Fields in the expected object's metadata may be ignored -// When run as part of a TemplateTestSuite, an individual case(s) may be focused. +// When run as part of a Suite, an individual case(s) may be focused. // This will exercise the individual test(s). // Note that the overall suite will fail (preventing focused tests from passing CI). -type TemplateTestCase struct { +type Test struct { Given Given Expect Expectation CompareOptions *CompareOptions @@ -46,7 +46,7 @@ type Given struct { SupplyChain SupplyChain } -func (c *TemplateTestCase) Run() error { +func (c *Test) Run() error { expectedObject, err := c.Expect.getExpected() if err != nil { return fmt.Errorf("failed to get expected object: %w", err) diff --git a/pkg/testing/cli-case.go b/pkg/testing/cli-case.go index be46b33ed..a6588615c 100644 --- a/pkg/testing/cli-case.go +++ b/pkg/testing/cli-case.go @@ -79,7 +79,7 @@ const ( supplyChainYttValuesDefaultFilename = "supply-chain-ytt-values.yaml" ) -func populateTestCase(testCase *TemplateTestCase, directory string) (*TemplateTestCase, error) { +func populateTestCase(testCase *Test, directory string) (*Test, error) { info, err := populateInfo(directory) if err != nil { return nil, fmt.Errorf("populate info: %w", err) @@ -127,7 +127,7 @@ func populateTestCase(testCase *TemplateTestCase, directory string) (*TemplateTe return testCase, nil } -func populateCompareOptions(testCase *TemplateTestCase, info *testInfo) *TemplateTestCase { +func populateCompareOptions(testCase *Test, info *testInfo) *Test { if info.CompareOptions.IgnoreMetadata != nil { if testCase.CompareOptions == nil { testCase.CompareOptions = &CompareOptions{} @@ -165,7 +165,7 @@ func populateCompareOptions(testCase *TemplateTestCase, info *testInfo) *Templat return testCase } -func populateTestCaseWorkload(testCase *TemplateTestCase, directory string, info *testInfo) (*TemplateTestCase, error) { +func populateTestCaseWorkload(testCase *Test, directory string, info *testInfo) (*Test, error) { newWorkloadValue, err := getLocallySpecifiedPath(directory, workloadDefaultFilename, info.Given.Workload) if err != nil { return nil, fmt.Errorf("get workload file specified in directory %s: %w", directory, err) @@ -176,7 +176,7 @@ func populateTestCaseWorkload(testCase *TemplateTestCase, directory string, info return testCase, nil } -func populateTestCaseTemplate(testCase *TemplateTestCase, directory string, info *testInfo) (*TemplateTestCase, error) { +func populateTestCaseTemplate(testCase *Test, directory string, info *testInfo) (*Test, error) { newTemplateFile := TemplateFile{} if previousTemplateFile, prevTemplateFileExisted := testCase.Given.Template.(*TemplateFile); prevTemplateFileExisted { @@ -204,7 +204,7 @@ func populateTestCaseTemplate(testCase *TemplateTestCase, directory string, info return testCase, nil } -func populateTestCaseMockSupplyChain(testCase *TemplateTestCase, info *testInfo) (*TemplateTestCase, bool) { +func populateTestCaseMockSupplyChain(testCase *Test, info *testInfo) (*Test, bool) { var mockSupplyChainSpecified bool mockSupplyChain := MockSupplyChain{} @@ -223,7 +223,7 @@ func populateTestCaseMockSupplyChain(testCase *TemplateTestCase, info *testInfo) return testCase, mockSupplyChainSpecified } -func populateTestCaseSupplyChain(testCase *TemplateTestCase, directory string, info *testInfo) (*TemplateTestCase, bool, error) { +func populateTestCaseSupplyChain(testCase *Test, directory string, info *testInfo) (*Test, bool, error) { var supplyChainSpecified bool newSupplyChain := SupplyChainFileSet{} diff --git a/pkg/testing/cli-suite.go b/pkg/testing/cli-suite.go index e174fd340..fa27dc7eb 100644 --- a/pkg/testing/cli-suite.go +++ b/pkg/testing/cli-suite.go @@ -20,7 +20,7 @@ import ( "path/filepath" ) -func buildTestSuite(testCase *TemplateTestCase, directory string) (TemplateTestSuite, error) { +func buildTestSuite(testCase *Test, directory string) (Suite, error) { var err error testCase, err = populateTestCase(testCase, directory) @@ -35,10 +35,10 @@ func buildTestSuite(testCase *TemplateTestCase, directory string) (TemplateTestS // recurse if len(subdirectories) > 0 { - testSuite := make(TemplateTestSuite) + testSuite := make(Suite) for _, subdirectory := range subdirectories { newCase := *testCase - var tempTestSuite TemplateTestSuite + var tempTestSuite Suite tempTestSuite, err = buildTestSuite(&newCase, filepath.Join(directory, subdirectory)) if err != nil { return nil, fmt.Errorf("failed building test case for subdirectory: %s: %w", subdirectory, err) @@ -50,7 +50,7 @@ func buildTestSuite(testCase *TemplateTestCase, directory string) (TemplateTestS return testSuite, nil } - return TemplateTestSuite{ + return Suite{ directory: testCase, }, nil } diff --git a/pkg/testing/cli.go b/pkg/testing/cli.go index fb7189136..03d5c57d2 100644 --- a/pkg/testing/cli.go +++ b/pkg/testing/cli.go @@ -109,7 +109,7 @@ Read more at cartographer.sh`, } func CliTest(directory string) error { - baseTestCase := TemplateTestCase{} + baseTestCase := Test{} testSuite, err := buildTestSuite(&baseTestCase, directory) if err != nil { return fmt.Errorf("build test cases: %w", err) diff --git a/pkg/testing/compare.go b/pkg/testing/compare.go index e6f32d2a3..7fc53dc51 100644 --- a/pkg/testing/compare.go +++ b/pkg/testing/compare.go @@ -31,7 +31,7 @@ type CompareOptions struct { type CMPOption func() (cmp.Options, error) -func (c *TemplateTestCase) stripIgnoredFields(expected *unstructured.Unstructured, actual *unstructured.Unstructured) { +func (c *Test) stripIgnoredFields(expected *unstructured.Unstructured, actual *unstructured.Unstructured) { delete(expected.Object, "status") delete(actual.Object, "status") diff --git a/pkg/testing/suite.go b/pkg/testing/suite.go index 622913217..96e1d720d 100644 --- a/pkg/testing/suite.go +++ b/pkg/testing/suite.go @@ -16,18 +16,18 @@ package testing import "testing" -// TemplateTestSuite is a collection of named template tests which may be run together -type TemplateTestSuite map[string]*TemplateTestCase +// Suite is a collection of named template tests which may be run together +type Suite map[string]*Test type FailedTest struct { name string err error } -// Assert allows testing a TemplateTestSuite when a *testing.T is not available, +// Assert allows testing a Suite when a *testing.T is not available, // e.g. when tests are not run from 'go test' // It returns a list of the named tests that passed and a list of the named tests that failed with their errors -func (s *TemplateTestSuite) Assert() ([]string, []*FailedTest) { +func (s *Suite) Assert() ([]string, []*FailedTest) { var ( passedTests []string failedTests []*FailedTest @@ -47,12 +47,12 @@ func (s *TemplateTestSuite) Assert() ([]string, []*FailedTest) { return passedTests, failedTests } -func (s *TemplateTestSuite) HasFocusedTests() bool { +func (s *Suite) HasFocusedTests() bool { _, focused := s.getTestsToRun() return focused } -func (s *TemplateTestSuite) Run(t *testing.T) { +func (s *Suite) Run(t *testing.T) { testsToRun, focused := s.getTestsToRun() if focused { @@ -70,7 +70,7 @@ func (s *TemplateTestSuite) Run(t *testing.T) { } } -func (s *TemplateTestSuite) RunConcurrently(t *testing.T) { +func (s *Suite) RunConcurrently(t *testing.T) { testsToRun, focused := s.getTestsToRun() if focused { @@ -89,10 +89,10 @@ func (s *TemplateTestSuite) RunConcurrently(t *testing.T) { } } -func (s *TemplateTestSuite) getTestsToRun() (TemplateTestSuite, bool) { +func (s *Suite) getTestsToRun() (Suite, bool) { focused := false testsToRun := *s - focusedCases := make(map[string]*TemplateTestCase, len(*s)) + focusedCases := make(map[string]*Test, len(*s)) for name, testCase := range *s { if testCase.Focus { diff --git a/tests/templates/template_test.go b/tests/templates/template_test.go index 4fa331abe..29329af4b 100644 --- a/tests/templates/template_test.go +++ b/tests/templates/template_test.go @@ -59,7 +59,7 @@ func TestTemplateExample(t *testing.T) { expectedUnstructured := createExpectedUnstructured() - testSuite := cartotesting.TemplateTestSuite{ + testSuite := cartotesting.Suite{ "template, workload and expected defined in files": { Given: cartotesting.Given{ Template: &cartotesting.TemplateFile{