Skip to content

Commit

Permalink
Merge pull request #583 from BallAerospace/fix_udp_localhost
Browse files Browse the repository at this point in the history
Fix casecmp logic
  • Loading branch information
jmthomas authored Sep 29, 2017
2 parents 25f8dd2 + ab49d62 commit e9da0b1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/cosmos/interfaces/udp_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def initialize(
@hostname = ConfigParser.handle_nil(hostname)
if @hostname
@hostname = @hostname.to_s
@hostname = '127.0.0.1' if @hostname.casecmp('LOCALHOST')
@hostname = '127.0.0.1' if @hostname.casecmp('LOCALHOST').zero?
end
@write_dest_port = ConfigParser.handle_nil(write_dest_port)
@write_dest_port = write_dest_port.to_i if @write_dest_port
Expand All @@ -51,7 +51,7 @@ def initialize(
@write_src_port = ConfigParser.handle_nil(write_src_port)
@write_src_port = @write_src_port.to_i if @write_src_port
@interface_address = ConfigParser.handle_nil(interface_address)
if @interface_address && @interface_address.casecmp('LOCALHOST')
if @interface_address && @interface_address.casecmp('LOCALHOST').zero?
@interface_address = '127.0.0.1'
end
@ttl = ttl.to_i
Expand All @@ -61,7 +61,7 @@ def initialize(
@read_timeout = ConfigParser.handle_nil(read_timeout)
@read_timeout = @read_timeout.to_f if @read_timeout
@bind_address = ConfigParser.handle_nil(bind_address)
if @bind_address && @bind_address.casecmp('LOCALHOST')
if @bind_address && @bind_address.casecmp('LOCALHOST').zero?
@bind_address = '127.0.0.1'
end
@write_socket = nil
Expand Down
2 changes: 1 addition & 1 deletion lib/cosmos/packets/telemetry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def items(target_name, packet_name)
# @param packet_name (see #packet) The packet name. LATEST is supported.
# @return [Array<PacketItem>] The telemetry item names for the given target and packet name
def item_names(target_name, packet_name)
if LATEST_PACKET_NAME.casecmp(packet_name) == 0
if LATEST_PACKET_NAME.casecmp(packet_name).zero?
target_upcase = target_name.to_s.upcase
target_latest_data = @config.latest_data[target_upcase]
raise "Telemetry Target '#{target_upcase}' does not exist" unless target_latest_data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def build_packet_to_data_objects_mapping
# Build the index into the hash of the form "TARGET_NAME PACKET_NAME"
# Note that + is used to create a new object and then << is used to concatenate
# to the new object.
if packet_name.casecmp(Telemetry::LATEST_PACKET_NAME) == 0
if packet_name.casecmp(Telemetry::LATEST_PACKET_NAME).zero?
packets = System.telemetry.latest_packets(target_name, data_object.item_name)
packets.each do |packet|
index = (packet.target_name + ' ') << packet.packet_name
Expand Down
10 changes: 8 additions & 2 deletions spec/interfaces/udp_interface_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ module Cosmos
describe UdpInterface do
describe "initialize" do
it "initializes the instance variables" do
i = UdpInterface.new('localhost','8888','8889','8890','127.0.0.1','64','5','5','127.0.0.1')
i = UdpInterface.new('localhost','8888','8889','8890','localhost','64','5','5','localhost')
expect(i.instance_variable_get("@hostname")).to eql '127.0.0.1'
expect(i.instance_variable_get("@interface_address")).to eql '127.0.0.1'
expect(i.instance_variable_get("@bind_address")).to eql '127.0.0.1'
i = UdpInterface.new('10.10.10.1','8888','8889','8890','10.10.10.2','64','5','5','10.10.10.3')
expect(i.instance_variable_get("@hostname")).to eql '10.10.10.1'
expect(i.instance_variable_get("@interface_address")).to eql '10.10.10.2'
expect(i.instance_variable_get("@bind_address")).to eql '10.10.10.3'
end

it "is not writeable if no write port given" do
Expand Down Expand Up @@ -237,4 +244,3 @@ module Cosmos
end
end
end

0 comments on commit e9da0b1

Please sign in to comment.