Class: TestRunner::TestConfig
- Inherits:
-
Object
- Object
- TestRunner::TestConfig
- Defined in:
- lib/test-runner/test_config.rb
Instance Attribute Summary collapse
- #config_path ⇒ Test readonly
- #test ⇒ Test readonly
Class Method Summary collapse
- .build(test, config_path:, system: NixCli::DEFAULT_SYSTEM, test_config_path: nil, repo_root: nil) ⇒ Object
- .load(test, config_path:) ⇒ Object
Instance Method Summary collapse
- #[](key) ⇒ Object
- #build ⇒ Object
- #dig(*keys) ⇒ Object
-
#initialize(test, config_path:, system: NixCli::DEFAULT_SYSTEM, test_config_path: nil, repo_root: nil) ⇒ TestConfig
constructor
A new instance of TestConfig.
- #load ⇒ Object
- #validate!(scripts) ⇒ Object
Constructor Details
#initialize(test, config_path:, system: NixCli::DEFAULT_SYSTEM, test_config_path: nil, repo_root: nil) ⇒ TestConfig
Returns a new instance of TestConfig.
25 26 27 28 29 30 |
# File 'lib/test-runner/test_config.rb', line 25 def initialize(test, config_path:, system: NixCli::DEFAULT_SYSTEM, test_config_path: nil, repo_root: nil) @test = test @nix_options = { system:, test_config_path:, repo_root: } @config_path = config_path @config = {} end |
Instance Attribute Details
#config_path ⇒ Test (readonly)
21 22 23 |
# File 'lib/test-runner/test_config.rb', line 21 def config_path @config_path end |
#test ⇒ Test (readonly)
21 22 23 |
# File 'lib/test-runner/test_config.rb', line 21 def test @test end |
Class Method Details
.build(test, config_path:, system: NixCli::DEFAULT_SYSTEM, test_config_path: nil, repo_root: nil) ⇒ Object
8 9 10 11 12 |
# File 'lib/test-runner/test_config.rb', line 8 def self.build(test, config_path:, system: NixCli::DEFAULT_SYSTEM, test_config_path: nil, repo_root: nil) tc = new(test, system:, test_config_path:, repo_root:, config_path:) tc.build tc end |
.load(test, config_path:) ⇒ Object
14 15 16 17 18 |
# File 'lib/test-runner/test_config.rb', line 14 def self.load(test, config_path:) tc = new(test, config_path:) tc.load tc end |
Instance Method Details
#[](key) ⇒ Object
66 67 68 |
# File 'lib/test-runner/test_config.rb', line 66 def [](key) @config[key] end |
#build ⇒ Object
32 33 34 35 36 |
# File 'lib/test-runner/test_config.rb', line 32 def build FileUtils.mkdir_p(File.dirname(config_path)) NixCli.new(**@nix_options).build_test_json(test.path, config_path, test_args: test.test_args) load end |
#dig(*keys) ⇒ Object
70 71 72 |
# File 'lib/test-runner/test_config.rb', line 70 def dig(*keys) @config.dig(*keys) end |
#load ⇒ Object
38 39 40 |
# File 'lib/test-runner/test_config.rb', line 38 def load @config = JSON.parse(File.read(config_path)) end |
#validate!(scripts) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/test-runner/test_config.rb', line 42 def validate!(scripts) unless @config.is_a?(Hash) && @config['machines'].is_a?(Hash) && @config['testScripts'].is_a?(Hash) raise ArgumentError, "Invalid prepared configuration for #{test.path}" end scripts.each do |script| entry = @config['testScripts'][script.name] next if entry.is_a?(Hash) && entry['script'].is_a?(String) raise ArgumentError, "Missing or invalid prepared script #{script.path}" end @config['machines'].each_value do |machine| unless machine.is_a?(Hash) && machine['memory'].is_a?(Integer) && machine['memory'] > 0 && machine['cpus'].is_a?(Integer) && machine['cpus'] > 0 raise ArgumentError, "Invalid prepared machine for #{test.path}" end OsVm::MachineConfig.validate_config!(machine) end self end |