-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80a97b5
commit f344aa0
Showing
8 changed files
with
108 additions
and
1 deletion.
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
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
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,34 @@ | ||
package mapper | ||
|
||
import ( | ||
"github.com/springernature/halfpipe/manifest" | ||
) | ||
|
||
type gitTriggerMapper struct { | ||
} | ||
|
||
func (g gitTriggerMapper) Apply(original manifest.Manifest) (updated manifest.Manifest, err error) { | ||
updated = original | ||
updated.Triggers = g.updateGitTrigger(updated.Triggers) | ||
return updated, nil | ||
} | ||
|
||
func (g gitTriggerMapper) updateGitTrigger(triggerList manifest.TriggerList) (updated manifest.TriggerList) { | ||
for _, trigger := range triggerList { | ||
switch trigger := trigger.(type) { | ||
case manifest.GitTrigger: | ||
for i, path := range trigger.WatchedPaths { | ||
if path == "." { | ||
trigger.WatchedPaths[i] = trigger.BasePath | ||
} | ||
} | ||
updated = append(updated, trigger) | ||
default: | ||
updated = append(updated, trigger) | ||
} | ||
} | ||
return | ||
} | ||
func NewGitTriggerMapper() Mapper { | ||
return gitTriggerMapper{} | ||
} |
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,56 @@ | ||
package mapper | ||
|
||
import ( | ||
"github.com/springernature/halfpipe/manifest" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestGitTriggerMapper_Apply(t *testing.T) { | ||
t.Run("does nothing on empty manifest", func(t *testing.T) { | ||
input := manifest.Manifest{} | ||
expected := manifest.Manifest{} | ||
|
||
updated, err := NewGitTriggerMapper().Apply(input) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, expected, updated) | ||
}) | ||
|
||
t.Run("does nothing when there is no dot in the watched paths", func(t *testing.T) { | ||
input := manifest.Manifest{ | ||
Triggers: manifest.TriggerList{ | ||
manifest.GitTrigger{WatchedPaths: []string{"a", "b"}}, | ||
}, | ||
} | ||
expected := manifest.Manifest{ | ||
Triggers: manifest.TriggerList{ | ||
manifest.GitTrigger{WatchedPaths: []string{"a", "b"}}, | ||
}, | ||
} | ||
|
||
updated, err := NewGitTriggerMapper().Apply(input) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, expected, updated) | ||
}) | ||
|
||
t.Run("converts dots to base path", func(t *testing.T) { | ||
input := manifest.Manifest{ | ||
Triggers: manifest.TriggerList{ | ||
manifest.GitTrigger{WatchedPaths: []string{"a", "."}, BasePath: "some/path/to/something"}, | ||
}, | ||
} | ||
expected := manifest.Manifest{ | ||
Triggers: manifest.TriggerList{ | ||
manifest.GitTrigger{WatchedPaths: []string{"a", "some/path/to/something"}, BasePath: "some/path/to/something"}, | ||
}, | ||
} | ||
|
||
updated, err := NewGitTriggerMapper().Apply(input) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, expected, updated) | ||
}) | ||
|
||
} |
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