當前位置: 首頁>>代碼示例>>Golang>>正文


Golang MockResourceProvider.DiffReturn方法代碼示例

本文整理匯總了Golang中github.com/hashicorp/terraform/terraform.MockResourceProvider.DiffReturn方法的典型用法代碼示例。如果您正苦於以下問題:Golang MockResourceProvider.DiffReturn方法的具體用法?Golang MockResourceProvider.DiffReturn怎麽用?Golang MockResourceProvider.DiffReturn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/hashicorp/terraform/terraform.MockResourceProvider的用法示例。


在下文中一共展示了MockResourceProvider.DiffReturn方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: testProvider

func testProvider() *terraform.MockResourceProvider {
	mp := new(terraform.MockResourceProvider)
	mp.DiffReturn = &terraform.InstanceDiff{
		Attributes: map[string]*terraform.ResourceAttrDiff{
			"foo": &terraform.ResourceAttrDiff{
				New: "bar",
			},
		},
	}
	mp.ResourcesReturn = []terraform.ResourceType{
		terraform.ResourceType{Name: "test_instance"},
	}

	return mp
}
開發者ID:discogestalt,項目名稱:terraform,代碼行數:15,代碼來源:testing_test.go

示例2: testProvider

func testProvider() *terraform.MockResourceProvider {
	p := new(terraform.MockResourceProvider)
	p.DiffReturn = &terraform.ResourceDiff{}
	p.RefreshFn = func(
		s *terraform.ResourceState) (*terraform.ResourceState, error) {
		return s, nil
	}
	p.ResourcesReturn = []terraform.ResourceType{
		terraform.ResourceType{
			Name: "test_instance",
		},
	}

	return p
}
開發者ID:GeorgeErickson,項目名稱:terraform-1,代碼行數:15,代碼來源:command_test.go

示例3: TestResourceProvider_diff

func TestResourceProvider_diff(t *testing.T) {
	p := new(terraform.MockResourceProvider)

	// Create a mock provider
	client, _ := plugin.TestPluginRPCConn(t, pluginMap(&ServeOpts{
		ProviderFunc: testProviderFixed(p),
	}))
	defer client.Close()

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

	p.DiffReturn = &terraform.InstanceDiff{
		Attributes: map[string]*terraform.ResourceAttrDiff{
			"foo": &terraform.ResourceAttrDiff{
				Old: "",
				New: "bar",
			},
		},
	}

	// Diff
	info := &terraform.InstanceInfo{}
	state := &terraform.InstanceState{}
	config := &terraform.ResourceConfig{
		Raw: map[string]interface{}{"foo": "bar"},
	}
	diff, err := provider.Diff(info, state, config)
	if !p.DiffCalled {
		t.Fatal("diff should be called")
	}
	if !reflect.DeepEqual(p.DiffDesired, config) {
		t.Fatalf("bad: %#v", p.DiffDesired)
	}
	if err != nil {
		t.Fatalf("bad: %#v", err)
	}
	if !reflect.DeepEqual(p.DiffReturn, diff) {
		t.Fatalf("bad: %#v", diff)
	}
}
開發者ID:paultyng,項目名稱:terraform,代碼行數:45,代碼來源:resource_provider_test.go

示例4: TestResourceProvider_diff

func TestResourceProvider_diff(t *testing.T) {
	p := new(terraform.MockResourceProvider)
	client, server := testClientServer(t)
	name, err := Register(server, p)
	if err != nil {
		t.Fatalf("err: %s", err)
	}
	provider := &ResourceProvider{Client: client, Name: name}

	p.DiffReturn = &terraform.InstanceDiff{
		Attributes: map[string]*terraform.ResourceAttrDiff{
			"foo": &terraform.ResourceAttrDiff{
				Old: "",
				New: "bar",
			},
		},
	}

	// Diff
	info := &terraform.InstanceInfo{}
	state := &terraform.InstanceState{}
	config := &terraform.ResourceConfig{
		Raw: map[string]interface{}{"foo": "bar"},
	}
	diff, err := provider.Diff(info, state, config)
	if !p.DiffCalled {
		t.Fatal("diff should be called")
	}
	if !reflect.DeepEqual(p.DiffDesired, config) {
		t.Fatalf("bad: %#v", p.DiffDesired)
	}
	if err != nil {
		t.Fatalf("bad: %#v", err)
	}
	if !reflect.DeepEqual(p.DiffReturn, diff) {
		t.Fatalf("bad: %#v", diff)
	}
}
開發者ID:AssertSelenium,項目名稱:terraform,代碼行數:38,代碼來源:resource_provider_test.go


注:本文中的github.com/hashicorp/terraform/terraform.MockResourceProvider.DiffReturn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。