Skip to content

Commit

Permalink
lint a random file (#3191)
Browse files Browse the repository at this point in the history
  • Loading branch information
osc-bot authored Nov 16, 2023
1 parent 5b28c18 commit d291b21
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions apps/myjobs/test/models/configuration_singleton_test.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# frozen_string_literal: true

require 'test_helper'

# FIXME: move to system directory for system tests

class ConfigurationSingletonTest < ActiveSupport::TestCase
#FIXME: this approach is ugly and difficult to follow
# FIXME: this approach is ugly and difficult to follow
#
# Marshaling the Configuration doesn't work because the methods are evaluated when
# you call them: Configuration doesn't store data for most of its options.
Expand Down Expand Up @@ -31,72 +33,74 @@ def runner(code, env: 'development', envvars: '')
#
# @return [OpenStruct] attrs have values set in Configuration after initialization
def config_via_runner(env: 'development', envvars: '')
code = %q(puts Marshal.dump(
code = 'puts Marshal.dump(
OpenStruct.new(
dataroot: Configuration.dataroot,
production_database_path: Configuration.production_database_path,
load_external_config: Configuration.load_external_config?,
show_job_options_account_field: Configuration.show_job_options_account_field?
)
)
)
'
Marshal.load(runner(code, env: env, envvars: envvars))
end

test "tests should not be run with .env.local* files in directory" do
assert Dir.glob(".env.local{.development,.production,}").none?, "these tests should not be run with a .env.local or .env.local.development or .env.local.production"
test 'tests should not be run with .env.local* files in directory' do
assert Dir.glob('.env.local{.development,.production,}').none?,
'these tests should not be run with a .env.local or .env.local.development or .env.local.production'
end

test "configuration defaults in development env" do
test 'configuration defaults in development env' do
config = config_via_runner

assert_equal Rails.root.join("data").to_s, config.dataroot.to_s
assert_equal Rails.root.join('data').to_s, config.dataroot.to_s
refute config.load_external_config
assert config.show_job_options_account_field
end

test "loading custom OSC external config in production env" do
config_root = Rails.root.join('config','examples','osc')
test 'loading custom OSC external config in production env' do
config_root = Rails.root.join('config', 'examples', 'osc')
config = config_via_runner(env: 'production', envvars: "OOD_APP_CONFIG_ROOT=#{config_root}")

assert_equal File.expand_path("~/ondemand/data/sys/myjobs"), config.dataroot.to_s
assert_equal File.expand_path("~/ondemand/data/sys/myjobs/production.sqlite3"), config.production_database_path.to_s
assert_equal File.expand_path('~/ondemand/data/sys/myjobs'), config.dataroot.to_s
assert_equal File.expand_path('~/ondemand/data/sys/myjobs/production.sqlite3'), config.production_database_path.to_s
assert_equal true, config.load_external_config
end

test "loading custom AweSim external config in production env" do
config_root = Rails.root.join('config','examples','awesim')
test 'loading custom AweSim external config in production env' do
config_root = Rails.root.join('config', 'examples', 'awesim')
config = config_via_runner(env: 'production', envvars: "OOD_APP_CONFIG_ROOT=#{config_root}")

assert_equal File.expand_path("~/awesim/data/sys/myjobs"), config.dataroot.to_s
assert_equal File.expand_path("~/awesim/data/sys/myjobs/production.sqlite3"), config.production_database_path.to_s
assert_equal File.expand_path('~/awesim/data/sys/myjobs'), config.dataroot.to_s
assert_equal File.expand_path('~/awesim/data/sys/myjobs/production.sqlite3'), config.production_database_path.to_s
assert_equal true, config.load_external_config
end

test "setting dataroot and database path" do
test 'setting dataroot and database path' do
Bundler.with_unbundled_env do
ENV['OOD_DATAROOT'] = nil
ENV['RAILS_ENV'] = 'production'

# default
assert_equal File.expand_path("~/ondemand/data/sys/myjobs"), ConfigurationSingleton.new.dataroot.to_s
assert_equal File.expand_path("~/ondemand/data/sys/myjobs/production.sqlite3"), ConfigurationSingleton.new.production_database_path.to_s
assert_equal File.expand_path('~/ondemand/data/sys/myjobs'), ConfigurationSingleton.new.dataroot.to_s
assert_equal File.expand_path('~/ondemand/data/sys/myjobs/production.sqlite3'),
ConfigurationSingleton.new.production_database_path.to_s

# set to tmp dir
ENV['OOD_DATAROOT'] = "/tmp/myjobs"
assert_equal "/tmp/myjobs", ConfigurationSingleton.new.dataroot.to_s
assert_equal "/tmp/myjobs/production.sqlite3", ConfigurationSingleton.new.production_database_path.to_s
ENV['OOD_DATAROOT'] = '/tmp/myjobs'
assert_equal '/tmp/myjobs', ConfigurationSingleton.new.dataroot.to_s
assert_equal '/tmp/myjobs/production.sqlite3', ConfigurationSingleton.new.production_database_path.to_s

# set seprate database path
ENV['DATABASE_PATH'] = "/tmp/db.sqlite3"
assert_equal "/tmp/db.sqlite3", ConfigurationSingleton.new.production_database_path.to_s
ENV['DATABASE_PATH'] = '/tmp/db.sqlite3'
assert_equal '/tmp/db.sqlite3', ConfigurationSingleton.new.production_database_path.to_s

ENV['DATABASE_PATH'] = "~root/db.sqlite3"
assert_equal "/root/db.sqlite3", ConfigurationSingleton.new.production_database_path.to_s
ENV['DATABASE_PATH'] = '~root/db.sqlite3'
assert_equal '/root/db.sqlite3', ConfigurationSingleton.new.production_database_path.to_s
end
end

test "hide account field" do
test 'hide account field' do
Bundler.with_unbundled_env do
assert ConfigurationSingleton.new.show_job_options_account_field?

Expand Down

0 comments on commit d291b21

Please sign in to comment.