Merge pull request #115 from sstarcher/chart_detection
support relative path for is local check
This commit is contained in:
		
						commit
						9b0d0d4cba
					
				| 
						 | 
					@ -398,15 +398,16 @@ func (state *HelmState) UpdateDeps(helm helmexec.Interface) []error {
 | 
				
			||||||
// 	 be constructed relative to the `base path`.
 | 
					// 	 be constructed relative to the `base path`.
 | 
				
			||||||
// - Everything else is assumed to be an absolute path or an actual <repository>/<chart> reference.
 | 
					// - Everything else is assumed to be an absolute path or an actual <repository>/<chart> reference.
 | 
				
			||||||
func normalizeChart(basePath, chart string) string {
 | 
					func normalizeChart(basePath, chart string) string {
 | 
				
			||||||
	if !isLocalChart(chart) {
 | 
						regex, _ := regexp.Compile("^[.]?./")
 | 
				
			||||||
 | 
						if !regex.MatchString(chart) {
 | 
				
			||||||
		return chart
 | 
							return chart
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return filepath.Join(basePath, chart)
 | 
						return filepath.Join(basePath, chart)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func isLocalChart(chart string) bool {
 | 
					func isLocalChart(chart string) bool {
 | 
				
			||||||
	regex, _ := regexp.Compile("^[.]?./")
 | 
						_, err := os.Stat(chart)
 | 
				
			||||||
	return regex.MatchString(chart)
 | 
						return err == nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func flagsForRelease(helm helmexec.Interface, basePath string, release *ReleaseSpec) ([]string, error) {
 | 
					func flagsForRelease(helm helmexec.Interface, basePath string, release *ReleaseSpec) ([]string, error) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -371,7 +371,7 @@ func Test_isLocalChart(t *testing.T) {
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "local chart",
 | 
								name: "local chart",
 | 
				
			||||||
			args: args{
 | 
								args: args{
 | 
				
			||||||
				chart: "./charts/nonstop",
 | 
									chart: "./",
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			want: true,
 | 
								want: true,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
| 
						 | 
					@ -392,14 +392,14 @@ func Test_isLocalChart(t *testing.T) {
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "parent local path",
 | 
								name: "parent local path",
 | 
				
			||||||
			args: args{
 | 
								args: args{
 | 
				
			||||||
				chart: "../../dotty",
 | 
									chart: "../examples",
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			want: true,
 | 
								want: true,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "parent-parent local path",
 | 
								name: "parent-parent local path",
 | 
				
			||||||
			args: args{
 | 
								args: args{
 | 
				
			||||||
				chart: "../../dotty",
 | 
									chart: "../../",
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			want: true,
 | 
								want: true,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
| 
						 | 
					@ -561,13 +561,13 @@ func TestHelmState_UpdateDeps(t *testing.T) {
 | 
				
			||||||
		BaseChartPath: "/src",
 | 
							BaseChartPath: "/src",
 | 
				
			||||||
		Releases: []ReleaseSpec{
 | 
							Releases: []ReleaseSpec{
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				Chart: "./local",
 | 
									Chart: "./..",
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				Chart: "../local",
 | 
									Chart: "../examples",
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				Chart: "../../local",
 | 
									Chart: "../../helmfile",
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				Chart: "published",
 | 
									Chart: "published",
 | 
				
			||||||
| 
						 | 
					@ -580,13 +580,14 @@ func TestHelmState_UpdateDeps(t *testing.T) {
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	want := []string{"/src/local", "/local", "/local"}
 | 
					
 | 
				
			||||||
 | 
						want := []string{"/", "/examples", "/helmfile"}
 | 
				
			||||||
	helm := &mockHelmExec{}
 | 
						helm := &mockHelmExec{}
 | 
				
			||||||
	errs := state.UpdateDeps(helm)
 | 
						errs := state.UpdateDeps(helm)
 | 
				
			||||||
	if !reflect.DeepEqual(helm.charts, want) {
 | 
						if !reflect.DeepEqual(helm.charts, want) {
 | 
				
			||||||
		t.Errorf("HelmState.UpdateDeps() = %v, want %v", helm.charts, want)
 | 
							t.Errorf("HelmState.UpdateDeps() = %v, want %v", helm.charts, want)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if len(errs) != 1 {
 | 
						if len(errs) != 0 {
 | 
				
			||||||
		t.Errorf("HelmState.UpdateDeps() - expected an error, but got: %v", len(errs))
 | 
							t.Errorf("HelmState.UpdateDeps() - no errors, but got: %v", len(errs))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue