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"
. "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(&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.
Click to show internal directories.
Click to hide internal directories.