Class: GroongaClientModel::Test::GroongaServerRunner

Inherits:
Groonga::Client::Test::GroongaServerRunner
  • Object
show all
Defined in:
lib/groonga_client_model/test/groonga_server_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(parallel_test: false) ⇒ GroongaServerRunner

Returns a new instance of GroongaServerRunner.



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/groonga_client_model/test/groonga_server_runner.rb', line 29

def initialize(parallel_test: false)
  super()
  if parallel_test
    host = "127.0.0.1"
    port = TCPServer.open(host, 0) do |server|
      server.addr[1]
    end
    Client.url = "http://#{host}:#{port}"
  end
  @client = Client.new
end

Instance Method Details

#runObject



41
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/groonga_client_model/test/groonga_server_runner.rb', line 41

def run
  super
  return if using_running_server?

  if defined?(Rails)
    base_dir = Rails.root
  else
    base_dir = Pathname.pwd
  end

  schema_path = base_dir + SchemaLoader.default_path
  migrate_path = base_dir + Migrator.default_search_path
  if schema_path.exist?
    schema_path.open do |schema_file|
      schema_loader = SchemaLoader.new(schema_file)
      schema_loader.load
    end
  elsif migrate_path.exist?
    output = StringIO.new
    migrator = Migrator.new(migrate_path)
    migrator.output = output
    migrator.migrate
  end
end

#urlObject



66
67
68
# File 'lib/groonga_client_model/test/groonga_server_runner.rb', line 66

def url
  URI.parse(@client.url)
end