File: testing_factory.go

package info (click to toggle)
vagrant 2.3.7%2Bgit20230731.5fc64cde%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 17,616 kB
  • sloc: ruby: 111,820; sh: 462; makefile: 123; ansic: 34; lisp: 1
file content (53 lines) | stat: -rw-r--r-- 1,069 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package plugin

import (
	"github.com/hashicorp/vagrant-plugin-sdk/component"
	"github.com/mitchellh/go-testing-interface"
)

func TestMinimalPluginInstance(t testing.T) *Instance {
	inst := &Instance{
		Name: "test",
	}
	return inst
}

func TestPluginInstance(t testing.T, opts ...PluginInstanceProperty) *Instance {
	inst := TestMinimalPluginInstance(t)
	for _, opt := range opts {
		if err := opt(inst); err != nil {
			t.Error(err)
		}
	}
	return inst
}

type PluginInstanceProperty func(*Instance) error

func WithPluginInstanceName(name string) PluginInstanceProperty {
	return func(i *Instance) (err error) {
		i.Name = name
		return
	}
}

func WithPluginInstanceType(t component.Type) PluginInstanceProperty {
	return func(i *Instance) (err error) {
		i.Type = t
		return
	}
}

func WithPluginInstanceComponent(c interface{}) PluginInstanceProperty {
	return func(i *Instance) (err error) {
		i.Component = c
		return
	}
}

func WithPluginInstanceParent(p *Instance) PluginInstanceProperty {
	return func(i *Instance) (err error) {
		i.Parent = p
		return
	}
}