-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for pipedv1 executor package
Signed-off-by: khanhtc1202 <[email protected]>
- Loading branch information
1 parent
8b49a84
commit 9b61c4a
Showing
3 changed files
with
143 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2024 The PipeCD Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package executor | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/pipe-cd/pipecd/pkg/model" | ||
) | ||
|
||
func TestDetermineStageStatus(t *testing.T) { | ||
testcases := []struct { | ||
name string | ||
sig StopSignalType | ||
ori model.StageStatus | ||
got model.StageStatus | ||
expected model.StageStatus | ||
}{ | ||
{ | ||
name: "No stop signal, should get got status", | ||
sig: StopSignalNone, | ||
ori: model.StageStatus_STAGE_RUNNING, | ||
got: model.StageStatus_STAGE_SUCCESS, | ||
expected: model.StageStatus_STAGE_SUCCESS, | ||
}, { | ||
name: "Terminated signal given, should get original status", | ||
sig: StopSignalTerminate, | ||
ori: model.StageStatus_STAGE_RUNNING, | ||
got: model.StageStatus_STAGE_SKIPPED, | ||
expected: model.StageStatus_STAGE_RUNNING, | ||
}, { | ||
name: "Timeout signal given, should get failed status", | ||
sig: StopSignalTimeout, | ||
ori: model.StageStatus_STAGE_RUNNING, | ||
got: model.StageStatus_STAGE_RUNNING, | ||
expected: model.StageStatus_STAGE_FAILURE, | ||
}, { | ||
name: "Cancel signal given, should get cancelled status", | ||
sig: StopSignalCancel, | ||
ori: model.StageStatus_STAGE_RUNNING, | ||
got: model.StageStatus_STAGE_RUNNING, | ||
expected: model.StageStatus_STAGE_CANCELLED, | ||
}, { | ||
name: "Unknown signal type given, should get failed status", | ||
sig: StopSignalType("unknown"), | ||
ori: model.StageStatus_STAGE_RUNNING, | ||
got: model.StageStatus_STAGE_RUNNING, | ||
expected: model.StageStatus_STAGE_FAILURE, | ||
}, | ||
} | ||
|
||
for _, tc := range testcases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
tc.got = DetermineStageStatus(tc.sig, tc.ori, tc.got) | ||
assert.Equal(t, tc.expected, tc.got) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2024 The PipeCD Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package executor | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewStopSignal(t *testing.T) { | ||
signal, handler := NewStopSignal() | ||
assert.NotNil(t, signal) | ||
assert.NotNil(t, signal.Context()) | ||
assert.NotNil(t, signal.Ch()) | ||
assert.NotNil(t, handler) | ||
assert.Equal(t, StopSignalNone, signal.Signal()) | ||
} | ||
|
||
func TestCancel(t *testing.T) { | ||
signal, handler := NewStopSignal() | ||
handler.Cancel() | ||
assert.Equal(t, StopSignalCancel, signal.Signal()) | ||
assert.Equal(t, StopSignalCancel, <-signal.Ch()) | ||
} | ||
|
||
func TestTimeout(t *testing.T) { | ||
signal, handler := NewStopSignal() | ||
handler.Timeout() | ||
assert.Equal(t, StopSignalTimeout, signal.Signal()) | ||
assert.Equal(t, StopSignalTimeout, <-signal.Ch()) | ||
} | ||
|
||
func TestTerminate(t *testing.T) { | ||
signal, handler := NewStopSignal() | ||
handler.Terminate() | ||
assert.Equal(t, StopSignalTerminate, signal.Signal()) | ||
assert.Equal(t, StopSignalTerminate, <-signal.Ch()) | ||
} | ||
|
||
func TestTerminated(t *testing.T) { | ||
signal, handler := NewStopSignal() | ||
assert.False(t, signal.Terminated()) | ||
handler.Terminate() | ||
assert.True(t, signal.Terminated()) | ||
} |