# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require "rake/testtask"

Rake::TestTask.new "test" do |t|
  t.test_files = FileList["acceptance/*_test.rb"]
  t.warning = false
end

namespace :fixtures do
  desc "Cleans out any fixture data that has been left behind by previous tests"
  task :clean do
    require "google/cloud/monitoring"
    project_id = ENV["GOOGLE_CLOUD_PROJECT"]
    raise "Set the environment variable GOOGLE_CLOUD_PROJECT." if project_id.nil?
    client = Google::Cloud::Monitoring.uptime_check_service
    project_name = client.project_path project: project_id
    configs = client.list_uptime_check_configs parent: project_name
    configs.each do |config|
      puts "Cleaning #{config.name}..."
      client.delete_uptime_check_config name: config.name
    end
  end
end
