-
Notifications
You must be signed in to change notification settings - Fork 1
/
tfgen.go
85 lines (75 loc) · 3.12 KB
/
tfgen.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
// Package tfgen provides property based test (PBT) generators for BastionZero
// Terraform Provider schema model types
package tfgen
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"pgregory.net/rapid"
)
func SetWithValueOrNullGen(ctx context.Context, gen *rapid.Generator[basetypes.SetValue]) *rapid.Generator[basetypes.SetValue] {
return rapid.Custom(func(t *rapid.T) basetypes.SetValue {
return rapid.OneOf(
rapid.Just(basetypes.NewSetNull(gen.Example(0).ElementType(ctx))),
rapid.Just(gen.Draw(t, "Value")),
).Draw(t, "SetWithValueOrNull")
})
}
func SetWithValueOrEmptyGen(ctx context.Context, gen *rapid.Generator[basetypes.SetValue]) *rapid.Generator[basetypes.SetValue] {
return rapid.Custom(func(t *rapid.T) basetypes.SetValue {
return rapid.OneOf(
rapid.Just(basetypes.NewSetValueMust(gen.Example(0).ElementType(ctx), []attr.Value{})),
rapid.Just(gen.Draw(t, "Value")),
).Draw(t, "SetWithValueOrEmpty")
})
}
func SetWithValueOrNullOrEmptyGen(ctx context.Context, gen *rapid.Generator[basetypes.SetValue]) *rapid.Generator[basetypes.SetValue] {
return rapid.Custom(func(t *rapid.T) basetypes.SetValue {
return rapid.OneOf(
rapid.Just(basetypes.NewSetValueMust(gen.Example(0).ElementType(ctx), []attr.Value{})),
rapid.Just(basetypes.NewSetNull(gen.Example(0).ElementType(ctx))),
rapid.Just(gen.Draw(t, "Value")),
).Draw(t, "SetWithValueOrNullOrEmpty")
})
}
func StringWithValueOrNullGen(gen *rapid.Generator[basetypes.StringValue]) *rapid.Generator[basetypes.StringValue] {
return rapid.Custom(func(t *rapid.T) basetypes.StringValue {
return rapid.OneOf(
rapid.Just(basetypes.NewStringNull()),
rapid.Just(gen.Draw(t, "Value")),
).Draw(t, "StringWithValueOrNull")
})
}
func StringWithValueOrEmptyGen(gen *rapid.Generator[basetypes.StringValue]) *rapid.Generator[basetypes.StringValue] {
return rapid.Custom(func(t *rapid.T) basetypes.StringValue {
return rapid.OneOf(
rapid.Just(basetypes.NewStringValue("")),
rapid.Just(gen.Draw(t, "Value")),
).Draw(t, "StringWithValueOrEmpty")
})
}
func StringWithValueOrNullOrEmptyGen(gen *rapid.Generator[basetypes.StringValue]) *rapid.Generator[basetypes.StringValue] {
return rapid.Custom(func(t *rapid.T) basetypes.StringValue {
return rapid.OneOf(
rapid.Just(basetypes.NewStringValue("")),
rapid.Just(basetypes.NewStringNull()),
rapid.Just(gen.Draw(t, "Value")),
).Draw(t, "StringWithValueOrNullOrEmpty")
})
}
func BoolWithValueOrNullGen(ctx context.Context) *rapid.Generator[basetypes.BoolValue] {
return rapid.Custom(func(t *rapid.T) basetypes.BoolValue {
return rapid.OneOf(
rapid.Just(basetypes.NewBoolNull()),
rapid.Just(basetypes.NewBoolValue(rapid.Bool().Draw(t, "Value"))),
).Draw(t, "BoolWithValueOrNull")
})
}
func Int64WithValueOrNullGen(ctx context.Context) *rapid.Generator[basetypes.Int64Value] {
return rapid.Custom(func(t *rapid.T) basetypes.Int64Value {
return rapid.OneOf(
rapid.Just(basetypes.NewInt64Null()),
rapid.Just(basetypes.NewInt64Value(rapid.Int64().Draw(t, "Value"))),
).Draw(t, "Int64WithValueOrNull")
})
}