Skip to content

Commit

Permalink
Merge pull request #797 from BallAerospace/spaces_in_check_extract
Browse files Browse the repository at this point in the history
closes #790. Support spaces in telemetry check
  • Loading branch information
ryanmelt authored May 15, 2018
2 parents 8de6592 + 9ea163f commit bb2147c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/cosmos/script/extract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def extract_fields_from_cmd_text(text)
target_name = first_half[0]
cmd_name = first_half[1]
cmd_params = {}

begin
packet = System.commands.packet(target_name, cmd_name).clone
rescue
Expand Down Expand Up @@ -129,7 +129,9 @@ def extract_fields_from_check_text(text)
comparison_to_eval = nil
return [target_name, packet_name, item_name, comparison_to_eval] if split_string.length == 3
raise "ERROR: Check improperly specified: #{text}" if split_string.length < 4
comparison_to_eval = split_string[3..(split_string.length - 1)].join(" ")
split_string = text.split(/ /) # Split on regex spaces to preserve spaces in comparison
index = split_string.index(item_name)
comparison_to_eval = split_string[(index + 1)..(split_string.length - 1)].join(" ")
raise "ERROR: Use '==' instead of '=': #{text}" if split_string[3] == '='
return [target_name, packet_name, item_name, comparison_to_eval]
end
Expand Down
5 changes: 5 additions & 0 deletions spec/script/extract_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ module Cosmos
it "should complain about trying to do an = comparison" do
expect { extract_fields_from_check_text("TARGET PACKET ITEM = 5") }.to raise_error(/ERROR: Use/)
end

it "should handle spaces throughout correctly" do
expect(extract_fields_from_check_text("TARGET PACKET ITEM == \"This is a test\"")).to eql(['TARGET', 'PACKET', 'ITEM', "== \"This is a test\""])
expect(extract_fields_from_check_text("TARGET PACKET ITEM == 'This is a test '")).to eql(['TARGET', 'PACKET', 'ITEM', " == 'This is a test '"])
end
end

end
Expand Down

0 comments on commit bb2147c

Please sign in to comment.