<commit_before># Copyright 2018 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
#
#      http://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.

project_id = attribute('project_id', required: true, type: :string)
zone = attribute('zone', required: true, type: :string)
instance_name = attribute('instance_name', required: true, type: :string)
network = attribute('network', type: :string, default: "default")
subnetwork = attribute('subnetwork', type: :string, default: "default")
image = attribute('image', required: true, type: :string)
machine_type = attribute('machine_type', type: :string, default: "n1-standard-1")

control "gce" do
  title "Google Compute Engine instance configuration"

  describe command("gcloud --project=#{project_id} compute instances describe #{instance_name} --format json") do
    its('exit_status') { should be 0 }
    its('stderr') { should eq '' }

    # let!(:metadata) do
    #   raise subject.stdout.inspect
    #   if subject.exit_status == 0
    #     JSON.parse(subject.stdout)
    #   else
    #     {}
    #   end
    # end

    # it "is in a running state" do
    #   expect(metadata['status']).to eq 'RUNNING'
    # end

    # it "is in the correct network" do
    #   expect(metadata['networkInterfaces'][0]['network']).to eq network
    # end<commit_msg>Specify --zone when looking up compute instance<commit_after># Copyright 2018 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
#
#      http://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.

project_id = attribute('project_id', required: true, type: :string)
zone = attribute('zone', required: true, type: :string)
instance_name = attribute('instance_name', required: true, type: :string)
network = attribute('network', type: :string, default: "default")
subnetwork = attribute('subnetwork', type: :string, default: "default")
image = attribute('image', required: true, type: :string)
machine_type = attribute('machine_type', type: :string, default: "n1-standard-1")

control "gce" do
  title "Google Compute Engine instance configuration"

  describe command("gcloud --project=#{project_id} compute instances describe #{instance_name} --zone=#{zone} --format json") do
    its('exit_status') { should be 0 }
    its('stderr') { should eq '' }

    # let!(:metadata) do
    #   raise subject.stdout.inspect
    #   if subject.exit_status == 0
    #     JSON.parse(subject.stdout)
    #   else
    #     {}
    #   end
    # end

    # it "is in a running state" do
    #   expect(metadata['status']).to eq 'RUNNING'
    # end

    # it "is in the correct network" do
    #   expect(metadata['networkInterfaces'][0]['network']).to eq network
    # end
{'fraction_non_alphanumeric': 0.11854360711261643, 'fraction_numerical': 0.00733841377363816, 'mean_word_length': 4.019830028328612, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3617817', 'n_tokens_mistral': 1001, 'n_tokens_neox': 980, 'n_words': 374}