Files
Packer-Cn/packer/testing.go
hashicorp-copywrite[bot] 19055df3ec [COMPLIANCE] License changes (#12568)
* Updating the license from MPL to Business Source License

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at https://hashi.co/license-faq, and details of the license at www.hashicorp.com/bsl.

* Update copyright file headers to BUSL-1.1

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-08-10 15:53:29 -07:00

83 lines
1.9 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package packer
import (
"bytes"
"io/ioutil"
"testing"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
)
func TestCoreConfig(t *testing.T) *CoreConfig {
// Create some test components
components := ComponentFinder{
PluginConfig: &PluginConfig{
Builders: MapOfBuilder{
"test": func() (packersdk.Builder, error) { return &packersdk.MockBuilder{}, nil },
},
},
}
return &CoreConfig{
Components: components,
}
}
func TestCore(t *testing.T, c *CoreConfig) *Core {
core := NewCore(c)
err := core.Initialize(InitializeOptions{})
if err != nil {
t.Fatalf("err: %s", err)
}
return core
}
func TestUi(t *testing.T) packersdk.Ui {
var buf bytes.Buffer
return &packersdk.BasicUi{
Reader: &buf,
Writer: ioutil.Discard,
ErrorWriter: ioutil.Discard,
}
}
// TestBuilder sets the builder with the name n to the component finder
// and returns the mock.
func TestBuilder(t *testing.T, c *CoreConfig, n string) *packersdk.MockBuilder {
var b packersdk.MockBuilder
c.Components.PluginConfig.Builders = MapOfBuilder{
n: func() (packersdk.Builder, error) { return &b, nil },
}
return &b
}
// TestProvisioner sets the prov. with the name n to the component finder
// and returns the mock.
func TestProvisioner(t *testing.T, c *CoreConfig, n string) *packersdk.MockProvisioner {
var b packersdk.MockProvisioner
c.Components.PluginConfig.Provisioners = MapOfProvisioner{
n: func() (packersdk.Provisioner, error) { return &b, nil },
}
return &b
}
// TestPostProcessor sets the prov. with the name n to the component finder
// and returns the mock.
func TestPostProcessor(t *testing.T, c *CoreConfig, n string) *MockPostProcessor {
var b MockPostProcessor
c.Components.PluginConfig.PostProcessors = MapOfPostProcessor{
n: func() (packersdk.PostProcessor, error) { return &b, nil },
}
return &b
}