forked from databricks/terraform-provider-databricks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext_test.go
34 lines (31 loc) · 826 Bytes
/
context_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package common
import (
"context"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/stretchr/testify/assert"
)
func TestAddContextToAllResources(t *testing.T) {
check := func(ctx context.Context, rd *schema.ResourceData, i any) diag.Diagnostics {
assert.Equal(t, "bar", ResourceName.GetOrUnknown(ctx))
return nil
}
p := &schema.Provider{
ResourcesMap: map[string]*schema.Resource{
"foo_bar": {
CreateContext: check,
ReadContext: check,
UpdateContext: check,
DeleteContext: check,
},
},
DataSourcesMap: map[string]*schema.Resource{
"foo_bar": {
ReadContext: check,
},
},
}
AddContextToAllResources(p, "foo")
p.ResourcesMap["foo_bar"].CreateContext(context.Background(), nil, nil)
}