From 6ae5444a2d326dc5d18698bf7a17ffdca154dce8 Mon Sep 17 00:00:00 2001 From: Ancor Gonzalez Sosa Date: Thu, 31 May 2018 18:09:49 +0200 Subject: [PATCH 1/2] Remove dead code --- src/modules/Nfs.rb | 57 ---------------------------------------------- 1 file changed, 57 deletions(-) diff --git a/src/modules/Nfs.rb b/src/modules/Nfs.rb index 499cfcf..9ab8038 100644 --- a/src/modules/Nfs.rb +++ b/src/modules/Nfs.rb @@ -243,63 +243,6 @@ def Export deep_copy(settings) end - # ------------------------------------------------------------ - # Space escaping. - # This should be done by the agent, but any-agent sucks. - - # Escape spaces " " -> "\\040". - # @param [String] s a string or nil - # @return escaped string or nil - def EscapeSpaces1(s) - return nil if s.nil? - s.gsub(/ /) { "\\040" } # block prevents interpreting \ as backreference - end - - # Escape spaces " " -> "\\040" in all values of all entries - # @param [Array Object>}] entries a list of maps, such as nfs_entries - # @return escaped entries - def EscapeSpaces(entries) - entries = deep_copy(entries) - Builtins.maplist(entries) do |entry| - Builtins.mapmap(entry) do |key, value| - { - key => if Ops.is_string?(value) - EscapeSpaces1(Convert.to_string(value)) - else - value - end - } - end - end - end - - # Un-escape spaces "\\040" -> " " - # @param [String] s string or nil - # @return escaped string or nil - def UnescapeSpaces1(s) - return nil if s.nil? - # escaped space, \040, is /\\040/ - s.gsub(/\\040/, " ") - end - - # Un-escape spaces "\\040" -> " " in all values of all entries - # @param [Array Object>}] entries a list of maps, such as nfs_entries - # @return escaped entries - def UnescapeSpaces(entries) - entries = deep_copy(entries) - Builtins.maplist(entries) do |entry| - Builtins.mapmap(entry) do |key, value| - { - key => if Ops.is_string?(value) - UnescapeSpaces1(Convert.to_string(value)) - else - value - end - } - end - end - end - def FindPortmapper # testsuite is dumb - it can't distinguish between the existence # of two services - either both exists or both do not From 581e91f07a2c81014277a4b0b8a252a19a7c86bc Mon Sep 17 00:00:00 2001 From: Ancor Gonzalez Sosa Date: Thu, 31 May 2018 18:40:53 +0200 Subject: [PATCH 2/2] Break down unit test for #SpecToServPath --- test/routines_test.rb | 94 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 77 insertions(+), 17 deletions(-) diff --git a/test/routines_test.rb b/test/routines_test.rb index 246a203..29b065a 100755 --- a/test/routines_test.rb +++ b/test/routines_test.rb @@ -49,23 +49,83 @@ def main end describe "#SpecToServPath" do - # FIXME: separate in individual tests - it "returns a couple term with the server and the exported path params" do - term = subject.SpecToServPath("big.foo.com:/share/data") - expect(term.value).to eql(:couple) - expect(term.params).to eql(["big.foo.com", "/share/data"]) - term = subject.SpecToServPath("big.foo.com:") - expect(term.params).to eql(["big.foo.com", ""]) - term = subject.SpecToServPath("big.foo.com") - expect(term.params).to eql(["", "big.foo.com"]) - term = subject.SpecToServPath(":/only/path") - expect(term.params).to eql(["", "/only/path"]) - term = subject.SpecToServPath("/nocolon/only/path") - expect(term.params).to eql(["", "/nocolon/only/path"]) - term = subject.SpecToServPath("fe80::219:d1ff:feac:fd10:/path") - expect(term.params).to eql(["fe80::219:d1ff:feac:fd10", "/path"]) - term = subject.SpecToServPath("") - expect(term.params).to eql(["", ""]) + let(:term) { subject.SpecToServPath(spec) } + + RSpec.shared_examples "couple term" do + it "returns a :couple term" do + expect(term).to be_a Yast::Term + expect(term.value).to eql(:couple) + end + end + + context "for a spec with url and path separated by colon" do + let(:spec) { "big.foo.com:/share/data" } + + include_examples "couple term" + + it "returns a term in which the params are the url and the path" do + expect(term.params).to eql ["big.foo.com", "/share/data"] + end + end + + context "for a spec with url followed by a colon but no path" do + let(:spec) { "big.foo.com:" } + + include_examples "couple term" + + it "returns a term in which the params are the url and an empty string" do + expect(term.params).to eql ["big.foo.com", ""] + end + end + + context "for a spec with a string that looks like an url and no colon" do + let(:spec) { "big.foo.com" } + + include_examples "couple term" + + it "returns a term in which the params are an empty string and the full spec" do + expect(term.params).to eql ["", "big.foo.com"] + end + end + + context "for a spec with a string that looks like a path and no colon" do + let(:spec) { "/nocolon/only/path" } + + include_examples "couple term" + + it "returns a term in which the params are an empty string and the full spec" do + expect(term.params).to eql ["", "/nocolon/only/path"] + end + end + + context "for a spec containing only a colon followed by a path" do + let(:spec) { ":/only/path" } + + include_examples "couple term" + + it "returns a term in which the params are an empty string and the path" do + expect(term.params).to eql ["", "/only/path"] + end + end + + context "for a spec containing an IPv6 address (several colons) followed by a colon and a path" do + let(:spec) { "fe80::219:d1ff:feac:fd10:/path" } + + include_examples "couple term" + + it "returns a term in which the params are the IP address (including all its colons) and the path" do + expect(term.params).to eql ["fe80::219:d1ff:feac:fd10", "/path"] + end + end + + context "for an empty spec" do + let(:spec) { "" } + + include_examples "couple term" + + it "returns a term in which the params are two empty strings" do + expect(term.params).to eql ["", ""] + end end end