-
Notifications
You must be signed in to change notification settings - Fork 91
/
object.go
49 lines (37 loc) · 1.25 KB
/
object.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package testdefaults
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/defaults"
)
var _ defaults.Object = Object{}
// Declarative defaults.Object for unit testing.
type Object struct {
// defaults.Describer interface methods
DescriptionMethod func(context.Context) string
MarkdownDescriptionMethod func(context.Context) string
// defaults.Object interface methods
DefaultObjectMethod func(context.Context, defaults.ObjectRequest, *defaults.ObjectResponse)
}
// Description satisfies the defaults.Describer interface.
func (v Object) Description(ctx context.Context) string {
if v.DescriptionMethod == nil {
return ""
}
return v.DescriptionMethod(ctx)
}
// MarkdownDescription satisfies the defaults.Describer interface.
func (v Object) MarkdownDescription(ctx context.Context) string {
if v.MarkdownDescriptionMethod == nil {
return ""
}
return v.MarkdownDescriptionMethod(ctx)
}
// DefaultObject satisfies the defaults.Object interface.
func (v Object) DefaultObject(ctx context.Context, req defaults.ObjectRequest, resp *defaults.ObjectResponse) {
if v.DefaultObjectMethod == nil {
return
}
v.DefaultObjectMethod(ctx, req, resp)
}