Skip to content

Commit

Permalink
Simplify language
Browse files Browse the repository at this point in the history
Cartesting tests are Test rather than TemplateTestCase

Similarly Suite rather than TemplateTestSuite
  • Loading branch information
waciumawanjohi committed Jun 20, 2023
1 parent b57f9cb commit 1924034
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions pkg/testing/case.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions pkg/testing/cli-case.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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{}

Expand All @@ -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{}
Expand Down
8 changes: 4 additions & 4 deletions pkg/testing/cli-suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -50,7 +50,7 @@ func buildTestSuite(testCase *TemplateTestCase, directory string) (TemplateTestS
return testSuite, nil
}

return TemplateTestSuite{
return Suite{
directory: testCase,
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/testing/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/testing/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
18 changes: 9 additions & 9 deletions pkg/testing/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/templates/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 1924034

Please sign in to comment.