<commit_before>package common

import (
	"context"
	"io/ioutil"
	"os"
	"testing"

	"github.com/hashicorp/packer/helper/multistep"
)

func TestStepCompactDisk_impl(t *testing.T) {
	var _ multistep.Step = new(StepCompactDisk)
}

func TestStepCompactDisk(t *testing.T) {
	state := testState(t)
	step := new(StepCompactDisk)

	// Create a fake vmdk file for disk file size operations
	diskFile, err := ioutil.TempFile("", "disk.vmdk")
	if err != nil {
		t.Fatalf("Error creating fake vmdk file: %s", err)
	}

	diskFullPath := diskFile.Name()
	defer os.Remove(diskFullPath)

	content := []byte("I am the fake vmdk's contents")
	if _, err := diskFile.Write(content); err != nil {
		t.Fatalf("Error writing to fake vmdk file: %s", err)
	}
	if err := diskFile.Close(); err != nil {
		t.Fatalf("Error closing fake vmdk file: %s", err)
	}

	// Set up required state
	state.Put("disk_full_paths", []string{diskFullPath})

	driver := state.Get("driver").(*DriverMock)

	// Test the run
	if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
		t.Fatalf("bad action: %#v", action)
	}
	if _, ok := state.GetOk("error"); ok {
		t.Fatal("should NOT have error")
	}

	// Test the driver
	if !driver.CompactDiskCalled {
		t.Fatal("should've called")
	}
	if driver.CompactDiskPath != diskFullPath {
		t.Fatal("should call with right path")
	}
}

func TestStepCompactDisk_skip(t *testing.T) {
	state := testState(t)
	step := new(StepCompactDisk)
	step.Skip = true

	diskFullPaths := []string{"foo"}
	state.Put("disk_full_paths", diskFullPaths)

	driver := state.Get("driver").(*DriverMock)

	// Test the run
	if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
		t.Fatalf("bad action: %#v", action)
	}
	if _, ok := state.GetOk("error"); ok {
		t.Fatal("should NOT have error")
	}

	// Test the driver
	if driver.CompactDiskCalled {
		t.Fatal("should not have called")
	}
}
<commit_msg>Revert "Fix test - reporting compaction results requires a tmp file"<commit_after>package common

import (
	"context"
	"testing"

	"github.com/hashicorp/packer/helper/multistep"
)

func TestStepCompactDisk_impl(t *testing.T) {
	var _ multistep.Step = new(StepCompactDisk)
}

func TestStepCompactDisk(t *testing.T) {
	state := testState(t)
	step := new(StepCompactDisk)

	diskFullPaths := []string{"foo"}
	state.Put("disk_full_paths", diskFullPaths)

	driver := state.Get("driver").(*DriverMock)

	// Test the run
	if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
		t.Fatalf("bad action: %#v", action)
	}
	if _, ok := state.GetOk("error"); ok {
		t.Fatal("should NOT have error")
	}

	// Test the driver
	if !driver.CompactDiskCalled {
		t.Fatal("should've called")
	}
	if driver.CompactDiskPath != "foo" {
		t.Fatal("should call with right path")
	}
}

func TestStepCompactDisk_skip(t *testing.T) {
	state := testState(t)
	step := new(StepCompactDisk)
	step.Skip = true

	diskFullPaths := []string{"foo"}
	state.Put("disk_full_paths", diskFullPaths)

	driver := state.Get("driver").(*DriverMock)

	// Test the run
	if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
		t.Fatalf("bad action: %#v", action)
	}
	if _, ok := state.GetOk("error"); ok {
		t.Fatal("should NOT have error")
	}

	// Test the driver
	if driver.CompactDiskCalled {
		t.Fatal("should not have called")
	}
}

{'fraction_non_alphanumeric': 0.15683962264150944, 'fraction_numerical': 0.0, 'mean_word_length': 4.334905660377358, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4731918', 'n_tokens_mistral': 1253, 'n_tokens_neox': 1208, 'n_words': 285}