Skip to content

Commit

Permalink
Merge pull request #16 from glaszig/master
Browse files Browse the repository at this point in the history
fix memcache address handling
  • Loading branch information
benschwarz authored Oct 1, 2020
2 parents a187a30 + b569525 commit 46d90b9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: [ '2.4.x', '2.5.x', '2.6.x', '2.7.x' ]
ruby: [ '2.5.x', '2.6.x', '2.7.x' ]
steps:
- name: Install memcache
run: |
Expand Down
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.5.8
2 changes: 1 addition & 1 deletion config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ require 'amnesia'
Encoding.default_internal = 'utf-8'
Encoding.default_external = 'utf-8'

use Amnesia::Application, hosts: ['localhost:11211', 'example.local:10987']
use Amnesia::Application, hosts: ['localhost', 'example.local:10987']
run Sinatra::Application
8 changes: 7 additions & 1 deletion lib/amnesia/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ class Host
FLOAT_STATS = %w[ rusage_user rusage_system ]
STRING_STATS = %w[ version libevent ]

def self.normalize_address address
return "#{address}:#{Dalli::Server::DEFAULT_PORT}" unless address.include? ":"

address
end

def initialize(address)
@address = address
@address = self.class.normalize_address address
end

def alive?
Expand Down
7 changes: 6 additions & 1 deletion spec/amnesia_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@
end

it "should respond to /:host" do
get "/127.0.0.1:11211"
get "/localhost:11211"
expect(last_response.status).to eq 200
end

it "should respond to /:host without port with not found" do
get "/localhost"
expect(last_response.status).to eq 404
end

it "should not display unknown host" do
get "/unknown-host"
expect(last_response.status).to eq 404
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

ENV['RACK_ENV'] ||= 'test'
ENV['AMNESIA_CREDS'] ||= 'admin:amnesia'
ENV['MEMCACHE_SERVERS'] ||= 'localhost'

require 'rack/test'
require 'amnesia'
Expand Down

0 comments on commit 46d90b9

Please sign in to comment.