-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Turn cartotest Expectation into an interface * SupplyChain interface for Cartotest * Supply a set of supply chain file paths Can pass in ytt values as well * Split large file * Refactor replaceIfFound * Update cli suite expected locating * Change cartotesting workload to an interface * Turn Givens.Template into an interface * Rename interface * Rename supplychain interface * BlueprintParams as an interface * Move functions * Change method to function * Change BlueprintInputs into an interface * Blueprint Params and Inputs nested under MockSupplyChain * Move method * Change pointers on methods * Move functions * Turn SupplyChain into an interface implemented by mock and actual supply chains * Rename Expectations and Given * Rename SupplyChainFileSet * Add fields to supply chain set * Rename Expectation interface implementations * Rename Expectation fields * First passing actual supply chain test * Change specification of ytt file for cli cartotests * Nest template cli fields as they are in new template struct * Nest mockSupplyChain CLI fields * Nest metadata and givens in CLI info file * Test CLI tests with go test * Begin moving CLI TestCase Population to functions * CLI TestCase Population in function * Split cli-suite-builder file into suite and case * Rename variables * Refactor populate testCase template * Further refactor populate testCase template * Rename function * Even further refactor populate testCase template * populate TestCase SupplyChain function * Working cartotest cli with actual supply chain * Create Comparison Option Field * CompareOptions yields cmp.Options * Cartotest CLI uses compareOptions * Reorder yaml files * Lint * Cartotest CLI can leverage number conversion function * Simplify cartotest cli Deprecate the 'templates' command * Ensure targetResource references provided template * Simplify language Cartesting tests are Test rather than TemplateTestCase Similarly Suite rather than TemplateTestSuite * Convert Blueprint params/inputs to SupplyChain params/inputs
- Loading branch information
1 parent
d5a9e41
commit c3aca9b
Showing
28 changed files
with
1,808 additions
and
770 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright 2021 VMware | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package testing | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
|
||
"github.com/vmware-tanzu/cartographer/pkg/templates" | ||
) | ||
|
||
// 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 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 Test struct { | ||
Given Given | ||
Expect Expectation | ||
CompareOptions *CompareOptions | ||
Focus bool | ||
} | ||
|
||
// Given must specify a Template and a Workload. | ||
// SupplyChain is optional | ||
type Given struct { | ||
Template Template | ||
Workload Workload | ||
SupplyChain SupplyChain | ||
} | ||
|
||
func (c *Test) Run() error { | ||
expectedObject, err := c.Expect.getExpected() | ||
if err != nil { | ||
return fmt.Errorf("failed to get expected object: %w", err) | ||
} | ||
|
||
actualObject, err := c.Given.getActualObject() | ||
if errors.Is(err, yttNotFound) { | ||
return fmt.Errorf("test requires ytt, but ytt was not found in path") | ||
} else if err != nil { | ||
return fmt.Errorf("failed to get actual object: %w", err) | ||
} | ||
|
||
c.stripIgnoredFields(expectedObject, actualObject) | ||
|
||
var opts cmp.Options | ||
if c.CompareOptions != nil && c.CompareOptions.CMPOption != nil { | ||
opts, err = c.CompareOptions.CMPOption() | ||
if err != nil { | ||
return fmt.Errorf("get compare options: %w", err) | ||
} | ||
} | ||
|
||
if diff := cmp.Diff(expectedObject.Object, actualObject.Object, opts); diff != "" { | ||
return fmt.Errorf("expected does not equal actual: (-expected +actual):\n%s", diff) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (i *Given) getActualObject() (*unstructured.Unstructured, error) { | ||
ctx := context.Background() | ||
|
||
workload, err := i.Workload.GetWorkload() | ||
if err != nil { | ||
return nil, fmt.Errorf("get workload failed: %w", err) | ||
} | ||
|
||
apiTemplate, err := i.Template.GetTemplate() | ||
if err != nil { | ||
return nil, fmt.Errorf("get populated template failed: %w", err) | ||
} | ||
|
||
if err = (*apiTemplate).ValidateCreate(); err != nil { | ||
return nil, fmt.Errorf("template validation failed: %w", err) | ||
} | ||
|
||
template, err := templates.NewReaderFromAPI(*apiTemplate) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get cluster template") | ||
} | ||
|
||
if template.IsYTTTemplate() { | ||
err = ensureYTTAvailable(ctx) | ||
if err != nil { | ||
return nil, fmt.Errorf("ensure YTT available: %w", err) | ||
} | ||
} | ||
|
||
if i.SupplyChain == nil { | ||
i.SupplyChain = &MockSupplyChain{} | ||
} | ||
|
||
return i.SupplyChain.stamp(ctx, workload, *apiTemplate, template) | ||
} |
Oops, something went wrong.