Exemplo n.º 1
0
// With md5 manifest only, sha256 only, and both
func TestVirtualBagRead_ManifestOptions(t *testing.T) {
	tempDir, bagPath, err := testhelper.UntarTestBag("example.edu.tagsample_good.tar")
	if err != nil {
		assert.Fail(t, err.Error())
	}
	if tempDir != "" {
		defer os.RemoveAll(tempDir)
	}

	// Delete the md5 manifest
	os.Remove(filepath.Join(bagPath, "manifest-md5.txt"))

	files := []string{"bagit.txt", "bag-info.txt", "aptrust-info.txt"}
	vbag := models.NewVirtualBag(bagPath, files, true, true)
	assert.NotNil(t, vbag)
	obj, _ := vbag.Read()

	// Should have manifest values for sha256
	for _, gf := range obj.GenericFiles {
		if gf.IngestFileType == constants.PAYLOAD_FILE {
			assert.Empty(t, gf.IngestManifestMd5)
			assert.NotEmpty(t, gf.IngestManifestSha256)
		}
	}

	tempDir, bagPath, err = testhelper.UntarTestBag("example.edu.tagsample_good.tar")
	if err != nil {
		assert.Fail(t, err.Error())
	}
	if tempDir != "" {
		defer os.RemoveAll(tempDir)
	}

	// Delete the sha256 manifest
	os.Remove(filepath.Join(bagPath, "manifest-sha256.txt"))

	files = []string{"bagit.txt", "bag-info.txt", "aptrust-info.txt"}
	vbag = models.NewVirtualBag(bagPath, files, true, true)
	assert.NotNil(t, vbag)
	obj, _ = vbag.Read()

	// Should have manifest values for sha256
	for _, gf := range obj.GenericFiles {
		if gf.IngestFileType == constants.PAYLOAD_FILE {
			assert.NotEmpty(t, gf.IngestManifestMd5)
			assert.Empty(t, gf.IngestManifestSha256)
		}
	}
}
Exemplo n.º 2
0
func TestVirtualBagRead_ChecksumOptions(t *testing.T) {
	tempDir, bagPath, err := testhelper.UntarTestBag("example.edu.tagsample_good.tar")
	if err != nil {
		assert.Fail(t, err.Error())
	}
	if tempDir != "" {
		defer os.RemoveAll(tempDir)
	}
	files := []string{"bagit.txt", "bag-info.txt", "aptrust-info.txt"}
	vbag := models.NewVirtualBag(bagPath, files, true, false)
	assert.NotNil(t, vbag)
	obj, _ := vbag.Read()

	// Should calculate md5 only
	for _, gf := range obj.GenericFiles {
		assert.NotEmpty(t, gf.IngestMd5)
		assert.Empty(t, gf.IngestSha256)
	}

	vbag = models.NewVirtualBag(bagPath, files, false, true)
	assert.NotNil(t, vbag)
	obj, _ = vbag.Read()

	// Should calculate sha256 only
	for _, gf := range obj.GenericFiles {
		assert.Empty(t, gf.IngestMd5)
		assert.NotEmpty(t, gf.IngestSha256)
	}

}
Exemplo n.º 3
0
func TestVirtualBagRead_FromDirectory(t *testing.T) {
	tempDir, bagPath, err := testhelper.UntarTestBag("example.edu.tagsample_good.tar")
	if err != nil {
		assert.Fail(t, err.Error())
	}
	if tempDir != "" {
		defer os.RemoveAll(tempDir)
	}
	files := []string{"bagit.txt", "bag-info.txt", "aptrust-info.txt"}
	vbag := models.NewVirtualBag(bagPath, files, true, true)
	assert.NotNil(t, vbag)
	obj, summary := vbag.Read()
	runAssertions(t, obj, summary, "TestVirtualBagRead_FromDirectory")
}
Exemplo n.º 4
0
// Read an invalid bag from a directory
func TestValidate_FromDirectory_BagInvalid(t *testing.T) {
	tempDir, bagPath, err := testhelper.UntarTestBag("example.edu.tagsample_bad.tar")
	if err != nil {
		assert.Fail(t, err.Error())
	}
	if tempDir != "" {
		defer os.RemoveAll(tempDir)
	}
	bagValidationConfig, err := getValidationConfig()
	if err != nil {
		assert.Fail(t, "Could not load BagValidationConfig: %s", err.Error())
	}
	validator, err := validation.NewBagValidator(bagPath, bagValidationConfig)
	if err != nil {
		assert.Fail(t, "NewBagValidator returned unexpected error: %s", err.Error())
	}
	result := validator.Validate()
	assert.NotNil(t, result.IntellectualObject)
	assert.NotEmpty(t, result.IntellectualObject.IngestErrorMessage)
	assert.True(t, result.ParseSummary.HasErrors())
}