Skip to content

Commit 4794d7e

Browse files
committed
Fix linter warnings
1 parent 3a56b1b commit 4794d7e

File tree

1 file changed

+65
-53
lines changed

1 file changed

+65
-53
lines changed

pkg/component/runtime/manager_fake_input_test.go

Lines changed: 65 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -791,9 +791,10 @@ func (suite *FakeInputSuite) TestManager_BadUnitToGood() {
791791
} else {
792792
unit, ok := state.Units[ComponentUnitKey{UnitType: client.UnitTypeInput, UnitID: "fake-input"}]
793793
if ok {
794-
if unit.State == client.UnitStateFailed {
794+
switch unit.State {
795+
case client.UnitStateFailed:
795796
subErrCh <- fmt.Errorf("unit failed: %s", unit.Message)
796-
} else if unit.State == client.UnitStateHealthy {
797+
case client.UnitStateHealthy:
797798
// update the bad unit to be good; so it will transition to healthy
798799
updatedComp := comp
799800
updatedComp.Units = make([]component.Unit, len(comp.Units))
@@ -815,9 +816,9 @@ func (suite *FakeInputSuite) TestManager_BadUnitToGood() {
815816
if err != nil {
816817
subErrCh <- err
817818
}
818-
} else if unit.State == client.UnitStateStopped || unit.State == client.UnitStateStarting {
819+
case client.UnitStateStopped, client.UnitStateStarting:
819820
// acceptable
820-
} else {
821+
default:
821822
// unknown state that should not have occurred
822823
subErrCh <- fmt.Errorf("unit reported unexpected state: %v", unit.State)
823824
}
@@ -831,24 +832,25 @@ func (suite *FakeInputSuite) TestManager_BadUnitToGood() {
831832
subErrCh <- errors.New("bad-input unit should be failed")
832833
}
833834
} else {
834-
if unit.State == client.UnitStateFailed {
835+
switch unit.State {
836+
case client.UnitStateFailed:
835837
if unit.Message == "hard-error for config" {
836838
// still hard-error; wait for it to go healthy
837839
} else {
838840
subErrCh <- fmt.Errorf("unit failed: %s", unit.Message)
839841
}
840-
} else if unit.State == client.UnitStateHealthy {
842+
case client.UnitStateHealthy:
841843
// bad unit is now healthy; stop the component
842844
m.Update(component.Model{Components: []component.Component{}})
843845
err := <-m.errCh
844846
if err != nil {
845847
subErrCh <- err
846848
}
847-
} else if unit.State == client.UnitStateStopped {
849+
case client.UnitStateStopped:
848850
subErrCh <- nil
849-
} else if unit.State == client.UnitStateStarting {
851+
case client.UnitStateStarting:
850852
// acceptable
851-
} else {
853+
default:
852854
// unknown state that should not have occurred
853855
subErrCh <- fmt.Errorf("unit reported unexpected state: %v", unit.State)
854856
}
@@ -1209,9 +1211,10 @@ func (suite *FakeInputSuite) TestManager_Configure() {
12091211
} else {
12101212
unit, ok := state.Units[ComponentUnitKey{UnitType: client.UnitTypeInput, UnitID: "fake-input"}]
12111213
if ok {
1212-
if unit.State == client.UnitStateFailed {
1214+
switch unit.State {
1215+
case client.UnitStateFailed:
12131216
subErrCh <- fmt.Errorf("unit failed: %s", unit.Message)
1214-
} else if unit.State == client.UnitStateHealthy {
1217+
case client.UnitStateHealthy:
12151218
// update config to change the state to degraded
12161219
comp.Units[0].Config = component.MustExpectedConfig(map[string]interface{}{
12171220
"type": "fake",
@@ -1223,11 +1226,11 @@ func (suite *FakeInputSuite) TestManager_Configure() {
12231226
if err != nil {
12241227
subErrCh <- err
12251228
}
1226-
} else if unit.State == client.UnitStateDegraded {
1229+
case client.UnitStateDegraded:
12271230
subErrCh <- nil
1228-
} else if unit.State == client.UnitStateStarting {
1231+
case client.UnitStateStarting:
12291232
// acceptable
1230-
} else {
1233+
default:
12311234
// unknown state that should not have occurred
12321235
subErrCh <- fmt.Errorf("unit reported unexpected state: %v", unit.State)
12331236
}
@@ -1343,11 +1346,12 @@ func (suite *FakeInputSuite) TestManager_RemoveUnit() {
13431346
} else {
13441347
unit0, ok := state.Units[ComponentUnitKey{UnitType: client.UnitTypeInput, UnitID: "fake-input-0"}]
13451348
if ok {
1346-
if unit0.State == client.UnitStateFailed {
1349+
switch unit0.State {
1350+
case client.UnitStateFailed:
13471351
subErrCh <- fmt.Errorf("unit 0 failed: %s", unit0.Message)
1348-
} else if unit0.State == client.UnitStateStarting || unit0.State == client.UnitStateHealthy {
1352+
case client.UnitStateStarting, client.UnitStateHealthy:
13491353
// acceptable
1350-
} else {
1354+
default:
13511355
// unknown state that should not have occurred
13521356
subErrCh <- fmt.Errorf("unit 0 reported unexpected state: %v", unit0.State)
13531357
}
@@ -1356,22 +1360,23 @@ func (suite *FakeInputSuite) TestManager_RemoveUnit() {
13561360
}
13571361
unit1, ok := state.Units[ComponentUnitKey{UnitType: client.UnitTypeInput, UnitID: "fake-input-1"}]
13581362
if ok {
1359-
if unit1.State == client.UnitStateFailed {
1363+
switch unit1.State {
1364+
case client.UnitStateFailed:
13601365
subErrCh <- fmt.Errorf("unit 1 failed: %s", unit1.Message)
1361-
} else if unit1.State == client.UnitStateHealthy {
1366+
case client.UnitStateHealthy:
13621367
// unit1 is healthy lets remove it from the component
13631368
comp.Units = comp.Units[0:1]
13641369
m.Update(component.Model{Components: []component.Component{comp}})
13651370
err = <-m.errCh
13661371
if err != nil {
13671372
subErrCh <- err
13681373
}
1369-
} else if unit1.State == client.UnitStateStarting || unit1.State == client.UnitStateStopping {
1374+
case client.UnitStateStarting, client.UnitStateStopping:
13701375
// acceptable
1371-
} else if unit1.State == client.UnitStateStopped {
1376+
case client.UnitStateStopped:
13721377
// unit should have been reported stopped before being removed
13731378
unit1Stopped = true
1374-
} else {
1379+
default:
13751380
// unknown state that should not have occurred
13761381
subErrCh <- fmt.Errorf("unit 1 reported unexpected state: %v", unit1.State)
13771382
}
@@ -1486,9 +1491,10 @@ func (suite *FakeInputSuite) TestManager_ActionState() {
14861491
} else {
14871492
unit, ok := state.Units[ComponentUnitKey{UnitType: client.UnitTypeInput, UnitID: "fake-input"}]
14881493
if ok {
1489-
if unit.State == client.UnitStateFailed {
1494+
switch unit.State {
1495+
case client.UnitStateFailed:
14901496
subErrCh <- fmt.Errorf("unit failed: %s", unit.Message)
1491-
} else if unit.State == client.UnitStateHealthy {
1497+
case client.UnitStateHealthy:
14921498
// must be called in a separate go routine because it cannot block receiving from the
14931499
// subscription channel
14941500
go func() {
@@ -1502,12 +1508,12 @@ func (suite *FakeInputSuite) TestManager_ActionState() {
15021508
subErrCh <- err
15031509
}
15041510
}()
1505-
} else if unit.State == client.UnitStateDegraded {
1511+
case client.UnitStateDegraded:
15061512
// action set it to degraded
15071513
subErrCh <- nil
1508-
} else if unit.State == client.UnitStateStarting {
1514+
case client.UnitStateStarting:
15091515
// acceptable
1510-
} else {
1516+
default:
15111517
// unknown state that should not have occurred
15121518
subErrCh <- fmt.Errorf("unit reported unexpected state: %v", unit.State)
15131519
}
@@ -1615,11 +1621,12 @@ func (suite *FakeInputSuite) TestManager_Restarts() {
16151621
} else {
16161622
unit, ok := state.Units[ComponentUnitKey{UnitType: client.UnitTypeInput, UnitID: "fake-input"}]
16171623
if ok {
1618-
if unit.State == client.UnitStateFailed {
1624+
switch unit.State {
1625+
case client.UnitStateFailed:
16191626
if !killed {
16201627
subErrCh <- fmt.Errorf("unit failed: %s", unit.Message)
16211628
}
1622-
} else if unit.State == client.UnitStateHealthy {
1629+
case client.UnitStateHealthy:
16231630
// force the input to exit and it should be restarted
16241631
if !killed {
16251632
killed = true
@@ -1641,9 +1648,9 @@ func (suite *FakeInputSuite) TestManager_Restarts() {
16411648
// got back to healthy after kill
16421649
subErrCh <- nil
16431650
}
1644-
} else if unit.State == client.UnitStateStarting {
1651+
case client.UnitStateStarting:
16451652
// acceptable
1646-
} else {
1653+
default:
16471654
// unknown state that should not have occurred
16481655
subErrCh <- fmt.Errorf("unit reported unexpected state: %v", unit.State)
16491656
}
@@ -1758,11 +1765,12 @@ func (suite *FakeInputSuite) TestManager_Restarts_ConfigKill() {
17581765
} else {
17591766
unit, ok := state.Units[ComponentUnitKey{UnitType: client.UnitTypeInput, UnitID: "fake-input"}]
17601767
if ok {
1761-
if unit.State == client.UnitStateFailed {
1768+
switch unit.State {
1769+
case client.UnitStateFailed:
17621770
if !killed {
17631771
subErrCh <- fmt.Errorf("unit failed: %s", unit.Message)
17641772
}
1765-
} else if unit.State == client.UnitStateHealthy {
1773+
case client.UnitStateHealthy:
17661774
// force the input to exit and it should be restarted
17671775
if !killed {
17681776
killed = true
@@ -1785,9 +1793,9 @@ func (suite *FakeInputSuite) TestManager_Restarts_ConfigKill() {
17851793
// got back to healthy after kill
17861794
subErrCh <- nil
17871795
}
1788-
} else if unit.State == client.UnitStateStarting || unit.State == client.UnitStateStopped {
1796+
case client.UnitStateStarting, client.UnitStateStopped:
17891797
// acceptable
1790-
} else {
1798+
default:
17911799
// unknown state that should not have occurred
17921800
subErrCh <- fmt.Errorf("unit reported unexpected state: %v", unit.State)
17931801
}
@@ -1903,10 +1911,11 @@ func (suite *FakeInputSuite) TestManager_KeepsRestarting() {
19031911
} else {
19041912
unit, ok := state.Units[ComponentUnitKey{UnitType: client.UnitTypeInput, UnitID: "fake-input"}]
19051913
if ok {
1906-
if unit.State == client.UnitStateFailed {
1914+
switch unit.State {
1915+
case client.UnitStateFailed:
19071916
// unit should not be failed because we allow restart per period
19081917
subErrCh <- fmt.Errorf("unit failed: %s", unit.Message)
1909-
} else if unit.State == client.UnitStateHealthy {
1918+
case client.UnitStateHealthy:
19101919
if lastStoppedCount != stoppedCount {
19111920
lastStoppedCount = stoppedCount
19121921

@@ -1927,11 +1936,11 @@ func (suite *FakeInputSuite) TestManager_KeepsRestarting() {
19271936
// got stopped 3 times and got back to healthy
19281937
subErrCh <- nil
19291938
}
1930-
} else if unit.State == client.UnitStateStarting {
1939+
case client.UnitStateStarting:
19311940
// acceptable
1932-
} else if unit.State == client.UnitStateStopped {
1941+
case client.UnitStateStopped:
19331942
stoppedCount += 1
1934-
} else {
1943+
default:
19351944
// unknown state that should not have occurred
19361945
subErrCh <- fmt.Errorf("unit reported unexpected state: %v", unit.State)
19371946
}
@@ -2153,9 +2162,10 @@ func (suite *FakeInputSuite) TestManager_InvalidAction() {
21532162
} else {
21542163
unit, ok := state.Units[ComponentUnitKey{UnitType: client.UnitTypeInput, UnitID: "fake-input"}]
21552164
if ok {
2156-
if unit.State == client.UnitStateFailed {
2165+
switch unit.State {
2166+
case client.UnitStateFailed:
21572167
subErrCh <- fmt.Errorf("unit failed: %s", unit.Message)
2158-
} else if unit.State == client.UnitStateHealthy {
2168+
case client.UnitStateHealthy:
21592169
actionCtx, actionCancel := context.WithTimeout(context.Background(), 5*time.Second)
21602170
_, err := m.PerformAction(actionCtx, comp, comp.Units[0], "invalid_missing_action", nil)
21612171
actionCancel()
@@ -2166,9 +2176,9 @@ func (suite *FakeInputSuite) TestManager_InvalidAction() {
21662176
} else {
21672177
subErrCh <- nil
21682178
}
2169-
} else if unit.State == client.UnitStateStarting {
2179+
case client.UnitStateStarting:
21702180
// acceptable
2171-
} else {
2181+
default:
21722182
// unknown state that should not have occurred
21732183
subErrCh <- fmt.Errorf("unit reported unexpected state: %v", unit.State)
21742184
}
@@ -2492,9 +2502,10 @@ func (suite *FakeInputSuite) TestManager_LogLevel() {
24922502
} else {
24932503
unit, ok := state.Units[ComponentUnitKey{UnitType: client.UnitTypeInput, UnitID: "fake-input"}]
24942504
if ok {
2495-
if unit.State == client.UnitStateFailed {
2505+
switch unit.State {
2506+
case client.UnitStateFailed:
24962507
subErrCh <- fmt.Errorf("unit failed: %s", unit.Message)
2497-
} else if unit.State == client.UnitStateHealthy {
2508+
case client.UnitStateHealthy:
24982509
updatedComp := comp
24992510
updatedComp.Units = make([]component.Unit, len(comp.Units))
25002511
copy(updatedComp.Units, comp.Units)
@@ -2519,9 +2530,9 @@ func (suite *FakeInputSuite) TestManager_LogLevel() {
25192530
} else {
25202531
subErrCh <- nil
25212532
}
2522-
} else if unit.State == client.UnitStateStarting {
2533+
case client.UnitStateStarting:
25232534
// acceptable
2524-
} else {
2535+
default:
25252536
// unknown state that should not have occurred
25262537
subErrCh <- fmt.Errorf("unit reported unexpected state: %v", unit.State)
25272538
}
@@ -2845,15 +2856,16 @@ func (suite *FakeInputSuite) TestManager_Chunk() {
28452856
healthyCount := 0
28462857
stoppedCount := 0
28472858
for _, unit := range state.Units {
2848-
if unit.State == client.UnitStateFailed {
2859+
switch unit.State {
2860+
case client.UnitStateFailed:
28492861
subErrCh <- fmt.Errorf("unit failed: %s", unit.Message)
2850-
} else if unit.State == client.UnitStateHealthy {
2862+
case client.UnitStateHealthy:
28512863
healthyCount += 1
2852-
} else if unit.State == client.UnitStateStopped {
2864+
case client.UnitStateStopped:
28532865
stoppedCount += 1
2854-
} else if unit.State == client.UnitStateStarting {
2866+
case client.UnitStateStarting:
28552867
// acceptable
2856-
} else {
2868+
default:
28572869
// unknown state that should not have occurred
28582870
subErrCh <- fmt.Errorf("unit reported unexpected state: %v", unit.State)
28592871
}

0 commit comments

Comments
 (0)