-
Notifications
You must be signed in to change notification settings - Fork 91
/
bool.go
98 lines (80 loc) · 1.83 KB
/
bool.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package types
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)
var (
_ attr.Type = BoolType{}
_ attr.Value = Bool{}
)
// BoolType is a reimplementation of types.BoolType that can be used as a base
// for other extension types in testing.
type BoolType struct{}
func (t BoolType) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (interface{}, error) {
return nil, fmt.Errorf("cannot apply AttributePathStep %T to %s", step, t.String())
}
func (t BoolType) Equal(o attr.Type) bool {
other, ok := o.(BoolType)
if !ok {
return false
}
return t == other
}
func (t BoolType) String() string {
return "testtypes.BoolType"
}
func (t BoolType) TerraformType(_ context.Context) tftypes.Type {
return tftypes.Bool
}
func (t BoolType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) {
if in.IsNull() {
return Bool{
Bool: types.Bool{Null: true},
CreatedBy: t,
}, nil
}
if !in.IsKnown() {
return Bool{
Bool: types.Bool{Unknown: true},
CreatedBy: t,
}, nil
}
var b bool
err := in.As(&b)
if err != nil {
return nil, err
}
return Bool{Bool: types.Bool{Value: b}, CreatedBy: t}, nil
}
type Bool struct {
types.Bool
CreatedBy attr.Type
}
func (b Bool) Type(_ context.Context) attr.Type {
return b.CreatedBy
}
func (b Bool) Equal(o attr.Value) bool {
ob, ok := o.(Bool)
if !ok {
return false
}
return b.Bool.Equal(ob.Bool)
}
func (b Bool) IsNull() bool {
return b.Bool.IsNull()
}
func (b Bool) IsUnknown() bool {
return b.Bool.IsUnknown()
}
func (b Bool) String() string {
if b.Bool.IsUnknown() {
return attr.UnknownValueString
}
if b.Bool.IsNull() {
return attr.NullValueString
}
return fmt.Sprintf("%t", b.Value)
}