Skip to content

Commit 12d98ee

Browse files
committed
Add tests for steps within group steps
1 parent 4487e15 commit 12d98ee

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

pipeline_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,3 +825,36 @@ func TestGeneratePipelineWithSecretsInGroup(t *testing.T) {
825825
assert.Contains(t, string(got), "- PROD_DB_HOST")
826826
assert.Contains(t, string(got), "- PROD_DB_PASS")
827827
}
828+
829+
func TestGeneratePipelineWithNotifyInGroup(t *testing.T) {
830+
steps := []Step{{
831+
Group: "Test Group",
832+
Steps: []Step{{
833+
Label: "Run Tests",
834+
Command: "echo 'test'",
835+
Notify: []StepNotify{{
836+
GithubStatus: GithubStatusNotification{
837+
Context: "buildkite/test/status",
838+
},
839+
}},
840+
}},
841+
}}
842+
843+
plugin := Plugin{}
844+
845+
tmp, hasPipeline, err := generatePipeline(steps, plugin)
846+
assert.NoError(t, err)
847+
assert.True(t, hasPipeline)
848+
defer os.Remove(tmp.Name())
849+
850+
content, err := os.ReadFile(tmp.Name())
851+
assert.NoError(t, err)
852+
853+
output := string(content)
854+
855+
// Verify correct notify syntax (not rawnotify)
856+
assert.Contains(t, output, "notify:")
857+
assert.NotContains(t, output, "rawnotify")
858+
assert.Contains(t, output, "github_commit_status:")
859+
assert.Contains(t, output, "context: buildkite/test/status")
860+
}

plugin_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,43 @@ func TestPluginShouldClearRawEnvFromNestedSteps(t *testing.T) {
944944
assert.Nil(t, secondStep.Build.RawEnv, "Second nested step Build.RawEnv should be nil")
945945
}
946946

947+
func TestPluginShouldProcessNotifyInNestedSteps(t *testing.T) {
948+
param := `[{
949+
"github.com/buildkite-plugins/monorepo-diff-buildkite-plugin#v1.0.0": {
950+
"watch": [{
951+
"path": "foo/**",
952+
"config": {
953+
"group": "Foo",
954+
"steps": [{
955+
"command": "./scripts/a.sh",
956+
"label": "Run A",
957+
"notify": [{
958+
"github_commit_status": {
959+
"context": "buildkite/foo/a"
960+
}
961+
}]
962+
}]
963+
}
964+
}]
965+
}
966+
}]`
967+
968+
got, err := initializePlugin(param)
969+
assert.NoError(t, err)
970+
971+
// Verify nested step exists
972+
assert.Equal(t, 1, len(got.Watch[0].Step.Steps))
973+
974+
nestedStep := got.Watch[0].Step.Steps[0]
975+
976+
// Verify RawNotify is cleared
977+
assert.Nil(t, nestedStep.RawNotify, "RawNotify should be nil after processing")
978+
979+
// Verify Notify is populated
980+
assert.Equal(t, 1, len(nestedStep.Notify), "Notify should have 1 entry")
981+
assert.Equal(t, "buildkite/foo/a", nestedStep.Notify[0].GithubStatus.Context)
982+
}
983+
947984
func TestPluginShouldPreserveDependsOnString(t *testing.T) {
948985
param := `[{
949986
"github.com/buildkite-plugins/monorepo-diff-buildkite-plugin#commit": {

0 commit comments

Comments
 (0)