Merge pull request #7 from BraydonKains/NonStrictName

Find process now matches on partial names and outputs all processes t…
nat_runner
Braydon Kains 5 years ago committed by GitHub
commit b5e6421cfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -22,8 +22,8 @@ class LtnpOperator
@ltnp_records.find { |r| r.port == port } @ltnp_records.find { |r| r.port == port }
end end
def search_p_name(p_name : String) : LtnpRecord | Nil def search_p_name(p_name : String) : Array(LtnpRecord)
@ltnp_records.find { |r| r.p_name == p_name } @ltnp_records.select { |r| r.p_name.includes?(p_name) }
end end
# Actions # Actions
@ -43,12 +43,12 @@ class LtnpOperator
# -p, --find-process # -p, --find-process
def find_process(p_name : String) def find_process(p_name : String)
record = search_p_name p_name records = search_p_name p_name
unless record.nil? unless records.empty?
result = record.output_s result = records.map { |record| record.output_s }.join("\n")
else else
result = "No process found by the name %s" % p_name result = "No processes found that match the name %s" % p_name
end end
result result

@ -8,6 +8,8 @@ describe LtnpOperator do
nonsense_port = "1234" nonsense_port = "1234"
existing_p_name = "polymer" existing_p_name = "polymer"
partial_existing_p_name = "poly"
multiple_exist_p_name = "spotify"
nonsense_p_name = "thisisnotathing" nonsense_p_name = "thisisnotathing"
describe "#get_port_record" do describe "#get_port_record" do
@ -22,11 +24,11 @@ describe LtnpOperator do
describe "#search_p_name" do describe "#search_p_name" do
it "should find record when process exists" do it "should find record when process exists" do
sut.search_p_name(existing_p_name).nil?.should be_false sut.search_p_name(existing_p_name).empty?.should be_false
end end
it "should not find record when process doesn't exist" do it "should not find record when process doesn't exist" do
sut.search_p_name(nonsense_p_name).nil?.should be_true sut.search_p_name(nonsense_p_name).empty?.should be_true
end end
end end
@ -41,10 +43,18 @@ describe LtnpOperator do
end end
describe "#find_process" do describe "#find_process" do
it "should output successful message if found" do it "should output successful message if full match found" do
sut.find_process(existing_p_name).should contain("Process:") sut.find_process(existing_p_name).should contain("Process:")
end end
it "should output successful message if partial match found" do
sut.find_process(partial_existing_p_name).should contain("Process:")
end
it "should output every found process" do
sut.find_process(multiple_exist_p_name).each_line.size.should eq 2
end
it "should output failure message if not found" do it "should output failure message if not found" do
sut.find_process(nonsense_p_name).should contain("No") sut.find_process(nonsense_p_name).should contain("No")
end end

Loading…
Cancel
Save