pull/13495/head
George Jenkins 10 months ago
parent e3ce2b188b
commit e81d56a247

@ -29,7 +29,10 @@ import (
)
func TestDependencyBuildCmd(t *testing.T) {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testcharts/*.tgz"))
srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testcharts/*.tgz"),
)
defer srv.Stop()
rootDir := srv.Root()

@ -32,7 +32,10 @@ import (
)
func TestDependencyUpdateCmd(t *testing.T) {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testcharts/*.tgz"))
srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testcharts/*.tgz"),
)
defer srv.Stop()
t.Logf("Listening on directory %s", srv.Root())
@ -148,7 +151,10 @@ func TestDependencyUpdateCmd_DoNotDeleteOldChartsOnError(t *testing.T) {
defer resetEnv()()
ensure.HelmHome(t)
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testcharts/*.tgz"))
srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testcharts/*.tgz"),
)
defer srv.Stop()
t.Logf("Listening on directory %s", srv.Root())
@ -242,7 +248,10 @@ func TestDependencyUpdateCmd_WithRepoThatWasNotAdded(t *testing.T) {
}
func setupMockRepoServer(t *testing.T) *repotest.Server {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testcharts/*.tgz"))
srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testcharts/*.tgz"),
)
t.Logf("Listening on directory %s", srv.Root())

@ -27,7 +27,11 @@ import (
)
func TestInstall(t *testing.T) {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testcharts/*.tgz*"), repotest.WithBasicAuth())
srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testcharts/*.tgz*"),
repotest.WithMiddleware(repotest.BasicAuthMiddleware(t)),
)
defer srv.Stop()
srv2 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

@ -28,7 +28,10 @@ import (
)
func TestPullCmd(t *testing.T) {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testcharts/*.tgz*"))
srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testcharts/*.tgz*"),
)
defer srv.Stop()
ociSrv, err := repotest.NewOCIServer(t, srv.Root())
@ -249,7 +252,11 @@ func TestPullCmd(t *testing.T) {
}
func TestPullWithCredentialsCmd(t *testing.T) {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testcharts/*.tgz*"), repotest.WithBasicAuth())
srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testcharts/*.tgz*"),
repotest.WithMiddleware(repotest.BasicAuthMiddleware(t)),
)
defer srv.Stop()
srv2 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

@ -34,11 +34,17 @@ import (
)
func TestRepoAddCmd(t *testing.T) {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*"))
srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer srv.Stop()
// A second test server is setup to verify URL changing
srv2 := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*"))
srv2 := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer srv2.Stop()
tmpdir := filepath.Join(t.TempDir(), "path-component.yaml/data")
@ -74,7 +80,10 @@ func TestRepoAddCmd(t *testing.T) {
}
func TestRepoAdd(t *testing.T) {
ts := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*"))
ts := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer ts.Stop()
rootDir := t.TempDir()
@ -125,7 +134,10 @@ func TestRepoAdd(t *testing.T) {
}
func TestRepoAddCheckLegalName(t *testing.T) {
ts := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*"))
ts := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer ts.Stop()
defer resetEnv()()
@ -179,7 +191,10 @@ func TestRepoAddConcurrentHiddenFile(t *testing.T) {
}
func repoAddConcurrent(t *testing.T, testName, repoFile string) {
ts := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*"))
ts := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer ts.Stop()
var wg sync.WaitGroup
@ -227,7 +242,11 @@ func TestRepoAddFileCompletion(t *testing.T) {
}
func TestRepoAddWithPasswordFromStdin(t *testing.T) {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*"), repotest.WithBasicAuth())
srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
repotest.WithMiddleware(repotest.BasicAuthMiddleware(t)),
)
defer srv.Stop()
defer resetEnv()()

@ -30,7 +30,10 @@ import (
)
func TestRepoRemove(t *testing.T) {
ts := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*"))
ts := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer ts.Stop()
rootDir := t.TempDir()
@ -159,7 +162,11 @@ func testCacheFiles(t *testing.T, cacheIndexFile string, cacheChartsFile string,
}
func TestRepoRemoveCompletion(t *testing.T) {
ts := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*"))
ts := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer ts.Stop()
rootDir := t.TempDir()

@ -106,7 +106,11 @@ func TestUpdateCustomCacheCmd(t *testing.T) {
cachePath := filepath.Join(rootDir, "updcustomcache")
os.Mkdir(cachePath, os.ModePerm)
ts := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*"))
ts := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer ts.Stop()
o := &repoUpdateOptions{
@ -127,7 +131,9 @@ func TestUpdateCharts(t *testing.T) {
defer resetEnv()()
ensure.HelmHome(t)
ts := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*"))
ts := repotest.NewTempServer(t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer ts.Stop()
r, err := repo.NewChartRepository(&repo.Entry{
@ -159,7 +165,10 @@ func TestUpdateChartsFail(t *testing.T) {
defer resetEnv()()
ensure.HelmHome(t)
ts := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*"))
ts := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer ts.Stop()
var invalidURL = ts.URL() + "55"
@ -189,7 +198,10 @@ func TestUpdateChartsFailWithError(t *testing.T) {
defer resetEnv()()
ensure.HelmHome(t)
ts := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testserver/*.*"))
ts := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testserver/*.*"),
)
defer ts.Stop()
var invalidURL = ts.URL() + "55"

@ -26,7 +26,10 @@ import (
)
func TestShowPreReleaseChart(t *testing.T) {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/testcharts/*.tgz*"))
srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testcharts/*.tgz*"),
)
defer srv.Stop()
if err := srv.LinkIndices(); err != nil {

@ -171,7 +171,11 @@ func TestIsTar(t *testing.T) {
}
func TestDownloadTo(t *testing.T) {
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/*.tgz*"), repotest.WithBasicAuth())
srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/*.tgz*"),
repotest.WithMiddleware(repotest.BasicAuthMiddleware(t)),
)
defer srv.Stop()
if err := srv.CreateIndex(); err != nil {
t.Fatal(err)
@ -218,7 +222,11 @@ func TestDownloadTo(t *testing.T) {
func TestDownloadTo_TLS(t *testing.T) {
// Set up mock server w/ tls enabled
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/*.tgz*"), repotest.WithTLS())
srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/*.tgz*"),
repotest.WithTLS(),
)
defer srv.Stop()
if err := srv.CreateIndex(); err != nil {
t.Fatal(err)
@ -269,7 +277,10 @@ func TestDownloadTo_VerifyLater(t *testing.T) {
dest := t.TempDir()
// Set up a fake repo
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/*.tgz*"))
srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/*.tgz*"),
)
defer srv.Stop()
if err := srv.LinkIndices(); err != nil {
t.Fatal(err)

@ -292,7 +292,10 @@ version: 0.1.0`
func TestUpdateBeforeBuild(t *testing.T) {
// Set up a fake repo
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/*.tgz*"))
srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/*.tgz*"),
)
defer srv.Stop()
if err := srv.LinkIndices(); err != nil {
t.Fatal(err)
@ -358,7 +361,10 @@ func TestUpdateBeforeBuild(t *testing.T) {
// to be fetched.
func TestUpdateWithNoRepo(t *testing.T) {
// Set up a fake repo
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/*.tgz*"))
srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/*.tgz*"),
)
defer srv.Stop()
if err := srv.LinkIndices(); err != nil {
t.Fatal(err)
@ -427,7 +433,10 @@ func TestUpdateWithNoRepo(t *testing.T) {
// If each of these main fields (name, version, repository) is not supplied by dep param, default value will be used.
func checkBuildWithOptionalFields(t *testing.T, chartName string, dep chart.Dependency) {
// Set up a fake repo
srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/*.tgz*"))
srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/*.tgz*"),
)
defer srv.Stop()
if err := srv.LinkIndices(); err != nil {
t.Fatal(err)

@ -33,14 +33,23 @@ import (
"golang.org/x/crypto/bcrypt"
"sigs.k8s.io/yaml"
"helm.sh/helm/v3/internal/tlsutil"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/chartutil"
ociRegistry "helm.sh/helm/v3/pkg/registry"
"helm.sh/helm/v3/pkg/repo"
"helm.sh/helm/v3/testdata"
)
func BasicAuthMiddleware(t *testing.T) http.HandlerFunc {
return http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
username, password, ok := r.BasicAuth()
if !ok || username != "username" || password != "password" {
t.Errorf("Expected request to use basic auth and for username == 'username' and password == 'password', got '%v', '%s', '%s'", ok, username, password)
}
})
}
type ServerOption func(*testing.T, *Server)
func WithTLS() ServerOption {
@ -49,14 +58,9 @@ func WithTLS() ServerOption {
}
}
func WithBasicAuth() ServerOption {
return func(t *testing.T, server *Server) {
server.middleware = http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
username, password, ok := r.BasicAuth()
if !ok || username != "username" || password != "password" {
t.Errorf("Expected request to use basic auth and for username == 'username' and password == 'password', got '%v', '%s', '%s'", ok, username, password)
}
})
func WithMiddleware(middleware http.HandlerFunc) ServerOption {
return func(_ *testing.T, server *Server) {
server.middleware = middleware
}
}
@ -369,10 +373,14 @@ func (s *Server) Start() {
if s.useTLS {
insecure := false
tlsConf, err := testdata.ReadTLSConfig(insecure)
cd := "../../testdata"
ca, pub, priv := filepath.Join(cd, "rootca.crt"), filepath.Join(cd, "crt.pem"), filepath.Join(cd, "key.pem")
tlsConf, err := tlsutil.NewClientTLS(pub, priv, ca, insecure)
if err != nil {
panic(err)
}
tlsConf.ServerName = "helm.sh"
s.srv.TLS = tlsConf
s.srv.StartTLS()

@ -100,7 +100,10 @@ func TestServer(t *testing.T) {
func TestNewTempServer(t *testing.T) {
ensure.HelmHome(t)
srv := NewTempServer(t, WithChartSourceGlob("testdata/examplechart-0.1.0.tgz"))
srv := NewTempServer(
t,
WithChartSourceGlob("testdata/examplechart-0.1.0.tgz"),
)
defer srv.Stop()
if srv.srv.URL == "" {
@ -137,7 +140,11 @@ func TestNewTempServer(t *testing.T) {
func TestNewTempServer_TLS(t *testing.T) {
ensure.HelmHome(t)
srv := NewTempServer(t, WithChartSourceGlob("testdata/examplechart-0.1.0.tgz"), WithTLS())
srv := NewTempServer(
t,
WithChartSourceGlob("testdata/examplechart-0.1.0.tgz"),
WithTLS(),
)
defer srv.Stop()
if !strings.HasPrefix(srv.URL(), "https://") {

Loading…
Cancel
Save