Files
Packer-Cn/command/command_test.go
T

54 lines
1.0 KiB
Go
Raw Permalink Normal View History

// Copyright (c) HashiCorp, Inc.
2023-08-10 15:53:29 -07:00
// SPDX-License-Identifier: BUSL-1.1
2014-10-28 15:09:22 -07:00
package command
import (
"bytes"
2023-09-22 15:44:03 +08:00
"os"
2014-10-28 19:29:51 -07:00
"path/filepath"
2014-10-28 15:09:22 -07:00
"testing"
2020-12-17 13:29:25 -08:00
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
2017-04-04 13:39:01 -07:00
"github.com/hashicorp/packer/packer"
2014-10-28 15:09:22 -07:00
)
2014-10-28 19:29:51 -07:00
const fixturesDir = "./test-fixtures"
func fatalCommand(t *testing.T, m Meta) {
ui := m.Ui.(*packersdk.BasicUi)
out := ui.Writer.(*bytes.Buffer)
err := ui.ErrorWriter.(*bytes.Buffer)
2014-10-28 19:29:51 -07:00
t.Fatalf(
"Bad exit code.\n\nStdout:\n\n%s\n\nStderr:\n\n%s",
out.String(),
err.String())
2014-10-28 19:29:51 -07:00
}
2020-10-02 10:49:21 +02:00
func testFixtureContent(n ...string) string {
path := filepath.Join(append([]string{fixturesDir}, n...)...)
2023-09-22 15:44:03 +08:00
b, err := os.ReadFile(path)
2020-10-02 10:49:21 +02:00
if err != nil {
panic(err)
}
return string(b)
}
func testFixture(n ...string) string {
paths := []string{fixturesDir}
paths = append(paths, n...)
return filepath.Join(paths...)
2014-10-28 19:29:51 -07:00
}
2014-10-28 15:09:22 -07:00
func testMeta(t *testing.T) Meta {
var out, err bytes.Buffer
2014-10-28 15:09:22 -07:00
return Meta{
2015-05-29 15:35:55 -07:00
CoreConfig: packer.TestCoreConfig(t),
Ui: &packersdk.BasicUi{
Writer: &out,
ErrorWriter: &err,
},
2014-10-28 15:09:22 -07:00
}
}