mirror of https://github.com/hashicorp/terraform
parent
d7a1f3dc0e
commit
76f5f1057e
@ -0,0 +1,5 @@
|
||||
package terraform
|
||||
|
||||
type CallbackUIOutput struct {
|
||||
OutputFun func(string)
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
package terraform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// PrefixUIOutput is an implementation of UIOutput that prefixes the output
|
||||
// with a string.
|
||||
type PrefixUIOutput struct {
|
||||
Prefix string
|
||||
UIOutput UIOutput
|
||||
}
|
||||
|
||||
func (i *PrefixUIOutput) Output(v string) {
|
||||
v = fmt.Sprintf("%s%s", i.Prefix, v)
|
||||
i.UIOutput.Output(v)
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
package terraform
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPrefixUIOutput_impl(t *testing.T) {
|
||||
var _ UIOutput = new(PrefixUIOutput)
|
||||
}
|
||||
|
||||
func testPrefixUIOutput(t *testing.T) {
|
||||
output := new(MockUIOutput)
|
||||
prefix := &PrefixUIOutput{
|
||||
Prefix: "foo",
|
||||
UIOutput: output,
|
||||
}
|
||||
|
||||
prefix.Output("foo")
|
||||
if output.OutputMessage != "foofoo" {
|
||||
t.Fatalf("bad: %#v", output)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package terraform
|
||||
|
||||
// ProvisionerUIOutput is an implementation of UIOutput that calls a hook
|
||||
// for the output so that the hooks can handle it.
|
||||
type ProvisionerUIOutput struct {
|
||||
Info *InstanceInfo
|
||||
Type string
|
||||
Hooks []Hook
|
||||
}
|
||||
|
||||
func (o *ProvisionerUIOutput) Output(msg string) {
|
||||
for _, h := range o.Hooks {
|
||||
h.ProvisionOutput(o.Info, o.Type, msg)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package terraform
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestProvisionerUIOutput_impl(t *testing.T) {
|
||||
var _ UIOutput = new(ProvisionerUIOutput)
|
||||
}
|
||||
|
||||
func TestProvisionerUIOutputOutput(t *testing.T) {
|
||||
hook := new(MockHook)
|
||||
output := &ProvisionerUIOutput{
|
||||
Info: nil,
|
||||
Type: "foo",
|
||||
Hooks: []Hook{hook},
|
||||
}
|
||||
|
||||
output.Output("bar")
|
||||
|
||||
if !hook.ProvisionOutputCalled {
|
||||
t.Fatal("should be called")
|
||||
}
|
||||
if hook.ProvisionOutputProvisionerId != "foo" {
|
||||
t.Fatalf("bad: %#v", hook.ProvisionOutputProvisionerId)
|
||||
}
|
||||
if hook.ProvisionOutputMessage != "bar" {
|
||||
t.Fatalf("bad: %#v", hook.ProvisionOutputMessage)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue