Skip to content

Commit

Permalink
Update specs
Browse files Browse the repository at this point in the history
  • Loading branch information
m-o-e committed Oct 8, 2023
1 parent e9d20fb commit 3ad8477
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 55 deletions.
56 changes: 47 additions & 9 deletions spec/envcat/cli/input_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,59 @@ require "../../../src/envcat/cli"
require "digest/sha256"

describe Envcat::Cli do
describe "-i json:fixtures/input/test.json -s AGE=42" do
it "overwrites value from json" do
{% for fmt in %w[json yaml toml] %}
describe "-i {{fmt.id}}:fixtures/input/test.{{fmt.id}}" do
it "parses and normalizes {{fmt.id}}" do
expect_output(nil, nil) { |o, e, i|
Envcat::Cli.invoke(%w[-f kv -i json:fixtures/input/test.json -s AGE=42 AGE], o, e, i)
o.to_s.should eq("AGE=42\n")
Envcat::Cli.invoke(%w[-f yaml -i {{fmt.id}}:fixtures/input/test.{{fmt.id}} *], o, e, i)
puts o.to_s
Digest::SHA256.hexdigest(o.to_s.split("\n").sort.join("\n")).should eq("66dc73717712ef4ed7ac7fa0cd1ccad48c67b718c038fb9c2f852c10e52e77d6")
}
end
end

describe "-s AGE=42 -i json:fixtures/input/test.json" do
it "overwrites value from json" do
expect_output(nil, nil) { |o, e, i|
Envcat::Cli.invoke(%w[-f kv -s AGE=42 -i json:fixtures/input/test.json AGE], o, e, i)
o.to_s.should eq("AGE=42\n")
describe "-i {{fmt.id}}:fixtures/input/test.invalid" do
it "prints error and exits with code 11 if parsing fails" do
expect_output(nil, /Malformed input.*is not valid {{fmt.id.upcase}}/) { |o, e, i|
expect_raises(Exit, "11") {
Envcat::Cli.invoke(%w[-f yaml -i {{fmt.id}}:fixtures/input/test.invalid *], o, e, i)
}
}
end
end

describe "-i {{fmt.id}}:fixtures/input/test.notfound" do
it "prints error and exits with code 7 if input file doesn't exist" do
expect_output(nil, /No such file or directory/) { |o, e, i|
expect_raises(Exit, "7") {
Envcat::Cli.invoke(%w[-f yaml -i {{fmt.id}}:fixtures/input/test.notfound *], o, e, i)
}
}
end
end
{% end %}

{% for fmt in %w[env- derp] %}
describe "-i {{fmt.id}}" do
it "prints error and exits with code 3 if argument to -i is invalid" do
expect_output(nil, /Unknown input type/) { |o, e, i|
expect_raises(Exit, "3") {
Envcat::Cli.invoke(%w[-i {{fmt.id}} *], o, e, i)
}
}
end
end
{% end %}

{% for fmt in %w[yaml yaml: json json: toml toml:] %}
describe "-i {{fmt.id}}" do
it "prints error and exits with code 3 if argument to -i misses path" do
expect_output(nil, /Path is required/) { |o, e, i|
expect_raises(Exit, "3") {
Envcat::Cli.invoke(%w[-i {{fmt.id}} *], o, e, i)
}
}
end
end
{% end %}
end
55 changes: 9 additions & 46 deletions spec/envcat/cli/set_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,21 @@ require "../../../src/envcat/cli"
require "digest/sha256"

describe Envcat::Cli do
{% for fmt in %w[json yaml toml] %}
describe "-i {{fmt.id}}:fixtures/input/test.{{fmt.id}}" do
it "parses and normalizes {{fmt.id}}" do
describe "-i json:fixtures/input/test.json -s AGE=42" do
it "overwrites value from json" do
expect_output(nil, nil) { |o, e, i|
Envcat::Cli.invoke(%w[-f yaml -i {{fmt.id}}:fixtures/input/test.{{fmt.id}} *], o, e, i)
Digest::SHA256.hexdigest(o.to_s.split("\n").sort.join("\n")).should eq("66dc73717712ef4ed7ac7fa0cd1ccad48c67b718c038fb9c2f852c10e52e77d6")
Envcat::Cli.invoke(%w[-f kv -i json:fixtures/input/test.json -s AGE=42 AGE], o, e, i)
o.to_s.should eq("AGE=42\n")
}
end
end

describe "-i {{fmt.id}}:fixtures/input/test.invalid" do
it "prints error and exits with code 11 if parsing fails" do
expect_output(nil, /Malformed input.*is not valid {{fmt.id.upcase}}/) { |o, e, i|
expect_raises(Exit, "11") {
Envcat::Cli.invoke(%w[-f yaml -i {{fmt.id}}:fixtures/input/test.invalid *], o, e, i)
}
}
end
end

describe "-i {{fmt.id}}:fixtures/input/test.notfound" do
it "prints error and exits with code 7 if input file doesn't exist" do
expect_output(nil, /No such file or directory/) { |o, e, i|
expect_raises(Exit, "7") {
Envcat::Cli.invoke(%w[-f yaml -i {{fmt.id}}:fixtures/input/test.notfound *], o, e, i)
}
}
end
end
{% end %}

{% for fmt in %w[env- derp] %}
describe "-i {{fmt.id}}" do
it "prints error and exits with code 3 if argument to -i is invalid" do
expect_output(nil, /Unknown input type/) { |o, e, i|
expect_raises(Exit, "3") {
Envcat::Cli.invoke(%w[-i {{fmt.id}} *], o, e, i)
}
}
end
end
{% end %}

{% for fmt in %w[yaml yaml: json json: toml toml:] %}
describe "-i {{fmt.id}}" do
it "prints error and exits with code 3 if argument to -i misses path" do
expect_output(nil, /Path is required/) { |o, e, i|
expect_raises(Exit, "3") {
Envcat::Cli.invoke(%w[-i {{fmt.id}} *], o, e, i)
}
describe "-s AGE=42 -i json:fixtures/input/test.json" do
it "overwrites value from json" do
expect_output(nil, nil) { |o, e, i|
Envcat::Cli.invoke(%w[-f kv -s AGE=42 -i json:fixtures/input/test.json AGE], o, e, i)
o.to_s.should eq("AGE=42\n")
}
end
end
{% end %}
end

0 comments on commit 3ad8477

Please sign in to comment.