| 
									
										
										
										
											2016-05-12 06:21:14 +08:00
										 |  |  | package lint | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"strings" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-12 06:58:41 +08:00
										 |  |  | const badChartDir = "testdata/badchartfile" | 
					
						
							| 
									
										
										
										
											2016-05-12 07:20:09 +08:00
										 |  |  | const badValuesFileDir = "testdata/badvaluesfile" | 
					
						
							| 
									
										
										
										
											2016-05-12 06:21:14 +08:00
										 |  |  | const badYamlFileDir = "testdata/albatross" | 
					
						
							|  |  |  | const goodChartDir = "testdata/goodone" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestBadChart(t *testing.T) { | 
					
						
							|  |  |  | 	m := All(badChartDir) | 
					
						
							|  |  |  | 	if len(m) != 3 { | 
					
						
							|  |  |  | 		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
 | 
					
						
							|  |  |  | 	var w, e, e2 = false, false, false | 
					
						
							| 
									
										
										
										
											2016-05-12 06:21:14 +08:00
										 |  |  | 	for _, msg := range m { | 
					
						
							|  |  |  | 		if msg.Severity == WarningSev { | 
					
						
							|  |  |  | 			if strings.Contains(msg.Text, "No templates") { | 
					
						
							|  |  |  | 				w = true | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if msg.Severity == ErrorSev { | 
					
						
							| 
									
										
										
										
											2016-05-12 06:58:41 +08:00
										 |  |  | 			if strings.Contains(msg.Text, "must be greater than 0.0.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-05-12 06:21:14 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-12 06:58:41 +08:00
										 |  |  | 	if !e || !e2 || !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) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |