コード例 #1
0
func TestUploadTarFile(t *testing.T) {
	Convey("Test Uploading a tar directory", t, func() {
		testData, err := testing_utils.NewTestDataContainer("testdata/copy-files", 6)
		So(err, ShouldBeNil)

		tempRemoteBasePath, err := ioutil.TempDir(os.TempDir(), "gopsexec-client-test-")
		So(err, ShouldBeNil)
		defer os.RemoveAll(tempRemoteBasePath)

		sessionFileSystem, err := testingGetNewSessionFileSystem()
		So(err, ShouldBeNil)

		testData.ForeachRelativeFile(func(relFile string) {
			localFullFilePath := filepath.Join(testData.FullDir, relFile)
			fullTempRemotePath := filepath.Join(tempRemoteBasePath, relFile)

			So(fullTempRemotePath, more_goconvey_assertions.AssertFileExistance, false)

			fileTarProvider := tar_io.Factories.TarProvider.File(localFullFilePath)
			err = sessionFileSystem.UploadTar(fileTarProvider, fullTempRemotePath, false)
			So(err, ShouldBeNil)

			So(fullTempRemotePath, more_goconvey_assertions.AssertFileExistance, true)
			So(testing_utils.CheckFilePropertiesEqual(localFullFilePath, fullTempRemotePath), ShouldBeNil)
		})

		err = os.RemoveAll(tempRemoteBasePath)
		So(err, ShouldBeNil)
		So(tempRemoteBasePath, more_goconvey_assertions.AssertDirectoryExistance, false)
		testData.ForeachRelativeFile(func(relFile string) {
			fullTempRemotePath := filepath.Join(tempRemoteBasePath, relFile)
			So(fullTempRemotePath, more_goconvey_assertions.AssertFileExistance, false)
		})
	})
}
コード例 #2
0
func TestDownloadTarDirectory(t *testing.T) {
	Convey("Test Downloading a tar directory", t, func() {
		testDataAsMockRemote, err := testing_utils.NewTestDataContainer("testdata/copy-files", 6)
		So(err, ShouldBeNil)

		tempLocalBasePath, err := ioutil.TempDir(os.TempDir(), "gopsexec-client-test-")
		So(err, ShouldBeNil)
		defer os.RemoveAll(tempLocalBasePath)

		//The dir already exists due to the TempDir method
		testDataAsMockRemote.ForeachRelativeFile(func(relFile string) {
			fullTempLocalPath := filepath.Join(tempLocalBasePath, relFile)
			So(fullTempLocalPath, more_goconvey_assertions.AssertFileExistance, false)
		})

		sessionFileSystem, err := testingGetNewSessionFileSystem()
		So(err, ShouldBeNil)

		tarReceiver := tar_io.Factories.TarReceiver.Dir(tempLocalBasePath)
		err = sessionFileSystem.DownloadTar(testDataAsMockRemote.FullDir, nil, tarReceiver)
		So(err, ShouldBeNil)

		So(tempLocalBasePath, more_goconvey_assertions.AssertDirectoryExistance, true)
		testDataAsMockRemote.ForeachRelativeFile(func(relFile string) {
			remoteFullFilePath := filepath.Join(testDataAsMockRemote.FullDir, relFile)
			fullTempLocalPath := filepath.Join(tempLocalBasePath, relFile)
			So(fullTempLocalPath, more_goconvey_assertions.AssertFileExistance, true)
			So(testing_utils.CheckFilePropertiesEqual(remoteFullFilePath, fullTempLocalPath), ShouldBeNil)
		})

		err = os.RemoveAll(tempLocalBasePath)
		So(err, ShouldBeNil)
		So(tempLocalBasePath, more_goconvey_assertions.AssertDirectoryExistance, false)
		testDataAsMockRemote.ForeachRelativeFile(func(relFile string) {
			fullTempLocalPath := filepath.Join(tempLocalBasePath, relFile)
			So(fullTempLocalPath, more_goconvey_assertions.AssertFileExistance, false)
		})
	})
}