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


Golang terraform.MockResourceProvider類代碼示例

本文整理匯總了Golang中github.com/whitepages/terraform-provider-stingray/Godeps/_workspace/src/github.com/hashicorp/terraform/terraform.MockResourceProvider的典型用法代碼示例。如果您正苦於以下問題:Golang MockResourceProvider類的具體用法?Golang MockResourceProvider怎麽用?Golang MockResourceProvider使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: TestResourceProvider_configure_errors

func TestResourceProvider_configure_errors(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.ConfigureReturnError = errors.New("foo")

	// Configure
	config := &terraform.ResourceConfig{
		Raw: map[string]interface{}{"foo": "bar"},
	}
	e := provider.Configure(config)
	if !p.ConfigureCalled {
		t.Fatal("configure should be called")
	}
	if !reflect.DeepEqual(p.ConfigureConfig, config) {
		t.Fatalf("bad: %#v", p.ConfigureConfig)
	}
	if e == nil {
		t.Fatal("should have error")
	}
	if e.Error() != "foo" {
		t.Fatalf("bad: %s", e)
	}
}
開發者ID:svend,項目名稱:terraform-provider-stingray,代碼行數:29,代碼來源:resource_provider_test.go

示例2: TestResourceProvider_validate_errors

func TestResourceProvider_validate_errors(t *testing.T) {
	p := new(terraform.MockResourceProvider)
	p.ValidateReturnErrors = []error{errors.New("foo")}

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

	// Configure
	config := &terraform.ResourceConfig{
		Raw: map[string]interface{}{"foo": "bar"},
	}
	w, e := provider.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)
	}
}
開發者ID:svend,項目名稱:terraform-provider-stingray,代碼行數:33,代碼來源:resource_provider_test.go

示例3: TestResourceProvider_validateResource_warns

func TestResourceProvider_validateResource_warns(t *testing.T) {
	p := new(terraform.MockResourceProvider)
	p.ValidateResourceReturnWarns = []string{"foo"}

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

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

	expected := []string{"foo"}
	if !reflect.DeepEqual(w, expected) {
		t.Fatalf("bad: %#v", w)
	}
}
開發者ID:svend,項目名稱:terraform-provider-stingray,代碼行數:34,代碼來源:resource_provider_test.go

示例4: TestResourceProvider_resources

func TestResourceProvider_resources(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}

	expected := []terraform.ResourceType{
		{"foo"},
		{"bar"},
	}

	p.ResourcesReturn = expected

	// Resources
	result := provider.Resources()
	if !p.ResourcesCalled {
		t.Fatal("resources should be called")
	}
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("bad: %#v", result)
	}
}
開發者ID:svend,項目名稱:terraform-provider-stingray,代碼行數:25,代碼來源:resource_provider_test.go

示例5: TestResourceProvider_refresh

func TestResourceProvider_refresh(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.RefreshReturn = &terraform.InstanceState{
		ID: "bob",
	}

	// Refresh
	info := &terraform.InstanceInfo{}
	state := &terraform.InstanceState{}
	newState, err := provider.Refresh(info, state)
	if !p.RefreshCalled {
		t.Fatal("refresh should be called")
	}
	if !reflect.DeepEqual(p.RefreshState, state) {
		t.Fatalf("bad: %#v", p.RefreshState)
	}
	if err != nil {
		t.Fatalf("bad: %#v", err)
	}
	if !reflect.DeepEqual(p.RefreshReturn, newState) {
		t.Fatalf("bad: %#v", newState)
	}
}
開發者ID:svend,項目名稱:terraform-provider-stingray,代碼行數:30,代碼來源:resource_provider_test.go

示例6: TestResourceProvider_diff_error

func TestResourceProvider_diff_error(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.DiffReturnError = errors.New("foo")

	// 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.Fatal("should have error")
	}
	if diff != nil {
		t.Fatal("should not have diff")
	}
}
開發者ID:svend,項目名稱:terraform-provider-stingray,代碼行數:31,代碼來源:resource_provider_test.go

示例7: TestResourceProvider_apply

func TestResourceProvider_apply(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.ApplyReturn = &terraform.InstanceState{
		ID: "bob",
	}

	// Apply
	info := &terraform.InstanceInfo{}
	state := &terraform.InstanceState{}
	diff := &terraform.InstanceDiff{}
	newState, err := provider.Apply(info, state, diff)
	if !p.ApplyCalled {
		t.Fatal("apply should be called")
	}
	if !reflect.DeepEqual(p.ApplyDiff, diff) {
		t.Fatalf("bad: %#v", p.ApplyDiff)
	}
	if err != nil {
		t.Fatalf("bad: %#v", err)
	}
	if !reflect.DeepEqual(p.ApplyReturn, newState) {
		t.Fatalf("bad: %#v", newState)
	}
}
開發者ID:svend,項目名稱:terraform-provider-stingray,代碼行數:31,代碼來源:resource_provider_test.go

示例8: 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:svend,項目名稱:terraform-provider-stingray,代碼行數:38,代碼來源:resource_provider_test.go


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