| 
									
										
										
										
											2023-08-22 12:56:56 +08:00
										 |  |  | package server | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import "testing" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestParseModelPath(t *testing.T) { | 
					
						
							|  |  |  | 	tests := []struct { | 
					
						
							| 
									
										
										
										
											2023-09-29 01:00:34 +08:00
										 |  |  | 		name string | 
					
						
							|  |  |  | 		arg  string | 
					
						
							|  |  |  | 		want ModelPath | 
					
						
							| 
									
										
										
										
											2023-08-22 12:56:56 +08:00
										 |  |  | 	}{ | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			"full path https", | 
					
						
							| 
									
										
										
										
											2023-08-23 00:39:42 +08:00
										 |  |  | 			"https://example.com/ns/repo:tag", | 
					
						
							| 
									
										
										
										
											2023-08-22 12:56:56 +08:00
										 |  |  | 			ModelPath{ | 
					
						
							|  |  |  | 				ProtocolScheme: "https", | 
					
						
							|  |  |  | 				Registry:       "example.com", | 
					
						
							|  |  |  | 				Namespace:      "ns", | 
					
						
							|  |  |  | 				Repository:     "repo", | 
					
						
							|  |  |  | 				Tag:            "tag", | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2023-08-23 00:39:42 +08:00
										 |  |  | 			"full path http", | 
					
						
							|  |  |  | 			"http://example.com/ns/repo:tag", | 
					
						
							| 
									
										
										
										
											2023-08-22 12:56:56 +08:00
										 |  |  | 			ModelPath{ | 
					
						
							|  |  |  | 				ProtocolScheme: "http", | 
					
						
							|  |  |  | 				Registry:       "example.com", | 
					
						
							|  |  |  | 				Namespace:      "ns", | 
					
						
							|  |  |  | 				Repository:     "repo", | 
					
						
							|  |  |  | 				Tag:            "tag", | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			"no protocol", | 
					
						
							| 
									
										
										
										
											2023-08-23 00:39:42 +08:00
										 |  |  | 			"example.com/ns/repo:tag", | 
					
						
							| 
									
										
										
										
											2023-08-22 12:56:56 +08:00
										 |  |  | 			ModelPath{ | 
					
						
							|  |  |  | 				ProtocolScheme: "https", | 
					
						
							|  |  |  | 				Registry:       "example.com", | 
					
						
							|  |  |  | 				Namespace:      "ns", | 
					
						
							|  |  |  | 				Repository:     "repo", | 
					
						
							|  |  |  | 				Tag:            "tag", | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			"no registry", | 
					
						
							| 
									
										
										
										
											2023-08-23 00:39:42 +08:00
										 |  |  | 			"ns/repo:tag", | 
					
						
							| 
									
										
										
										
											2023-08-22 12:56:56 +08:00
										 |  |  | 			ModelPath{ | 
					
						
							|  |  |  | 				ProtocolScheme: "https", | 
					
						
							|  |  |  | 				Registry:       DefaultRegistry, | 
					
						
							|  |  |  | 				Namespace:      "ns", | 
					
						
							|  |  |  | 				Repository:     "repo", | 
					
						
							|  |  |  | 				Tag:            "tag", | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			"no namespace", | 
					
						
							| 
									
										
										
										
											2023-08-23 00:39:42 +08:00
										 |  |  | 			"repo:tag", | 
					
						
							| 
									
										
										
										
											2023-08-22 12:56:56 +08:00
										 |  |  | 			ModelPath{ | 
					
						
							|  |  |  | 				ProtocolScheme: "https", | 
					
						
							|  |  |  | 				Registry:       DefaultRegistry, | 
					
						
							|  |  |  | 				Namespace:      DefaultNamespace, | 
					
						
							|  |  |  | 				Repository:     "repo", | 
					
						
							|  |  |  | 				Tag:            "tag", | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			"no tag", | 
					
						
							| 
									
										
										
										
											2023-08-23 00:39:42 +08:00
										 |  |  | 			"repo", | 
					
						
							| 
									
										
										
										
											2023-08-22 12:56:56 +08:00
										 |  |  | 			ModelPath{ | 
					
						
							|  |  |  | 				ProtocolScheme: "https", | 
					
						
							|  |  |  | 				Registry:       DefaultRegistry, | 
					
						
							|  |  |  | 				Namespace:      DefaultNamespace, | 
					
						
							|  |  |  | 				Repository:     "repo", | 
					
						
							|  |  |  | 				Tag:            DefaultTag, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for _, tc := range tests { | 
					
						
							|  |  |  | 		t.Run(tc.name, func(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2023-08-23 00:39:42 +08:00
										 |  |  | 			got := ParseModelPath(tc.arg) | 
					
						
							| 
									
										
										
										
											2023-08-22 12:56:56 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if got != tc.want { | 
					
						
							|  |  |  | 				t.Errorf("got: %q want: %q", got, tc.want) | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |