Skip to content

Commit

Permalink
Merge pull request #66 from ancorgs/cleanup_master
Browse files Browse the repository at this point in the history
Merging #65 to master
  • Loading branch information
ancorgs committed Jun 1, 2018
2 parents 9c56855 + 409cf57 commit bced586
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 74 deletions.
57 changes: 0 additions & 57 deletions src/modules/Nfs.rb
Expand Up @@ -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<Hash{String => 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<Hash{String => 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
Expand Down
94 changes: 77 additions & 17 deletions test/routines_test.rb
Expand Up @@ -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

Expand Down

0 comments on commit bced586

Please sign in to comment.