| 
									
										
										
										
											2016-05-10 02:40:10 +08:00
										 |  |  | package repo | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-11 05:15:06 +08:00
										 |  |  | const testfile = "testdata/local-index.yaml" | 
					
						
							| 
									
										
										
										
											2016-05-10 02:40:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-11 05:15:06 +08:00
										 |  |  | func TestLoadIndexFile(t *testing.T) { | 
					
						
							|  |  |  | 	cf, err := LoadIndexFile(testfile) | 
					
						
							| 
									
										
										
										
											2016-05-10 02:40:10 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2016-05-11 05:15:06 +08:00
										 |  |  | 		t.Errorf("Failed to load index file: %s", err) | 
					
						
							| 
									
										
										
										
											2016-05-10 02:40:10 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if len(cf.Entries) != 2 { | 
					
						
							| 
									
										
										
										
											2016-05-11 05:15:06 +08:00
										 |  |  | 		t.Errorf("Expected 2 entries in the index file, but got %d", len(cf.Entries)) | 
					
						
							| 
									
										
										
										
											2016-05-10 02:40:10 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	nginx := false | 
					
						
							|  |  |  | 	alpine := false | 
					
						
							|  |  |  | 	for k, e := range cf.Entries { | 
					
						
							|  |  |  | 		if k == "nginx-0.1.0" { | 
					
						
							|  |  |  | 			if e.Name == "nginx" { | 
					
						
							|  |  |  | 				if len(e.Keywords) == 3 { | 
					
						
							|  |  |  | 					nginx = true | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if k == "alpine-1.0.0" { | 
					
						
							|  |  |  | 			if e.Name == "alpine" { | 
					
						
							|  |  |  | 				if len(e.Keywords) == 4 { | 
					
						
							|  |  |  | 					alpine = true | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if !nginx { | 
					
						
							|  |  |  | 		t.Errorf("nginx entry was not decoded properly") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if !alpine { | 
					
						
							|  |  |  | 		t.Errorf("alpine entry was not decoded properly") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |