test

package
Version: v1.56.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: Apache-2.0, BSD-2-Clause, MIT, + 1 more Imports: 7 Imported by: 0

README

Generator test framework

The generator test framework provides a function whith the specs for a set of tests that can be reused for testing generators.

The tests are based on comparing the output of the generator for a set of pre-defined cloud-init files with a generator-specific output provided in a test file.

Each Generator implementation can use this function as shown bellow:

package my_generator_test

import (
	"embed"

	"github.com/gardener/gardener/extensions/pkg/controller/operatingsystemconfig/oscommon/generator/test"

	. "github.com/onsi/ginkgo/v2"
	. "github.com/onsi/gomega"
)

//go:embed /path/to/testfiles
var files embed.FS

var _ = Describe("My Generator Test", func(){
    Describe("Conformance Tests", 
        test.DescribeTest(NewGenerator(), files),
    )

    Describe("My other Tests", func(){
        // ...
    })
})

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DescribeTest = func(g generator.Generator, files embed.FS) func() {
	return func() {
		It("should render correctly", func() {
			expectedCloudInit, err := files.ReadFile("cloud-init")
			Expect(err).NotTo(HaveOccurred())

			cloudInit, _, err := g.Generate(logr.Discard(), &generator.OperatingSystemConfig{
				Object: &extensionsv1alpha1.OperatingSystemConfig{},
				Files: []*generator.File{
					{
						Path:        "/foo",
						Content:     []byte("bar"),
						Permissions: &onlyOwnerPerm,
					},
					{
						Path:              "/foo2",
						Content:           []byte("bar"),
						TransmitUnencoded: pointer.Bool(true),
					},
				},

				Units: []*generator.Unit{
					{
						Name:    "docker.service",
						Content: []byte("unit"),
						DropIns: []*generator.DropIn{
							{
								Name:    "10-docker-opts.conf",
								Content: []byte("override"),
							},
						},
					},
				},
				Bootstrap: true,
			})

			Expect(err).NotTo(HaveOccurred())
			Expect(cloudInit).To(Equal(expectedCloudInit))
		})
	}
}

DescribeTest returns a function which can be used in tests for the template generator implementation. It receives an instance of a template generator and embedded files with the test files to be used in the tests.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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