machine_tag_set_spec.rb 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. require 'spec_helper'
  2. describe MachineTag::Set do
  3. it 'should create sets with plain tags' do
  4. tags = MachineTag::Set['a', 'b', 'c']
  5. tags.should eq Set['a', 'b', 'c']
  6. tags.plain_tags.should eq Set['a', 'b', 'c']
  7. tags.machine_tags.should be_empty
  8. end
  9. it 'should create sets with machine tags' do
  10. tags = MachineTag::Set['a:b=x', 'a:b=y', 'a:c=z', 'd:e=f']
  11. tags.should eq Set['a:b=x', 'a:b=y', 'a:c=z', 'd:e=f']
  12. tags.plain_tags.should be_empty
  13. tags.machine_tags.should eq Set['a:b=x', 'a:b=y', 'a:c=z', 'd:e=f']
  14. tags['a'].should eq Set['a:b=x', 'a:b=y', 'a:c=z']
  15. tags['a:b'].should eq Set['a:b=x', 'a:b=y']
  16. tags['a', 'c'].should eq Set['a:c=z']
  17. end
  18. it 'should create sets with mixed plain and machine tags' do
  19. tags = MachineTag::Set['a:b=x', 'a:b=y', 'a:c=z', 'd', 'e', 'f']
  20. tags.should eq Set['a:b=x', 'a:b=y', 'a:c=z', 'd', 'e', 'f']
  21. tags.plain_tags.should eq Set['d', 'e', 'f']
  22. tags.machine_tags.should eq Set['a:b=x', 'a:b=y', 'a:c=z']
  23. tags['a'].should eq Set['a:b=x', 'a:b=y', 'a:c=z']
  24. tags['a:b'].should eq Set['a:b=x', 'a:b=y']
  25. tags['a', 'c'].should eq Set['a:c=z']
  26. end
  27. describe '#add' do
  28. let(:tags) { MachineTag::Set.new }
  29. it 'should add strings' do
  30. tags << 'a'
  31. tags.first.should be_an_instance_of(MachineTag::Tag)
  32. end
  33. it 'should add tags' do
  34. tag = MachineTag::Tag.new('a')
  35. tags << tag
  36. tags.first.should be(tag)
  37. end
  38. end
  39. describe '#[]' do
  40. let(:tags) { MachineTag::Set.new }
  41. it 'should not retrieve with an invalid predicate' do
  42. expect do
  43. tags['a', '!']
  44. end.to raise_error(ArgumentError, 'Invalid machine tag predicate: "!"')
  45. end
  46. it 'should not retrieve with a combined namespace and predicate and a predicate' do
  47. expect do
  48. tags['a:b', 'c']
  49. end.to raise_error(ArgumentError, 'Separate predicate passed with namespace and predicate: "a:b", "c"')
  50. end
  51. it 'should not retreive with an invalid namespace and/or predicate' do
  52. expect do
  53. tags['!']
  54. end.to raise_error(ArgumentError, 'Invalid machine tag namespace and/or predicate: "!", nil')
  55. expect do
  56. tags['a:!']
  57. end.to raise_error(ArgumentError, 'Invalid machine tag namespace and/or predicate: "a:!", nil')
  58. end
  59. end
  60. end