Skip to content

Commit

Permalink
Adding #labels 🎯
Browse files Browse the repository at this point in the history
  • Loading branch information
shettytejas committed Jan 9, 2024
1 parent 1d4f601 commit 01f6717
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 0 deletions.
51 changes: 51 additions & 0 deletions fixtures/vcr_cassettes/labels/with_name_param_as_array.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions fixtures/vcr_cassettes/labels/with_name_param_as_string.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions fixtures/vcr_cassettes/labels/without_name_param.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions lib/azure_app_config/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ def fetch(name, label: nil)
parse_fetch_response response
end

def labels(name: nil)
name, _ = normalise_parameters(name: name, label: nil)
path = "/labels"

query_params = URI.encode_www_form(name: name.join(","))
parse_labels_response client.get(path, query_params)
end

def keys(name: nil)
name, = normalise_parameters(name: name, label: nil)
path = "/keys"
Expand Down Expand Up @@ -120,5 +128,9 @@ def parse_keys_response(response)
data = JSON.parse(response.body)
data["items"].map { |item| item["name"].gsub(key_prefix, "") }
end

def parse_labels_response(response)
JSON.parse(response.body)["items"].map { |item| item["name"] }
end
end
end
46 changes: 46 additions & 0 deletions spec/azure_app_config/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,59 @@
end
end

describe "#labels" do
subject(:result) { described_class.instance.labels(name: name) }

describe "without name param" do
let(:name) { nil }

it "returns all labels" do
VCR.use_cassette("labels/without_name_param") do
expect(result).to be_a Array

expect(result.size).to be > 0
expect(result).to match_array([nil, "prod", "test"])
end
end
end

describe "with name param" do
describe "as string" do
let(:name) { "p*" }

it "returns matching labels" do
VCR.use_cassette("labels/with_name_param_as_string") do
expect(result).to be_a Array

expect(result.size).to eq 1
expect(result).to(be_all { |k| k.start_with?(name.chomp("*")) })
end
end
end

describe "as array" do
let(:name) { ["prod", "test"] }

it "returns matching labels" do
VCR.use_cassette("labels/with_name_param_as_array") do
expect(result).to be_a Array

expect(result.size).to eq 2
expect(result).to(be_all { |k| name.include?(k) })
end
end
end
end
end

describe "#method_missing" do
it "testing if all the above methods work as expected" do
expect(described_class).to respond_to(:all)
expect(described_class).to respond_to(:fetch)
expect(described_class).to respond_to(:disabled?)
expect(described_class).to respond_to(:enabled?)
expect(described_class).to respond_to(:keys)
expect(described_class).to respond_to(:labels)

expect(described_class).not_to respond_to(:some_wrong_method)
end
Expand Down

0 comments on commit 01f6717

Please sign in to comment.