test

package
v0.0.0-...-c165a09 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Copyright 2023 The Nephio Authors.

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.

Copyright 2023 The Nephio Authors.

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckExpectedOutput

func CheckExpectedOutput(t *testing.T, dir string, rl *fn.ResourceList)

func CheckResults

func CheckResults(t *testing.T, dir string, rl *fn.ResourceList)

func CheckRunError

func CheckRunError(t *testing.T, dir string, actualError error)

func MustParseKubeObject

func MustParseKubeObject(t *testing.T, path string) *fn.KubeObject

MustParseKubeObject reads one KubeObject from the given YAML file or fails the test

func MustParseKubeObjects

func MustParseKubeObjects(t *testing.T, path string) fn.KubeObjects

MustParseKubeObjects reads a list of KubeObjects from the given YAML file or fails the test

func ParseResourceListFromDir

func ParseResourceListFromDir(t *testing.T, dir string) *fn.ResourceList

ParseResourceListFromDir parses all YAML files from the given `dir`, and gives back the parsed objects in a ResourceList, or fails the test

func RunGoldenTestForPipeline

func RunGoldenTestForPipeline(t *testing.T, inputDir string, krmFunctions []fn.ResourceListProcessor, expectedDataDir string)

RunGoldenTestForPipeline tests a sequence (pipeline) of KRM functions that are applied to a kpt package one after the other, and the final output is tested against some expected output. RunGoldenTestForPipeline behaves similar to RunGoldenTests, but it runs only one testcase whose data is in `dir`. The files in `dir` are interpreted the same as by RunGoldenTests. (See details in the documentation of RunGoldenTests)

func RunGoldenTestForPipelineOfFuncs

func RunGoldenTestForPipelineOfFuncs(t *testing.T, inputDir string, krmFunctions []fn.ResourceListProcessorFunc, expectedDataDir string)

RunGoldenTestForPipelineOfFuncs calls RunGoldenTestForPipeline after converting `krmFunctions` to the expected format

func RunGoldenTests

func RunGoldenTests(t *testing.T, basedir string, krmFunction fn.ResourceListProcessor)

RunGoldenTests provides the functionality of its upstream counterpart: testhelpers.RunGoldenTests, but with some extra functionality (i.e. _expected_error.txt, _expected_results.yaml, _actual_output.yaml).

RunGoldenTests provides the test infra to run golden test. "basedir" should be the parent directory, under where each sub-directory contains data for a test case. "krmFunction" should be your ResourceListProcessor implementation that is to be tested.

For example, if "testdata" is the basedir, it contains two cases "test1" and "test2":

└── testdata
    └── test1
        ├── _expected.yaml
        ├── _fnconfig.yaml
        └── resources.yaml
    └── test2
        ├── _expected_error.txt
        ├── _expected_results.yaml
        ├── Kptfile
        ├── service.yaml
        └── deployment.yaml

The files in a test case's subdirectory are interpreted as follows:

  • YAML files whose name doesn't start with an underscore (including the Kptfile) are interpreted as parts of the input kpt package. They should contain YAML serialized KRM resources.
  • _fnconfig.yaml, if present, holds the configuration parameters of the KRM functions
  • _expected.yaml holds the expected output of the KRM function. If present, then the YAML output of the KRM function is compared to it character-by-character
  • _expected_results.yaml allows to test if certain results (typically errors) are present in the output's `Results` list without comparing the rest of the output. If present, it should contain a list of fn.Result objects, and each of them should be present in the output.
  • _expected_error.txt allows testing if the KRM function's implementation (the Run function) returned with an error. If present, then the KRM function is expected to return with an error whose message contains the string in the file. If this file is not present in a test case's subdirectory, and the KRM function returns with an error, then the test is considered failed.

After running a testcase RunGoldenTests creates a file named _actual_output.yaml in its subdirectory, containing the actual output of the KRM function. This file can be used to compare with _expected.yaml by an external diff (GUI) tool.

If the `WRITE_GOLDEN_OUTPUT` environment variable is set with a non-empty value, then the _expected.yaml file is overwritten with actual output of the KRM function.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL