Add coverage for pulumi.Fprintf.
Just what it says on the tin.
package pulumi
import (
+ "bytes"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
-func TestSprintfPrompt(t *testing.T) {
- out := Sprintf("%v %v %v", "foo", 42, true)
- v, known, err := await(out)
+func testPrintf(t *testing.T, ins ...interface{}) {
+ const f = "%v %v %v"
+ expected := fmt.Sprintf(f, "foo", 42, true)
+
+ // Fprintf
+ buf := &bytes.Buffer{}
+ out := Output(Fprintf(buf, f, ins...))
+ _, known, err := await(out)
assert.True(t, known)
assert.Nil(t, err)
- assert.Equal(t, fmt.Sprintf("%v %v %v", "foo", 42, true), v)
-}
+ assert.Equal(t, expected, buf.String())
-func TestSprintfInputs(t *testing.T) {
- out := Sprintf("%v %v %v", String("foo"), Int(42), Bool(true))
+ // Sprintf
+ out = Sprintf(f, ins...)
v, known, err := await(out)
assert.True(t, known)
assert.Nil(t, err)
- assert.Equal(t, fmt.Sprintf("%v %v %v", "foo", 42, true), v)
+ assert.Equal(t, expected, v)
+}
+
+func TestSprintfPrompt(t *testing.T) {
+ testPrintf(t, "foo", 42, true)
+}
+
+func TestSprintfInputs(t *testing.T) {
+ testPrintf(t, String("foo"), Int(42), Bool(true))
}
func TestSprintfOutputs(t *testing.T) {
- out := Sprintf("%v %v %v", ToOutput("foo"), ToOutput(42), ToOutput(true))
- v, known, err := await(out)
- assert.True(t, known)
- assert.Nil(t, err)
- assert.Equal(t, fmt.Sprintf("%v %v %v", "foo", 42, true), v)
+ testPrintf(t, ToOutput("foo"), ToOutput(42), ToOutput(true))
}
