| 
									
										
										
										
											2016-05-12 06:21:14 +08:00
										 |  |  | package lint | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2016-06-10 07:51:00 +08:00
										 |  |  | 	"k8s.io/helm/pkg/lint/support" | 
					
						
							| 
									
										
										
										
											2016-05-12 06:21:14 +08:00
										 |  |  | 	"strings" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-10 07:51:00 +08:00
										 |  |  | const badChartDir = "rules/testdata/badchartfile" | 
					
						
							|  |  |  | const badValuesFileDir = "rules/testdata/badvaluesfile" | 
					
						
							|  |  |  | const badYamlFileDir = "rules/testdata/albatross" | 
					
						
							|  |  |  | const goodChartDir = "rules/testdata/goodone" | 
					
						
							| 
									
										
										
										
											2016-05-12 06:21:14 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | func TestBadChart(t *testing.T) { | 
					
						
							|  |  |  | 	m := All(badChartDir) | 
					
						
							| 
									
										
										
										
											2016-06-10 07:51:00 +08:00
										 |  |  | 	if len(m) != 4 { | 
					
						
							|  |  |  | 		t.Errorf("Number of errors %v", len(m)) | 
					
						
							| 
									
										
										
										
											2016-05-12 06:21:14 +08:00
										 |  |  | 		t.Errorf("All didn't fail with expected errors, got %#v", m) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-12 06:58:41 +08:00
										 |  |  | 	// There should be 2 WARNINGs and one ERROR messages, check for them
 | 
					
						
							| 
									
										
										
										
											2016-06-10 07:51:00 +08:00
										 |  |  | 	var w, e, e2, e3 bool | 
					
						
							| 
									
										
										
										
											2016-05-12 06:21:14 +08:00
										 |  |  | 	for _, msg := range m { | 
					
						
							| 
									
										
										
										
											2016-06-10 07:51:00 +08:00
										 |  |  | 		if msg.Severity == support.WarningSev { | 
					
						
							|  |  |  | 			if strings.Contains(msg.Text, "Templates directory not found") { | 
					
						
							| 
									
										
										
										
											2016-05-12 06:21:14 +08:00
										 |  |  | 				w = true | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-06-10 07:51:00 +08:00
										 |  |  | 		if msg.Severity == support.ErrorSev { | 
					
						
							|  |  |  | 			if strings.Contains(msg.Text, "'version' 0.0.0 is less than or equal to 0") { | 
					
						
							| 
									
										
										
										
											2016-05-12 06:21:14 +08:00
										 |  |  | 				e = true | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-05-12 06:58:41 +08:00
										 |  |  | 			if strings.Contains(msg.Text, "'name' is required") { | 
					
						
							|  |  |  | 				e2 = true | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-06-10 07:51:00 +08:00
										 |  |  | 			if strings.Contains(msg.Text, "'name' and directory do not match") { | 
					
						
							|  |  |  | 				e3 = true | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-05-12 06:21:14 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-06-10 07:51:00 +08:00
										 |  |  | 	if !e || !e2 || !e3 || !w { | 
					
						
							| 
									
										
										
										
											2016-05-12 06:21:14 +08:00
										 |  |  | 		t.Errorf("Didn't find all the expected errors, got %#v", m) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestInvalidYaml(t *testing.T) { | 
					
						
							|  |  |  | 	m := All(badYamlFileDir) | 
					
						
							|  |  |  | 	if len(m) != 1 { | 
					
						
							| 
									
										
										
										
											2016-05-12 07:20:09 +08:00
										 |  |  | 		t.Errorf("All didn't fail with expected errors, got %#v", m) | 
					
						
							| 
									
										
										
										
											2016-05-12 06:21:14 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if !strings.Contains(m[0].Text, "deliberateSyntaxError") { | 
					
						
							|  |  |  | 		t.Errorf("All didn't have the error for deliberateSyntaxError") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-12 07:20:09 +08:00
										 |  |  | func TestBadValues(t *testing.T) { | 
					
						
							|  |  |  | 	m := All(badValuesFileDir) | 
					
						
							|  |  |  | 	if len(m) != 1 { | 
					
						
							|  |  |  | 		t.Errorf("All didn't fail with expected errors, got %#v", m) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-06-07 09:34:30 +08:00
										 |  |  | 	if !strings.Contains(m[0].Text, "cannot unmarshal") { | 
					
						
							|  |  |  | 		t.Errorf("All didn't have the error for invalid key format: %s", m[0].Text) | 
					
						
							| 
									
										
										
										
											2016-05-12 07:20:09 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-12 06:21:14 +08:00
										 |  |  | func TestGoodChart(t *testing.T) { | 
					
						
							|  |  |  | 	m := All(goodChartDir) | 
					
						
							|  |  |  | 	if len(m) != 0 { | 
					
						
							|  |  |  | 		t.Errorf("All failed but shouldn't have: %#v", m) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |