コード例 #1
0
func TestResourceProvisioner_validate_errors(t *testing.T) {
	p := new(terraform.MockResourceProvisioner)
	p.ValidateReturnErrors = []error{errors.New("foo")}

	client, server := testClientServer(t)
	name, err := Register(server, p)
	if err != nil {
		t.Fatalf("err: %s", err)
	}
	provisioner := &ResourceProvisioner{Client: client, Name: name}

	// Configure
	config := &terraform.ResourceConfig{
		Raw: map[string]interface{}{"foo": "bar"},
	}
	w, e := provisioner.Validate(config)
	if !p.ValidateCalled {
		t.Fatal("configure should be called")
	}
	if !reflect.DeepEqual(p.ValidateConfig, config) {
		t.Fatalf("bad: %#v", p.ValidateConfig)
	}
	if w != nil {
		t.Fatalf("bad: %#v", w)
	}

	if len(e) != 1 {
		t.Fatalf("bad: %#v", e)
	}
	if e[0].Error() != "foo" {
		t.Fatalf("bad: %#v", e)
	}
}
コード例 #2
0
func TestResourceProvisioner_validate_warns(t *testing.T) {
	p := new(terraform.MockResourceProvisioner)
	p.ValidateReturnWarns = []string{"foo"}

	client, server := testClientServer(t)
	name, err := Register(server, p)
	if err != nil {
		t.Fatalf("err: %s", err)
	}
	provisioner := &ResourceProvisioner{Client: client, Name: name}

	// Configure
	config := &terraform.ResourceConfig{
		Raw: map[string]interface{}{"foo": "bar"},
	}
	w, e := provisioner.Validate(config)
	if !p.ValidateCalled {
		t.Fatal("configure should be called")
	}
	if !reflect.DeepEqual(p.ValidateConfig, config) {
		t.Fatalf("bad: %#v", p.ValidateConfig)
	}
	if e != nil {
		t.Fatalf("bad: %#v", e)
	}

	expected := []string{"foo"}
	if !reflect.DeepEqual(w, expected) {
		t.Fatalf("bad: %#v", w)
	}
}
コード例 #3
0
func TestResourceProvisioner_validate_errors(t *testing.T) {
	// Create a mock provider
	p := new(terraform.MockResourceProvisioner)
	client, _ := plugin.TestPluginRPCConn(t, pluginMap(&ServeOpts{
		ProvisionerFunc: testProvisionerFixed(p),
	}))
	defer client.Close()

	// Request the provider
	raw, err := client.Dispense(ProvisionerPluginName)
	if err != nil {
		t.Fatalf("err: %s", err)
	}
	provisioner := raw.(terraform.ResourceProvisioner)

	p.ValidateReturnErrors = []error{errors.New("foo")}

	// Configure
	config := &terraform.ResourceConfig{
		Raw: map[string]interface{}{"foo": "bar"},
	}
	w, e := provisioner.Validate(config)
	if !p.ValidateCalled {
		t.Fatal("configure should be called")
	}
	if !reflect.DeepEqual(p.ValidateConfig, config) {
		t.Fatalf("bad: %#v", p.ValidateConfig)
	}
	if w != nil {
		t.Fatalf("bad: %#v", w)
	}

	if len(e) != 1 {
		t.Fatalf("bad: %#v", e)
	}
	if e[0].Error() != "foo" {
		t.Fatalf("bad: %#v", e)
	}
}
コード例 #4
0
ファイル: apply_test.go プロジェクト: semarj/terraform
func TestApply_parallelism2(t *testing.T) {
	statePath := testTempFile(t)

	ui := new(cli.MockUi)
	p := testProvider()
	pr := new(terraform.MockResourceProvisioner)

	pr.ApplyFn = func(*terraform.InstanceState, *terraform.ResourceConfig) error {
		time.Sleep(time.Second)
		return nil
	}

	args := []string{
		"-state", statePath,
		"-parallelism=2",
		testFixturePath("parallelism"),
	}

	c := &ApplyCommand{
		Meta: Meta{
			ContextOpts: testCtxConfigWithShell(p, pr),
			Ui:          ui,
		},
	}

	start := time.Now()
	if code := c.Run(args); code != 0 {
		t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
	}
	elapsed := time.Since(start).Seconds()

	// This test should take exactly one second, plus some minor amount of execution time.
	if elapsed < 1 || elapsed > 1.2 {
		t.Fatalf("bad: %f\n\n%s", elapsed, ui.ErrorWriter.String())
	}

}