Example #1
0
func TestDownloadManifest(t *testing.T) {
	plugin := createStubPluginInput()
	context := createStubInstanceContext()

	manager := updateManager{}
	util := fakeUtility{}
	out := UpdatePluginOutput{}

	fileDownload = func(log log.T, input artifact.DownloadInput) (output artifact.DownloadOutput, err error) {
		result := artifact.DownloadOutput{}
		result.IsHashMatched = true
		result.LocalFilePath = "testdata/sampleManifest.json"
		return result, nil
	}

	manifest, err := manager.downloadManifest(logger, &util, plugin, context, &out)

	assert.NoError(t, err)
	assert.NotNil(t, manifest)
}
Example #2
0
func TestDownloadUpdater_HashDoesNotMatch(t *testing.T) {
	plugin := createStubPluginInput()
	context := createStubInstanceContext()
	manifest := createStubManifest(plugin, context, true, true)

	manager := updateManager{}
	util := fakeUtility{}
	out := UpdatePluginOutput{}

	// file download failed
	fileDownload = func(log log.T, input artifact.DownloadInput) (output artifact.DownloadOutput, err error) {
		result := artifact.DownloadOutput{}
		result.IsHashMatched = false
		result.LocalFilePath = ""
		return result, fmt.Errorf("404")
	}

	_, err := manager.downloadUpdater(logger, &util, plugin.AgentName, manifest, &out, context)

	assert.Error(t, err)
	assert.Contains(t, err.Error(), "failed to download file reliably")
	assert.Contains(t, err.Error(), "404")
}
Example #3
0
func TestDownloadUpdater_FailedDuringUnCompress(t *testing.T) {
	plugin := createStubPluginInput()
	context := createStubInstanceContext()
	manifest := createStubManifest(plugin, context, true, true)

	manager := updateManager{}
	util := fakeUtility{}
	out := UpdatePluginOutput{}

	fileDownload = func(log log.T, input artifact.DownloadInput) (output artifact.DownloadOutput, err error) {
		result := artifact.DownloadOutput{}
		result.IsHashMatched = true
		result.LocalFilePath = "updater/location"
		return result, nil
	}

	fileUncompress = func(src, dest string) error {
		return fmt.Errorf("Failed with uncompress")
	}

	_, err := manager.downloadUpdater(logger, &util, plugin.AgentName, manifest, &out, context)

	assert.Error(t, err, "Failed with uncompress")
}