88)
99
1010// WorkspaceOption configures a TestWorkspace
11- type WorkspaceOption func (* TestWorkspace )
11+ type WorkspaceOption func (* TestWorkspace ) error
1212
1313// SystemOption configures a System
1414type SystemOption func (* TestWorkspace , * oapi.System , * eventsBuilder )
@@ -38,7 +38,7 @@ type PolicyOption func(*TestWorkspace, *oapi.Policy, *eventsBuilder)
3838type PolicyTargetSelectorOption func (* TestWorkspace , * oapi.PolicyTargetSelector )
3939
4040// RelationshipRuleOption configures a RelationshipRule
41- type RelationshipRuleOption func (* TestWorkspace , * oapi.RelationshipRule )
41+ type RelationshipRuleOption func (* TestWorkspace , * oapi.RelationshipRule ) error
4242
4343// PropertyMatcherOption configures a PropertyMatcher
4444type PropertyMatcherOption func (* TestWorkspace , * oapi.PropertyMatcher )
@@ -75,13 +75,14 @@ func newEventsBuilder() *eventsBuilder {
7575// ===== Workspace Options =====
7676
7777func WithWorkspaceID (id string ) WorkspaceOption {
78- return func (ws * TestWorkspace ) {
78+ return func (ws * TestWorkspace ) error {
7979 ws .workspace .ID = id
80+ return nil
8081 }
8182}
8283
8384func WithSystem (options ... SystemOption ) WorkspaceOption {
84- return func (ws * TestWorkspace ) {
85+ return func (ws * TestWorkspace ) error {
8586 s := c .NewSystem (ws .workspace .ID )
8687
8788 eb := newEventsBuilder ()
@@ -98,11 +99,13 @@ func WithSystem(options ...SystemOption) WorkspaceOption {
9899 for _ , event := range eb .postEvents {
99100 ws .PushEvent (context .Background (), event .Type , event .Data )
100101 }
102+
103+ return nil
101104 }
102105}
103106
104107func WithResource (options ... ResourceOption ) WorkspaceOption {
105- return func (ws * TestWorkspace ) {
108+ return func (ws * TestWorkspace ) error {
106109 r := c .NewResource (ws .workspace .ID )
107110 eb := newEventsBuilder ()
108111
@@ -123,11 +126,13 @@ func WithResource(options ...ResourceOption) WorkspaceOption {
123126 for _ , event := range eb .postEvents {
124127 ws .PushEvent (context .Background (), event .Type , event .Data )
125128 }
129+
130+ return nil
126131 }
127132}
128133
129134func WithJobAgent (options ... JobAgentOption ) WorkspaceOption {
130- return func (ws * TestWorkspace ) {
135+ return func (ws * TestWorkspace ) error {
131136 ja := c .NewJobAgent (ws .workspace .ID )
132137
133138 for _ , option := range options {
@@ -139,11 +144,13 @@ func WithJobAgent(options ...JobAgentOption) WorkspaceOption {
139144 handler .JobAgentCreate ,
140145 ja ,
141146 )
147+
148+ return nil
142149 }
143150}
144151
145152func WithPolicy (options ... PolicyOption ) WorkspaceOption {
146- return func (ws * TestWorkspace ) {
153+ return func (ws * TestWorkspace ) error {
147154 p := c .NewPolicy (ws .workspace .ID )
148155
149156 eb := newEventsBuilder ()
@@ -156,22 +163,28 @@ func WithPolicy(options ...PolicyOption) WorkspaceOption {
156163 handler .PolicyCreate ,
157164 p ,
158165 )
166+
167+ return nil
159168 }
160169}
161170
162171func WithRelationshipRule (options ... RelationshipRuleOption ) WorkspaceOption {
163- return func (ws * TestWorkspace ) {
172+ return func (ws * TestWorkspace ) error {
164173 rr := c .NewRelationshipRule (ws .workspace .ID )
165174
166175 for _ , option := range options {
167- option (ws , rr )
176+ if err := option (ws , rr ); err != nil {
177+ return err
178+ }
168179 }
169180
170181 ws .PushEvent (
171182 context .Background (),
172183 handler .RelationshipRuleCreate ,
173184 rr ,
174185 )
186+
187+ return nil
175188 }
176189}
177190
@@ -206,7 +219,7 @@ func WithDeploymentVariable(key string, options ...DeploymentVariableOption) Dep
206219}
207220
208221func WithResourceProvider (options ... ResourceProviderOption ) WorkspaceOption {
209- return func (ws * TestWorkspace ) {
222+ return func (ws * TestWorkspace ) error {
210223 rp := c .NewResourceProvider (ws .workspace .ID )
211224
212225 for _ , option := range options {
@@ -218,6 +231,8 @@ func WithResourceProvider(options ...ResourceProviderOption) WorkspaceOption {
218231 handler .ResourceProviderCreate ,
219232 rp ,
220233 )
234+
235+ return nil
221236 }
222237}
223238
@@ -586,71 +601,85 @@ func PolicyTargetJsonResourceSelector(selector map[string]any) PolicyTargetSelec
586601// ===== RelationshipRule Options =====
587602
588603func RelationshipRuleName (name string ) RelationshipRuleOption {
589- return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) {
604+ return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) error {
590605 rr .Name = name
606+ return nil
591607 }
592608}
593609
594610func RelationshipRuleDescription (description string ) RelationshipRuleOption {
595- return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) {
611+ return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) error {
596612 rr .Description = & description
613+ return nil
597614 }
598615}
599616
600617func RelationshipRuleID (id string ) RelationshipRuleOption {
601- return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) {
618+ return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) error {
602619 rr .Id = id
620+ return nil
603621 }
604622}
605623
606624func RelationshipRuleReference (reference string ) RelationshipRuleOption {
607- return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) {
625+ return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) error {
608626 rr .Reference = reference
627+ return nil
609628 }
610629}
611630
612631func RelationshipRuleFromType (fromType string ) RelationshipRuleOption {
613- return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) {
632+ return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) error {
614633 rr .FromType = fromType
634+ return nil
615635 }
616636}
617637
618638func RelationshipRuleToType (toType string ) RelationshipRuleOption {
619- return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) {
639+ return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) error {
620640 rr .ToType = toType
641+ return nil
621642 }
622643}
623644
624645func RelationshipRuleFromJsonSelector (selector map [string ]any ) RelationshipRuleOption {
625- return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) {
646+ return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) error {
626647 s := & oapi.Selector {}
627- _ = s .FromJsonSelector (oapi.JsonSelector {Json : selector })
648+ if err := s .FromJsonSelector (oapi.JsonSelector {Json : selector }); err != nil {
649+ return err
650+ }
628651 rr .FromSelector = s
652+ return nil
629653 }
630654}
631655
632656func RelationshipRuleToJsonSelector (selector map [string ]any ) RelationshipRuleOption {
633- return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) {
657+ return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) error {
634658 s := & oapi.Selector {}
635- _ = s .FromJsonSelector (oapi.JsonSelector {Json : selector })
659+ if err := s .FromJsonSelector (oapi.JsonSelector {Json : selector }); err != nil {
660+ return err
661+ }
636662 rr .ToSelector = s
663+ return nil
637664 }
638665}
639666
640667func RelationshipRuleType (relType string ) RelationshipRuleOption {
641- return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) {
668+ return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) error {
642669 rr .RelationshipType = relType
670+ return nil
643671 }
644672}
645673
646674func RelationshipRuleMetadata (metadata map [string ]string ) RelationshipRuleOption {
647- return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) {
675+ return func (_ * TestWorkspace , rr * oapi.RelationshipRule ) error {
648676 rr .Metadata = metadata
677+ return nil
649678 }
650679}
651680
652681func WithPropertyMatcher (options ... PropertyMatcherOption ) RelationshipRuleOption {
653- return func (ws * TestWorkspace , rr * oapi.RelationshipRule ) {
682+ return func (ws * TestWorkspace , rr * oapi.RelationshipRule ) error {
654683 pm := c .NewPropertyMatcher ([]string {}, []string {})
655684
656685 for _ , option := range options {
@@ -664,16 +693,19 @@ func WithPropertyMatcher(options ...PropertyMatcherOption) RelationshipRuleOptio
664693 existingProperties = existingMatcher .Properties
665694 }
666695
667- rr .Matcher .FromPropertiesMatcher (oapi.PropertiesMatcher {
696+ if err := rr .Matcher .FromPropertiesMatcher (oapi.PropertiesMatcher {
668697 Properties : append (existingProperties , * pm ),
669- })
698+ }); err != nil {
699+ return err
700+ }
701+
702+ return nil
670703 }
671704}
672705
673706func WithCelMatcher (cel string ) RelationshipRuleOption {
674- return func (ws * TestWorkspace , rr * oapi.RelationshipRule ) {
675-
676- rr .Matcher .FromCelMatcher (oapi.CelMatcher {Cel : cel })
707+ return func (ws * TestWorkspace , rr * oapi.RelationshipRule ) error {
708+ return rr .Matcher .FromCelMatcher (oapi.CelMatcher {Cel : cel })
677709 }
678710}
679711
0 commit comments