forks_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package core
  2. import (
  3. "testing"
  4. "gopkg.in/src-d/go-git.v4"
  5. "github.com/stretchr/testify/assert"
  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{}) {
  23. }
  24. func (item *testForkPipelineItem) ListConfigurationOptions() []ConfigurationOption {
  25. return nil
  26. }
  27. func (item *testForkPipelineItem) Flag() string {
  28. return "mytest"
  29. }
  30. func (item *testForkPipelineItem) Features() []string {
  31. return nil
  32. }
  33. func (item *testForkPipelineItem) Initialize(repository *git.Repository) {
  34. item.Mutable = map[int]bool{}
  35. }
  36. func (item *testForkPipelineItem) Consume(deps map[string]interface{}) (map[string]interface{}, error) {
  37. return map[string]interface{}{"test": "foo"}, nil
  38. }
  39. func (item *testForkPipelineItem) Fork(n int) []PipelineItem {
  40. return ForkCopyPipelineItem(item, n)
  41. }
  42. func TestForkCopyPipelineItem(t *testing.T) {
  43. origin := &testForkPipelineItem{}
  44. origin.Initialize(nil)
  45. origin.Mutable[2] = true
  46. origin.Immutable = "before"
  47. clone := origin.Fork(1)[0].(*testForkPipelineItem)
  48. origin.Immutable = "after"
  49. origin.Mutable[1] = true
  50. assert.True(t, clone.Mutable[1])
  51. assert.True(t, clone.Mutable[2])
  52. assert.Equal(t, "before", clone.Immutable)
  53. }