Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Using non local redis server for tests #184

Open
qgriffith-zz opened this issue May 13, 2016 · 6 comments
Open

Using non local redis server for tests #184

qgriffith-zz opened this issue May 13, 2016 · 6 comments

Comments

@qgriffith-zz
Copy link

I am running lita in a docker container that is linked to a another docker container using redis. I have the lita_config.rb setup to use the redis container. Lita itself is using the redis container properly. I am running into a issue when I try to run tests on handlers I have created that also use redis. I have a directory under lita called plugins/. I run rake -t inside that directory to run the test for that handler. It fails because it is trying to use redis on local host. I am assuming the tests are ignoring lita_config.rb and defaulting to local host for redis. Is there a way to make test use a separate redis hosts.

@jimmycuadra
Copy link
Collaborator

Try adding a before block that sets the configuration:

before do
  registry.config.redis[:host] = "dockerhost"
  registry.config.redis[:port] = 12345
end

@qgriffith-zz
Copy link
Author

Thanks for the tip. I gave it a try and it still attempts to use redis on local host. I even output the config to make sure it is being set properly.

require "spec_helper"

describe Lita::Handlers::Fridaypicks, lita_handler: true do

  it { is_expected.to route("#FridayPicks test") }

  before do
    registry.config.redis[:host] = ENV['REDIS_HOST']
    registry.config.redis[:port] = 6379
    puts registry.config.redis
  end

  it "lets add a pick" do
    send_message("#FridayPicks test")
    expect(replies.last).to match(/^I have stored the Friday Pick (.*)/)
  end
end

@ghost
Copy link

ghost commented Dec 27, 2016

Also, it seems weird that Redis is even needed for unit tests. Unit tests should not require external systems.

@atmosx
Copy link

atmosx commented Jan 5, 2018

@qgriffith did you manage to solve this somehow?!

@brodock
Copy link
Contributor

brodock commented Jun 6, 2018

Also looking for a solution

@brodock
Copy link
Contributor

brodock commented Jun 6, 2018

I got a nice suggestion from @atmosx on my mailbox, but somehow it's not showing up here.

I think I found out a different way to handle it. I'm trying to build this in GitLab CI, and there it provides redis as a docker service, which means it will be available as Host: redis instead of localhost etc.

This is what I've added to the spec_helper.rb for my lita plugin:

require 'pry'
require 'simplecov'
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
  SimpleCov::Formatter::HTMLFormatter,
]
SimpleCov.start { add_filter '/spec/' }

require 'lita-queue'
require 'lita/rspec'

# Patch for GitLab CI compatibility
if ENV['GITLAB_CI']
  Lita.configure do |config|
    config.redis[:host] = 'redis'
  end
end

# A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
# was generated with Lita 4, the compatibility mode should be left disabled.
Lita.version_3_compatibility_mode = false

By using the conditional there I can still run locally with local redis but when in CI it will use the correct host.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants