// We should parse the tags in the specified files. // We should not parse other tag files func TestVirtualBagTagFileOptions(t *testing.T) { tarFilePath := testhelper.VbagGetPath("example.edu.tagsample_good.tar") files := []string{} vbag := models.NewVirtualBag(tarFilePath, files, true, true) assert.NotNil(t, vbag) obj, _ := vbag.Read() assert.Equal(t, 0, len(obj.IngestTags)) files = []string{"bagit.txt"} vbag = models.NewVirtualBag(tarFilePath, files, true, true) assert.NotNil(t, vbag) obj, _ = vbag.Read() assert.Equal(t, 2, len(obj.IngestTags)) files = []string{"bagit.txt", "bag-info.txt"} vbag = models.NewVirtualBag(tarFilePath, files, true, true) assert.NotNil(t, vbag) obj, _ = vbag.Read() assert.Equal(t, 8, len(obj.IngestTags)) files = []string{"bagit.txt", "bag-info.txt", "aptrust-info.txt"} vbag = models.NewVirtualBag(tarFilePath, files, true, true) assert.NotNil(t, vbag) obj, _ = vbag.Read() assert.Equal(t, 10, len(obj.IngestTags)) }
func TestVirtualBagRead_FromTarFile(t *testing.T) { tarFilePath := testhelper.VbagGetPath("example.edu.tagsample_good.tar") files := []string{"bagit.txt", "bag-info.txt", "aptrust-info.txt"} vbag := models.NewVirtualBag(tarFilePath, files, true, true) assert.NotNil(t, vbag) obj, summary := vbag.Read() runAssertions(t, obj, summary, "TestVirtualBagRead_FromTarFile") }
func TestVirtualBagReadReportsMissingFiles(t *testing.T) { // This bad bag has a number of problems. // Here, we're specifically testing to see if a missing file is reported. tarFilePath := testhelper.VbagGetPath("example.edu.tagsample_bad.tar") files := []string{"bagit.txt", "bag-info.txt", "aptrust-info.txt"} vbag := models.NewVirtualBag(tarFilePath, files, true, true) assert.NotNil(t, vbag) obj, summary := vbag.Read() // custom_tags/tag_file_xyz.pdf appears twice in missing files // list because it's mentioned in manifest-md5 and manifest-sha256 assert.True(t, summary.HasErrors()) require.Equal(t, 3, len(obj.IngestMissingFiles)) assert.Equal(t, "data/file-not-in-bag", obj.IngestMissingFiles[0].FilePath) assert.Equal(t, "custom_tags/tag_file_xyz.pdf", obj.IngestMissingFiles[1].FilePath) assert.Equal(t, "custom_tags/tag_file_xyz.pdf", obj.IngestMissingFiles[2].FilePath) }
func TestNewVirtualBag(t *testing.T) { tarFilePath := testhelper.VbagGetPath("example.edu.tagsample_good.tar") vbag := models.NewVirtualBag(tarFilePath, nil, false, false) assert.NotNil(t, vbag) }