<commit_before>/*
 * This file is part of the KubeVirt project
 *
 * 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.
 *
 * Copyright 2017 Red Hat, Inc.
 *
 */

package cloudinit

import (
	"encoding/base64"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"
	"time"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	k8sv1 "k8s.io/api/core/v1"

	v1 "kubevirt.io/client-go/api/v1"
)

var _ = Describe("CloudInit", func() {

	var (
		isoCreationFunc IsoCreationFunc
		tmpDir          string
	)

	createEmptyVMIWithVolumes := func(volumes []v1.Volume) *v1.VirtualMachineInstance {
		return &v1.VirtualMachineInstance{
			Spec: v1.VirtualMachineInstanceSpec{
				Volumes: volumes,
			},
		}
	}

	fakeVolumeMountDir := func(dirName string, files map[string]string) string {
		volumeDir := filepath.Join(tmpDir, dirName)
		err := os.Mkdir(volumeDir, 0700)
		Expect(err).To(Not(HaveOccurred()), "could not create volume dir: ", volumeDir)
		for fileName, content := range files {
			err = ioutil.WriteFile(
				filepath.Join(volumeDir, fileName),
				[]byte(content),
				0644)
			Expect(err).To(Not(HaveOccurred()), "could not create file: ", fileName)
		}
		return volumeDir
	}

	BeforeEach(func() {
		tmpDir, _ = ioutil.TempDir("", "cloudinittest")
		err := SetLocalDirectory(tmpDir)
		if err != nil {
			panic(err)
		}
		isoCreationFunc = func(isoOutFile, volumeID string, inDir string) error {
			switch volumeID {<commit_msg>cloud-init_test: add err check for ioutil.TempDir<commit_after>/*
 * This file is part of the KubeVirt project
 *
 * 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.
 *
 * Copyright 2017 Red Hat, Inc.
 *
 */

package cloudinit

import (
	"encoding/base64"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"
	"time"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	k8sv1 "k8s.io/api/core/v1"

	v1 "kubevirt.io/client-go/api/v1"
)

var _ = Describe("CloudInit", func() {

	var (
		isoCreationFunc IsoCreationFunc
		tmpDir          string
	)

	createEmptyVMIWithVolumes := func(volumes []v1.Volume) *v1.VirtualMachineInstance {
		return &v1.VirtualMachineInstance{
			Spec: v1.VirtualMachineInstanceSpec{
				Volumes: volumes,
			},
		}
	}

	fakeVolumeMountDir := func(dirName string, files map[string]string) string {
		volumeDir := filepath.Join(tmpDir, dirName)
		err := os.Mkdir(volumeDir, 0700)
		Expect(err).To(Not(HaveOccurred()), "could not create volume dir: ", volumeDir)
		for fileName, content := range files {
			err = ioutil.WriteFile(
				filepath.Join(volumeDir, fileName),
				[]byte(content),
				0644)
			Expect(err).To(Not(HaveOccurred()), "could not create file: ", fileName)
		}
		return volumeDir
	}

	BeforeEach(func() {
		var err error
		tmpDir, err = ioutil.TempDir("", "cloudinittest")
		Expect(err).ToNot(HaveOccurred())
		err = SetLocalDirectory(tmpDir)
		if err != nil {
			panic(err)
		}
		isoCreationFunc = func(isoOutFile, volumeID string, inDir string) error {
			switch volumeID {
{'fraction_non_alphanumeric': 0.11622094476380905, 'fraction_numerical': 0.013996500874781305, 'mean_word_length': 3.827503015681544, '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': '4871555', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1333, 'n_words': 378}