Skip to content

Commit a32d0c0

Browse files
chore: more lint fix
1 parent 6cfac9f commit a32d0c0

File tree

3 files changed

+69
-33
lines changed

3 files changed

+69
-33
lines changed

apps/workspace-engine/test/e2e/engine_deployment_version_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,10 @@ func TestEngine_MultipleDeploymentsIndependentVersions(t *testing.T) {
322322
if !ok {
323323
continue
324324
}
325-
if release.ReleaseTarget.DeploymentId == deployment1Id {
325+
switch release.ReleaseTarget.DeploymentId {
326+
case deployment1Id:
326327
deployment1Jobs++
327-
} else if release.ReleaseTarget.DeploymentId == deployment2Id {
328+
case deployment2Id:
328329
deployment2Jobs++
329330
}
330331
}
@@ -526,9 +527,10 @@ func TestEngine_DeploymentVersionCreationWithMultipleEnvironments(t *testing.T)
526527
if !ok {
527528
continue
528529
}
529-
if release.ReleaseTarget.EnvironmentId == envDevId {
530+
switch release.ReleaseTarget.EnvironmentId {
531+
case envDevId:
530532
devJobs++
531-
} else if release.ReleaseTarget.EnvironmentId == envProdId {
533+
case envProdId:
532534
prodJobs++
533535
}
534536
}

apps/workspace-engine/test/integration/opts.go

Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
// WorkspaceOption configures a TestWorkspace
11-
type WorkspaceOption func(*TestWorkspace)
11+
type WorkspaceOption func(*TestWorkspace) error
1212

1313
// SystemOption configures a System
1414
type SystemOption func(*TestWorkspace, *oapi.System, *eventsBuilder)
@@ -38,7 +38,7 @@ type PolicyOption func(*TestWorkspace, *oapi.Policy, *eventsBuilder)
3838
type 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
4444
type PropertyMatcherOption func(*TestWorkspace, *oapi.PropertyMatcher)
@@ -75,13 +75,14 @@ func newEventsBuilder() *eventsBuilder {
7575
// ===== Workspace Options =====
7676

7777
func 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

8384
func 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

104107
func 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

129134
func 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

145152
func 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

162171
func 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

208221
func 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

588603
func 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

594610
func 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

600617
func 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

606624
func 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

612631
func 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

618638
func 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

624645
func 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

632656
func 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

640667
func 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

646674
func 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

652681
func 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

673706
func 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

apps/workspace-engine/test/integration/workspace.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ func NewTestWorkspace(
4040
tw.eventListener = events.NewEventHandler()
4141

4242
for _, option := range options {
43-
option(tw)
43+
if err := option(tw); err != nil {
44+
tw.t.Fatalf("failed to apply option: %v", err)
45+
}
4446
}
4547

4648
return tw

0 commit comments

Comments
 (0)