test

package
v0.0.0-...-ef68a79 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2019 License: Apache-2.0, MIT Imports: 4 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:

import (
	"github.com/gobuffalo/packr"
	"github.com/gardener/gardener-extensions/pkg/controller/operatingsystemconfig/os-common/generator/test"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)
         
var _ Describe("My Generator Test", func(){
      var box packr.Box

      BeforeSuite(func() {
     	box = packr.NewBox("/path/to/testfiles")
      })

      Describe("Conformance Tests", test.DescribeTest(NewGenerator(),box))

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DescribeTest = func(g generator.Generator, box packr.Box) func() {
	return func() {

		ginkgo.It("should render correctly", func() {
			expectedCloudInit, err := box.Find("cloud-init")
			gomega.Expect(err).NotTo(gomega.HaveOccurred())

			cloudInit, _, err := g.Generate(&generator.OperatingSystemConfig{
				Files: []*generator.File{
					{
						Path:        "/foo",
						Content:     []byte("bar"),
						Permissions: &onlyOwnerPerm,
					},
				},

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

			gomega.Expect(err).NotTo(gomega.HaveOccurred())
			gomega.Expect(cloudInit).To(gomega.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 a packr Box 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