You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by se...@apache.org on 2019/09/26 19:25:59 UTC

[whimsy] branch master updated: Allow /srv/subscriptions to be overridden

This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new fa7654c  Allow /srv/subscriptions to be overridden
fa7654c is described below

commit fa7654c6b2eeacdeb0496e30786a394bb23488e5
Author: Sebb <se...@apache.org>
AuthorDate: Thu Sep 26 20:25:48 2019 +0100

    Allow /srv/subscriptions to be overridden
    
    Make it easy to test using same data as Travis
---
 .travis.yml              |  2 --
 lib/spec/spec_helper.rb  |  8 ++++++--
 lib/whimsy/asf/config.rb | 24 ++++++++++++++++++++++++
 lib/whimsy/asf/mlist.rb  | 13 +++++++++----
 4 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 2dfffab..5f9b952 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -34,8 +34,6 @@ sudo: required
 before_script:
   - export rvmsudo_secure_path=1
   - rvmsudo ruby -I $PWD/lib -r whimsy/asf -e "ASF::LDAP.configure"
-  - sudo mkdir /srv/subscriptions
-  - sudo cp lib/test/subscriptions/list-* /srv/subscriptions
 
 ########################################################################
 #                             Notification                             #
diff --git a/lib/spec/spec_helper.rb b/lib/spec/spec_helper.rb
index 0f6dcea..17b405b 100644
--- a/lib/spec/spec_helper.rb
+++ b/lib/spec/spec_helper.rb
@@ -2,13 +2,17 @@ $LOAD_PATH.unshift '/srv/whimsy/lib'
 
 require 'whimsy/asf'
 # Override with test data if there is no checkout available (allows local use)
-unless ASF::SVN.find('apmail_bin')
-  TEST_DATA = true # Test data does not yet support all tests
+unless ASF::SVN.find('apmail_bin') and not ENV['RAKE_TEST'] == 'TRUE'
+  TEST_DATA = true # Test data is smaller so some tests need adjusting
+  puts "Overriding data directories"
   ASF::SVN['apmail_bin'] = File.expand_path('../test/svn/apmail_bin', __dir__)
+  ASF::Config[:subscriptions] = File.expand_path('../test/subscriptions', __dir__)
 else
   TEST_DATA = false
 end
 
+puts "TEST_DATA=#{TEST_DATA}"
+
 unless defined?(SPEC_ROOT)
   SPEC_ROOT = File.join(File.dirname(__FILE__))
 end
diff --git a/lib/whimsy/asf/config.rb b/lib/whimsy/asf/config.rb
index ebf0080..b38e108 100644
--- a/lib/whimsy/asf/config.rb
+++ b/lib/whimsy/asf/config.rb
@@ -16,6 +16,9 @@ module ASF
 
     @config = YAML.load_file("#@home/.whimsy") rescue {}
 
+    # allow for test overrides
+    @testdata = {}
+
     # default :svn and :git
     @config[:svn] ||= '/srv/svn/*'
     @config[:git] ||= '/srv/git/*'
@@ -27,6 +30,14 @@ module ASF
     # see: http://mail-archives.apache.org/mod_mbox/whimsical-dev/201705.mbox/%3CCAFG6u8FJwvWvnd29O-cUZyQnCXrRvWSRDc11zaPx6_Y4ihnsfg%40mail.gmail.com%3E
     @config[:cache] ||= '/srv/cache'
 
+    # Contains the data files from the ezmlm mail server, e.g.
+    # list-subs - subscriptions
+    # list-mods - moderators
+    # The above are used by mlist.rb
+    # list-flags - flags domain listname
+    # The above are used by mail.rb
+    @config[:subscriptions] ||= '/srv/subscriptions'
+
     @config[:lib] ||= []
 
     # add gems to lib
@@ -51,6 +62,19 @@ module ASF
     def self.get(value)
       @config[value]
     end
+
+    # Look up a configuration value by name (generally a symbol, like
+    # <tt>:svn</tt>). Allows test overrides
+    def self.[](value)
+      @testdata[value] || @config[value]
+    end
+
+    # Set a local directory corresponding to a path  
+    # Useful as a test data override.
+    def self.[]=(name, path)
+      @testdata[name] = File.expand_path(path).untaint
+    end
+
   end
 
 end
diff --git a/lib/whimsy/asf/mlist.rb b/lib/whimsy/asf/mlist.rb
index fc27c34..0f96be8 100644
--- a/lib/whimsy/asf/mlist.rb
+++ b/lib/whimsy/asf/mlist.rb
@@ -1,4 +1,7 @@
+$LOAD_PATH.unshift '/srv/whimsy/lib'
+
 require 'weakref'
+require 'whimsy/asf/config'
 
 module ASF
 
@@ -381,15 +384,17 @@ module ASF
                  ARCH_MBOX_PUB, ARCH_MBOX_PRV, ARCH_MBOX_RST, ARCH_EXT_MAIL_ARCHIVE]
     # TODO alias archivers: either add list or use RE to filter them
 
-    LIST_MODS = '/srv/subscriptions/list-mods'
+    LIST_BASE = ASF::Config[:subscriptions] # allow overrides for testing etc
+
+    LIST_MODS = File.join(LIST_BASE, 'list-mods')
 
-    LIST_SUBS = '/srv/subscriptions/list-subs'
+    LIST_SUBS = File.join(LIST_BASE, 'list-subs')
 
-    LIST_DIGS = '/srv/subscriptions/list-digs'
+    LIST_DIGS = File.join(LIST_BASE, 'list-digs')
 
     # If this file exists, it is the time when the data was last extracted
     # The mods and subs files are only updated if they have changed
-    LIST_TIME = '/srv/subscriptions/list-start'
+    LIST_TIME = File.join(LIST_BASE, 'list-start')
 
   end
 end