Skip to content
Browse files

Rewrite settings handling tests to match changes in settings.

  • Loading branch information...
1 parent 8646ada commit a7cc5f3ba51b1a1cb5009278b7f1296dd17f8620 @bigpresh committed
Showing with 56 additions and 20 deletions.
  1. +56 −20 t/01-parse-config.t
View
76 t/01-parse-config.t
@@ -1,38 +1,74 @@
#!perl -T
-# Test the config setting parsing.
-package main;
+# Tests for channel/auth settings handling.
+#
+# Mock the bot store with known settings, then check we get the right info back.
+
+
+# Fake bot storage; pretend to be the Store module, to some degree.
+# Instantiated with a hashref of settings, stores then in the object, and
+# returns them when asked for
+package MockStore;
use strict;
-use Bot::BasicBot::Pluggable::Module::GitHub;
+sub new {
+ my ($class, $settings) = @_;
+ return bless { settings => $settings } => $class;
+}
+sub get {
+ my ($self, $namespace, $key) = @_;
+ return unless $namespace eq 'GitHub';
+ return $self->{settings}{$key};
+}
+
# Subclass to override fetching of config setting from store
package MockBot;
use base 'Bot::BasicBot::Pluggable::Module::GitHub';
sub get {
- return shift->{_fake_config_setting};
+ my ($self,$setting) = @_;
+ return $self->{_conf}{$setting};
+}
+sub store {
+ my $self = shift;
+ return $self->{_store};
}
-
# On with the show...
package main;
+use strict;
+use Bot::BasicBot::Pluggable::Module::GitHub;
+
+
+package main;
use Test::More tests => 4;
my $plugin = MockBot->new;
-# First, if we provide an overall project for all channels, we should get it
-# back for a random channel:
-$plugin->{_fake_config_setting} = 'user/repo';
-is($plugin->github_project('#fake'), 'user/repo',
- "Configuring repo for all channels works");
-
-# Now, if we configure different projects for different channels, make sure they
-# work:
-$plugin->{_fake_config_setting} = '#chan1:user1/repo1;#chan2:user2/repo2';
-is($plugin->github_project('#chan1'), 'user1/repo1',
- "Per-channel repo works");
-is($plugin->github_project('#chan2'), 'user2/repo2',
- "Per-channel repo works");
-is ($plugin->github_project('#fake'), undef,
- "Per-channel repo returns nothing for non-matching channel");
+# Set some projects for channels, then we can test we get the right info back
+$plugin->{_store} = MockStore->new({
+ project_for_channel => {
+ '#foo' => 'someuser/foo',
+ '#bar' => 'bobby/tables',
+ },
+ auth_for_project => {
+ 'bobby/tables' => 'bobby:tables',
+ },
+});
+
+
+
+is($plugin->project_for_channel('#foo'), 'someuser/foo',
+ 'Got expected project for a channel'
+);
+
+is($plugin->project_for_channel('#fake'), undef,
+ 'Got undef project for non-configured channel'
+);
+is($plugin->auth_for_project('bobby/tables'), 'bobby:tables',
+ 'Got expected auth info for a project'
+);
+is($plugin->auth_for_project('fake/project'), undef,
+ 'Got undef auth info for non-configured project'
+);

0 comments on commit a7cc5f3

Please sign in to comment.
Something went wrong with that request. Please try again.