func (rt *RepoTester) GetChartPackage(w http.ResponseWriter, r *http.Request, chartPackageName string) {
	w.WriteHeader(200)
	_, filename, _, _ := runtime.Caller(1)
	testdataPath := path.Join(path.Dir(filename), "../../../testdata")
	chartPackageFile := path.Join(testdataPath, "charts", chartPackageName)
	chartPackage, err := ioutil.ReadFile(chartPackageFile)
	if err != nil {
		rt.t.Fatal(err)
	}
	w.Write(chartPackage)
}
GetChartPackage returns a packaged helm chart
package helmclassic
import (
	"archive/tar"
	"compress/gzip"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"net/url"
	"path"
	"path/filepath"
	"regexp"
	"runtime"
	"strings"
	"testing"
	"github.com/bitnami-labs/charts-syncer/api"
	"gopkg.in/yaml.v2"
)
var (
	helmRegex        = regexp.MustCompile(`(?m)\/charts\/(.*.tgz)`)
	username  string = "user"
	password  string = "password"
)
type Metadata struct {
	AppVersion string `json:"appVersion"`
	Name       string `json:"name"`
	Version    string `json:"version"`
}
type ChartVersion struct {
	Name    string   `json:"name"`
	Version string   `json:"version"`
	URLs    []string `json:"urls"`
}
type httpError struct {
	status int
	body   string
}
type RepoTester struct {
	url      *url.URL
	username string
	password string
	t        *testing.T
	index map[string][]*ChartVersion
	emptyIndex bool
	indexFile string
	ChartsPostError *httpError
}
func NewTester(t *testing.T, repo *api.Repo, emptyIndex bool, indexFile string, createServer bool) *RepoTester {
	t.Helper()
	tester := &RepoTester{
		t:          t,
		username:   username,
		password:   password,
		emptyIndex: emptyIndex,
		indexFile:  indexFile,
		index:      make(map[string][]*ChartVersion),
	}
	if createServer {
		s := httptest.NewServer(tester)
		u, err := url.Parse(s.URL)
		if err != nil {
			t.Fatal(err)
		}
		t.Cleanup(s.Close)
		tester.url = u
	}
	return tester
}
func (rt *RepoTester) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	username, password, ok := r.BasicAuth()
	if got, want := ok, true; got != want {
		rt.t.Errorf("got: %t, want: %t", got, want)
	}
	if got, want := username, rt.username; got != want {
		rt.t.Errorf("got: %q, want: %q", got, want)
	}
	if got, want := password, rt.password; got != want {
		rt.t.Errorf("got: %q, want: %q", got, want)
	}
	if r.URL.Path == "/index.yaml" && r.Method == "GET" {
		rt.GetIndex(w, r, rt.emptyIndex, rt.indexFile)
		return
	}
	if helmRegex.Match([]byte(r.URL.Path)) && r.Method == "GET" {
		chartPackage := strings.Split(r.URL.Path, "/")[2]
		rt.GetChartPackage(w, r, chartPackage)
		return
	}
	rt.t.Fatalf("unexpected request %s %s", r.Method, r.URL.Path)
}
func (rt *RepoTester) GetChart(w http.ResponseWriter, r *http.Request, chart string) {
	w.Header().Set("Content-Type", "application/json")
	if err := json.NewEncoder(w).Encode(rt.index[chart]); err != nil {
		rt.t.Fatal(err)
	}
}
func (rt *RepoTester) GetURL() string {
	return rt.url.String()
}
func (rt *RepoTester) GetIndex(w http.ResponseWriter, r *http.Request, emptyIndex bool, indexFile string) {
	w.Header().Set("Content-Type", "application/yaml")
	w.WriteHeader(200)
	_, filename, _, _ := runtime.Caller(1)
	testdataPath := path.Join(path.Dir(filename), "../../../testdata")
	if indexFile == "" {
		indexFile = filepath.Join(testdataPath, "index.yaml")
	}
	if emptyIndex {
		indexFile = filepath.Join(testdataPath, "empty-index.yaml")
	}
	index, err := ioutil.ReadFile(indexFile)
	if err != nil {
		rt.t.Fatal(err)
	}
	w.Write(index)
}