<commit_before>#
# Author:: <NAME> (<<EMAIL>>)
# Copyright:: Copyright (c) 2012 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# 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.
#

require 'spec_helper'
require 'support/shared/unit/file_system_support'
require 'chef/chef_fs/file_pattern'
require 'chef/chef_fs/command_line'

describe 'diff' do
  include FileSystemSupport

  context 'with two filesystems with all types of difference' do
    let(:a) {
      memory_fs('a', {
        :both_dirs => {
          :sub_both_dirs => { :subsub => nil },
          :sub_both_files => nil,
          :sub_both_files_different => "a\n",
          :sub_both_dirs_empty => {},
          :sub_dirs_empty_in_a_filled_in_b => {},
          :sub_dirs_empty_in_b_filled_in_a => { :subsub => nil },
          :sub_a_only_dir => { :subsub => nil },
          :sub_a_only_file => nil,
          :sub_dir_in_a_file_in_b => {},
          :sub_file_in_a_dir_in_b => nil
        },
        :both_files => nil,
        :both_files_different => "a\n",
        :both_dirs_empty => {},
        :dirs_empty_in_a_filled_in_b => {},
        :dirs_empty_in_b_filled_in_a => { :subsub => nil },
        :dirs_in_a_cannot_be_in_b => {},
        :file_in_a_cannot_be_in_b => nil,
        :a_only_dir => { :subsub => nil },
        :a_only_file => nil,
        :dir_in_a_file_in_b => {},
        :file_in_a_dir_in_b => nil
      }, /cannot_be_in_a/)
    }
    let(:b) {
      memory_fs('b', {
        :both_dirs => {
          :sub_both_dirs => { :subsub => nil },
          :sub_both_files => nil,
          :sub_both_files_different => "b\n",
          :sub_both_dirs_empty => {},
          :sub_dirs_empty_in_a_filled_in_b => { :subsub => nil },
          :sub_dirs_empty_in_b_filled_in_a => {},
          :sub_b_only_dir => { :subsub => nil },
          :sub_b_only_file => nil,
          :sub_dir_in_a_file_in_b => nil,
          :sub_file_in_a_dir_in_b => {}
        },
        :both_files => nil,
        :both_files_different => "b\n",
        :both_dirs_empty => {},
        :dirs_empty_in_a_filled_in_b => { :subsub => nil },
        :dirs_empty_in_b_filled_in_a => {},
        :dirs_in_b_cannot_be_in_a => {},
        :file_in_b_cannot_be_in_a => nil,
        :b_only_dir => { :subsub => nil },
        :b_only_file => nil,
        :dir_in_a_file_in_b => nil,
        :file_in_a_dir_in_b => {}
      }, /cannot_be_in_b/)
    }
    it 'Chef::ChefFS::CommandLine.diff(/)' do
      results = []
      Chef::ChefFS::CommandLine.diff(pattern('/'), a, b, nil, nil) do |diff|
        results << diff.gsub(/\s+\d\d\d\d-\d\d-\d\d\s\d?\d:\d\d:\d\d\.\d{9} -\d\d\d\d/, ' DATE')
      end
      results.should =~ [
        'diff --knife a/both_dirs/sub_both_files_different b/both_dirs/sub_both_files_different
--- a/both_dirs/sub_both_files_different DATE
+++ b/both_dirs/sub_both_files_different DATE
@@ -1 +1 @@
-a
+b
','diff --knife a/both_dirs/sub_dirs_empty_in_a_filled_in_b/subsub b/both_dirs/sub_dirs_empty_in_a_filled_in_b/subsub
new file
--- /dev/null DATE
+++ b/both_dirs/sub_dirs_empty_in_a_filled_in_b/subsub DATE
@@ -0,0 +1 @@
+subsub
','diff --knife a/both_dirs/sub_dirs_empty_in_b_filled_in_a/subsub b/both_dirs/sub_dirs_empty_in_b_filled_in_a/subsub
deleted file
--- a/both_dirs/sub_dirs_empty_in_b_filled_in_a/subsub DATE
+++ /dev/null DATE
@@ -1 +0,0 @@
-subsub
','Only in a/both_dirs: sub_a_only_dir
','diff --knife a/both_dirs/sub_a_only_file b/both_dirs/sub_a_only_file
deleted file
--- a/both_dirs/sub_a_only_file DATE
+++ /dev/null DATE
@@ -1 +0,0 @@
-sub_a_only_file
','File b/both_dirs/sub_dir_in_a_file_in_b is a directory while file b/both_dirs/sub_dir_in_a_file_in_b is a regular file<commit_msg>Handle GMT and postive time zones in spec test<commit_after>#
# Author:: <NAME> (<<EMAIL>>)
# Copyright:: Copyright (c) 2012 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# 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.
#

require 'spec_helper'
require 'support/shared/unit/file_system_support'
require 'chef/chef_fs/file_pattern'
require 'chef/chef_fs/command_line'

describe 'diff' do
  include FileSystemSupport

  context 'with two filesystems with all types of difference' do
    let(:a) {
      memory_fs('a', {
        :both_dirs => {
          :sub_both_dirs => { :subsub => nil },
          :sub_both_files => nil,
          :sub_both_files_different => "a\n",
          :sub_both_dirs_empty => {},
          :sub_dirs_empty_in_a_filled_in_b => {},
          :sub_dirs_empty_in_b_filled_in_a => { :subsub => nil },
          :sub_a_only_dir => { :subsub => nil },
          :sub_a_only_file => nil,
          :sub_dir_in_a_file_in_b => {},
          :sub_file_in_a_dir_in_b => nil
        },
        :both_files => nil,
        :both_files_different => "a\n",
        :both_dirs_empty => {},
        :dirs_empty_in_a_filled_in_b => {},
        :dirs_empty_in_b_filled_in_a => { :subsub => nil },
        :dirs_in_a_cannot_be_in_b => {},
        :file_in_a_cannot_be_in_b => nil,
        :a_only_dir => { :subsub => nil },
        :a_only_file => nil,
        :dir_in_a_file_in_b => {},
        :file_in_a_dir_in_b => nil
      }, /cannot_be_in_a/)
    }
    let(:b) {
      memory_fs('b', {
        :both_dirs => {
          :sub_both_dirs => { :subsub => nil },
          :sub_both_files => nil,
          :sub_both_files_different => "b\n",
          :sub_both_dirs_empty => {},
          :sub_dirs_empty_in_a_filled_in_b => { :subsub => nil },
          :sub_dirs_empty_in_b_filled_in_a => {},
          :sub_b_only_dir => { :subsub => nil },
          :sub_b_only_file => nil,
          :sub_dir_in_a_file_in_b => nil,
          :sub_file_in_a_dir_in_b => {}
        },
        :both_files => nil,
        :both_files_different => "b\n",
        :both_dirs_empty => {},
        :dirs_empty_in_a_filled_in_b => { :subsub => nil },
        :dirs_empty_in_b_filled_in_a => {},
        :dirs_in_b_cannot_be_in_a => {},
        :file_in_b_cannot_be_in_a => nil,
        :b_only_dir => { :subsub => nil },
        :b_only_file => nil,
        :dir_in_a_file_in_b => nil,
        :file_in_a_dir_in_b => {}
      }, /cannot_be_in_b/)
    }
    it 'Chef::ChefFS::CommandLine.diff(/)' do
      results = []
      Chef::ChefFS::CommandLine.diff(pattern('/'), a, b, nil, nil) do |diff|
        # Removes the date stamp from the diff and replaces it with ' DATE'
        # example match: "/dev/null\t2012-10-16 16:15:54.000000000 +0000"
        results << diff.gsub(/\s+\d\d\d\d-\d\d-\d\d\s\d?\d:\d\d:\d\d\.\d{9} [+-]\d\d\d\d/, ' DATE')
      end
      results.should =~ [
        'diff --knife a/both_dirs/sub_both_files_different b/both_dirs/sub_both_files_different
--- a/both_dirs/sub_both_files_different DATE
+++ b/both_dirs/sub_both_files_different DATE
@@ -1 +1 @@
-a
+b
','diff --knife a/both_dirs/sub_dirs_empty_in_a_filled_in_b/subsub b/both_dirs/sub_dirs_empty_in_a_filled_in_b/subsub
new file
--- /dev/null DATE
+++ b/both_dirs/sub_dirs_empty_in_a_filled_in_b/subsub DATE
@@ -0,0 +1 @@
+subsub
','diff --knife a/both_dirs/sub_dirs_empty_in_b_filled_in_a/subsub b/both_dirs/sub_dirs_empty_in_b_filled_in_a/subsub
deleted file
--- a/both_dirs/sub_dirs_empty_in_b_filled_in_a/subsub DATE
+++ /dev/null DATE
@@ -1 +0,0 @@
-subsub
','Only in a/both_dirs: sub_a_only_dir
','diff --knife a/both_dirs/sub_a_only_file b/both_dirs/sub_a_only_file
deleted file
--- a/both_dirs/sub_a_only_file DATE
+++ /dev/null DATE
@@ -1 +0,0 @@
-sub_a_only_file
','File b/both_dirs/sub_dir_in_a_file_in_b is a directory while file b/both_dirs/sub_dir_in_a_file_in_b is a regular file
{'fraction_non_alphanumeric': 0.13763717020779828, 'fraction_numerical': 0.008288582769087088, 'mean_word_length': 2.942475839852738, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 117, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '5431545', 'n_tokens_mistral': 3396, 'n_tokens_neox': 3305, 'n_words': 600}