forks_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package core
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "gopkg.in/src-d/go-git.v4"
  6. )
  7. type testForkPipelineItem struct {
  8. NoopMerger
  9. Mutable map[int]bool
  10. Immutable string
  11. }
  12. func (item *testForkPipelineItem) Name() string {
  13. return "Test"
  14. }
  15. func (item *testForkPipelineItem) Provides() []string {
  16. arr := [...]string{"test"}
  17. return arr[:]
  18. }
  19. func (item *testForkPipelineItem) Requires() []string {
  20. return []string{}
  21. }
  22. func (item *testForkPipelineItem) Configure(facts map[string]interface{}) error {
  23. return nil
  24. }
  25. func (item *testForkPipelineItem) ListConfigurationOptions() []ConfigurationOption {
  26. return nil
  27. }
  28. func (item *testForkPipelineItem) Flag() string {
  29. return "mytest"
  30. }
  31. func (item *testForkPipelineItem) Features() []string {
  32. return nil
  33. }
  34. func (item *testForkPipelineItem) Initialize(repository *git.Repository) error {
  35. item.Mutable = map[int]bool{}
  36. return nil
  37. }
  38. func (item *testForkPipelineItem) Consume(deps map[string]interface{}) (map[string]interface{}, error) {
  39. return map[string]interface{}{"test": "foo"}, nil
  40. }
  41. func (item *testForkPipelineItem) Fork(n int) []PipelineItem {
  42. return ForkCopyPipelineItem(item, n)
  43. }
  44. func TestForkCopyPipelineItem(t *testing.T) {
  45. origin := &testForkPipelineItem{}
  46. origin.Initialize(nil)
  47. origin.Mutable[2] = true
  48. origin.Immutable = "before"
  49. clone := origin.Fork(1)[0].(*testForkPipelineItem)
  50. origin.Immutable = "after"
  51. origin.Mutable[1] = true
  52. assert.True(t, clone.Mutable[1])
  53. assert.True(t, clone.Mutable[2])
  54. assert.Equal(t, "before", clone.Immutable)
  55. }