Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
300 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'unleash' | ||
require 'unleash/context' | ||
require 'unleash/bootstrap/from_file' | ||
|
||
puts ">> START bootstrap.rb" | ||
|
||
@unleash = Unleash::Client.new( | ||
url: 'http://unleash.herokuapp.com/api', | ||
custom_http_headers: { 'Authorization': '943ca9171e2c884c545c5d82417a655fb77cec970cc3b78a8ff87f4406b495d0' }, | ||
app_name: 'bootstrap-test', | ||
instance_id: 'local-test-cli', | ||
refresh_interval: 2, | ||
metrics_interval: 2, | ||
retry_limit: 2, | ||
bootstrap_data: Unleash::Bootstrap::FromFile.new('./examples/default-toggles.json').read | ||
) | ||
|
||
feature_name = "featureX" | ||
unleash_context = Unleash::Context.new | ||
unleash_context.user_id = 123 | ||
|
||
sleep 1 | ||
3.times do | ||
if @unleash.is_enabled?(feature_name, unleash_context) | ||
puts "> #{feature_name} is enabled" | ||
else | ||
puts "> #{feature_name} is not enabled" | ||
end | ||
sleep 1 | ||
puts "---" | ||
puts "" | ||
puts "" | ||
end | ||
|
||
sleep 3 | ||
feature_name = "foobar" | ||
if @unleash.is_enabled?(feature_name, unleash_context, true) | ||
puts "> #{feature_name} is enabled" | ||
else | ||
puts "> #{feature_name} is not enabled" | ||
end | ||
|
||
puts "> shutting down client..." | ||
|
||
@unleash.shutdown | ||
|
||
puts ">> END bootstrap.rb" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
{ | ||
"version": 1, | ||
"features": [ | ||
{ | ||
"name": "featureX", | ||
"enabled": true, | ||
"strategies": [ | ||
{ | ||
"name": "default" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "featureY", | ||
"enabled": false, | ||
"strategies": [ | ||
{ | ||
"name": "baz", | ||
"parameters": { | ||
"foo": "bar" | ||
} | ||
} | ||
] | ||
|
||
}, | ||
{ | ||
"name": "featureZ", | ||
"enabled": true, | ||
"strategies": [ | ||
{ | ||
"name": "default" | ||
}, | ||
{ | ||
"name": "hola", | ||
"parameters": { | ||
"name": "val" | ||
} | ||
} | ||
] | ||
|
||
} | ||
]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Unleash | ||
module Bootstrap | ||
class NotImplemented < RuntimeError | ||
end | ||
|
||
class Base | ||
def read | ||
raise NotImplemented, "Bootstrap is not implemented" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Unleash | ||
module Bootstrap | ||
class FromFile < Base | ||
# @param file_path [String] | ||
def self.read(file_path) | ||
File.read(file_path) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Unleash | ||
module Bootstrap | ||
class FromUri < Base | ||
# @param url [String] | ||
# @param headers [Hash, nil] HTTP headers to use. If not set, the unleash client SDK ones will be used. | ||
def self.read(url, headers = nil) | ||
response = Unleash::Util::Http.get(URI.parse(url), nil, headers) | ||
|
||
return nil if response.code != '200' | ||
|
||
response.body | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"version": 1, | ||
"features": [ | ||
{ | ||
"name": "featureX", | ||
"enabled": true, | ||
"strategies": [ | ||
{ | ||
"name": "default" | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'spec_helper' | ||
require 'rspec/json_expectations' | ||
require 'unleash/bootstrap/base' | ||
require 'unleash/bootstrap/from_file' | ||
require 'json' | ||
|
||
RSpec.describe Unleash::Bootstrap::FromFile do | ||
before do | ||
Unleash.configuration = Unleash::Configuration.new | ||
Unleash.logger = Unleash.configuration.logger | ||
end | ||
|
||
it 'loads bootstrap toggle correctly from file' do | ||
bootstrap_file = './spec/unleash/bootstrap-resources/features-v1.json' | ||
|
||
bootstrap_contents = Unleash::Bootstrap::FromFile.read(bootstrap_file) | ||
bootstrap_features = JSON.parse(bootstrap_contents)['features'] | ||
|
||
file_contents = File.open(bootstrap_file).read | ||
file_features = JSON.parse(file_contents)['features'] | ||
|
||
expect(bootstrap_features).to include_json(file_features) | ||
end | ||
end |
Oops, something went wrong.