| 
									
										
										
										
											2016-07-31 12:09:44 +02:00
										 |  |  | package checker | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2017-06-04 11:16:55 +02:00
										 |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2016-07-31 12:09:44 +02:00
										 |  |  | 	"testing" | 
					
						
							| 
									
										
										
										
											2017-07-23 14:21:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-24 17:42:25 +02:00
										 |  |  | 	"github.com/restic/restic/internal/restic" | 
					
						
							| 
									
										
										
										
											2016-07-31 12:09:44 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // TestCheckRepo runs the checker on repo. | 
					
						
							| 
									
										
										
										
											2016-09-03 13:34:04 +02:00
										 |  |  | func TestCheckRepo(t testing.TB, repo restic.Repository) { | 
					
						
							| 
									
										
										
										
											2020-11-07 00:07:32 +01:00
										 |  |  | 	chkr := New(repo, true) | 
					
						
							| 
									
										
										
										
											2016-07-31 12:09:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-04 11:16:55 +02:00
										 |  |  | 	hints, errs := chkr.LoadIndex(context.TODO()) | 
					
						
							| 
									
										
										
										
											2016-07-31 12:09:44 +02:00
										 |  |  | 	if len(errs) != 0 { | 
					
						
							|  |  |  | 		t.Fatalf("errors loading index: %v", errs) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if len(hints) != 0 { | 
					
						
							|  |  |  | 		t.Fatalf("errors loading index: %v", hints) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-07 22:33:44 +01:00
										 |  |  | 	err := chkr.LoadSnapshots(context.TODO()) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Error(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-01 21:12:23 +02:00
										 |  |  | 	// packs | 
					
						
							| 
									
										
										
										
											2016-07-31 12:09:44 +02:00
										 |  |  | 	errChan := make(chan error) | 
					
						
							| 
									
										
										
										
											2017-06-04 11:16:55 +02:00
										 |  |  | 	go chkr.Packs(context.TODO(), errChan) | 
					
						
							| 
									
										
										
										
											2016-08-01 21:12:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for err := range errChan { | 
					
						
							|  |  |  | 		t.Error(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// structure | 
					
						
							|  |  |  | 	errChan = make(chan error) | 
					
						
							| 
									
										
										
										
											2020-12-06 00:07:45 +01:00
										 |  |  | 	go chkr.Structure(context.TODO(), nil, errChan) | 
					
						
							| 
									
										
										
										
											2016-07-31 12:09:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for err := range errChan { | 
					
						
							|  |  |  | 		t.Error(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-01 21:12:23 +02:00
										 |  |  | 	// unused blobs | 
					
						
							| 
									
										
										
										
											2020-11-06 23:41:04 +01:00
										 |  |  | 	blobs := chkr.UnusedBlobs(context.TODO()) | 
					
						
							| 
									
										
										
										
											2016-08-01 21:12:23 +02:00
										 |  |  | 	if len(blobs) > 0 { | 
					
						
							|  |  |  | 		t.Errorf("unused blobs found: %v", blobs) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// read data | 
					
						
							| 
									
										
										
										
											2016-07-31 12:09:44 +02:00
										 |  |  | 	errChan = make(chan error) | 
					
						
							| 
									
										
										
										
											2020-11-08 21:03:59 +01:00
										 |  |  | 	go chkr.ReadData(context.TODO(), errChan) | 
					
						
							| 
									
										
										
										
											2016-07-31 12:09:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for err := range errChan { | 
					
						
							|  |  |  | 		t.Error(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |