-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathRakefile
82 lines (71 loc) · 2.5 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Copyright 2020 Google LLC
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
require "bundler/gem_tasks"
require "rake/testtask"
require "securerandom"
desc "Run tests."
Rake::TestTask.new do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
t.warning = false
end
task :default => :test
require "yard"
require "yard/rake/yardoc_task"
YARD::Rake::YardocTask.new do |y|
# y.options << "--fail-on-warning"
end
desc "Run the spanner connector acceptance tests."
task :acceptance, [:project, :keyfile, :instance, :tests] do |t, args|
project = args[:project]
project ||= ENV["SPANNER_TEST_PROJECT"] || ENV["GCLOUD_TEST_PROJECT"]
emulator_host = args[:emulator_host]
emulator_host ||= ENV["SPANNER_EMULATOR_HOST"]
keyfile = args[:keyfile]
keyfile ||= ENV["SPANNER_TEST_KEYFILE"] || ENV["GCLOUD_TEST_KEYFILE"] || ENV["GOOGLE_APPLICATION_CREDENTIALS"]
if keyfile
keyfile = File.read keyfile
else
keyfile ||= ENV["SPANNER_TEST_KEYFILE_JSON"] || ENV["GCLOUD_TEST_KEYFILE_JSON"]
end
if project.nil? || (keyfile.nil? && emulator_host.nil?)
fail "You must provide a project and keyfile or emulator host name."
end
instance = args[:instance]
instance ||= ENV["SPANNER_TEST_INSTANCE"]
if instance.nil?
fail "You must provide an instance name"
end
# clear any env var already set
require "google/cloud/spanner/credentials"
Google::Cloud::Spanner::Credentials.env_vars.each do |path|
ENV[path] = nil
end
tests = args[:tests]
tests ||= "**"
# always overwrite when running tests
ENV["SPANNER_TEST_PROJECT"] = project
ENV["SPANNER_TEST_KEYFILE_JSON"] = keyfile
ENV["SPANNER_TEST_INSTANCE"] = instance
ENV["SPANNER_EMULATOR_HOST"] = emulator_host
Rake::TestTask.new :run do |t|
t.libs << "acceptance"
t.libs << "lib"
t.test_files = FileList["acceptance/#{tests}/*_test.rb"] unless tests.start_with? "exclude "
t.test_files = FileList.new("acceptance/**/*_test.rb") do |fl|
fl.exclude "acceptance/#{tests.split(" ")[1]}/*_test.rb"
puts "excluding acceptance/#{tests.split(" ")[1]}/*_test.rb"
end if tests.start_with? "exclude"
t.warning = false
end
Rake::Task["run"].invoke
end
desc +"Runs the `examples/snippets/quickstart` example on a Spanner emulator. See the directory `examples/snippets`"
"for more examples."
task :example do
Dir.chdir("examples/snippets/quickstart") { sh "bundle exec rake run" }
end