testing

package
v0.0.0-...-44f477e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ChartListContent = []byte{} /* 1257 elements not displayed */

ChartListContent is the mock data of chart list

View Source
var HelmChartContent = []byte{} /* 17597 elements not displayed */

HelmChartContent is mock data of chart tgz...

View Source
var HelmChartProvContent = []byte{} /* 1269 elements not displayed */

HelmChartProvContent is mock data of chart tgz...

View Source
var MockChartRepoHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	hlog.Infof("Incoming testing request: %s", r.RequestURI)
	switch r.RequestURI {
	case "/health":
		if r.Method == http.MethodGet {
			mockStatus := make(map[string]interface{})
			mockStatus["health"] = true
			data, _ := json.Marshal(mockStatus)
			w.Write(data)

			return
		}
	case "/repo1/index.yaml", "/library/index.yaml":
		if r.Method == http.MethodGet {
			w.Write([]byte(repo1IndexYaml))
			return
		}
	case "/repo2/index.yaml":
		if r.Method == http.MethodGet {
			w.Write([]byte(repo2IndexYaml))
			return
		}
	case "/not-existing-ns/index.yaml":
		if r.Method == http.MethodGet {
			w.WriteHeader(http.StatusNotFound)
			return
		}
	case "/repo1/charts/harbor-0.2.0.tgz",
		"/library/charts/harbor-0.2.0.tgz":
		if r.Method == http.MethodGet {
			w.Write(HelmChartContent)
			return
		}
	case "/repo1/charts/harbor-0.2.0.tgz.prov",
		"/library/charts/harbor-0.2.0.tgz.prov":
		if r.Method == http.MethodGet {
			w.Write(HelmChartProvContent)
			return
		}
	case "/api/repo1/charts", "/api/library/charts":
		if r.Method == http.MethodGet {
			w.Write(ChartListContent)
			return
		}
	case "/api/repo1/charts/harbor/0.2.0",
		"/api/library/charts/harbor/0.2.0":
		if r.Method == http.MethodGet {
			w.Write([]byte(harborChartV))
			return
		}
		if r.Method == http.MethodDelete {
			w.WriteHeader(http.StatusOK)
			return
		}
	case "/api/repo1/charts/harbor/1.0.0":
		if r.Method == http.MethodGet {
			w.WriteHeader(http.StatusNotFound)
			w.Write([]byte("Not found"))
			return
		}
	case "/api/repo1/charts/harbor/0.2.1",
		"/api/library/charts/harbor/0.2.1":
		if r.Method == http.MethodDelete {
			w.WriteHeader(http.StatusOK)
			return
		}
	case "/api/repo1/charts/harbor":
		if r.Method == http.MethodGet {
			w.Write([]byte(chartVersionsOfHarbor))
			return
		}
	case "/api/library/charts/harbor":
		if r.Method == http.MethodGet {
			w.Write([]byte(chartVersionsOfHarbor))
			return
		}
		if r.Method == http.MethodDelete {
			w.WriteHeader(http.StatusOK)
		}
	case "/repo3/charts/harbor-0.8.1.tgz":
		if r.Method == http.MethodGet {
			w.WriteHeader(http.StatusUnauthorized)
			w.Write([]byte("Unauthorized"))
			return
		}
	case "/api/project_for_test_deletable/charts":
		if r.Method == http.MethodGet {
			w.Write([]byte("{}"))
			return
		}
	default:
		if r.Method == http.MethodGet {
			if strings.HasSuffix(r.RequestURI, "/index.yaml") {
				w.Write([]byte(repo2IndexYaml))
				return
			}
		}
	}

	w.WriteHeader(http.StatusNotImplemented)
	w.Write([]byte("not supported"))
})

MockChartRepoHandler is the backend chart server handler

Functions

This section is empty.

Types

type Suite

type Suite struct {
	suite.Suite
	ClearTables []string
	ClearSQLs   []string
}

Suite ...

func (*Suite) AddProject

func (suite *Suite) AddProject(ctx context.Context, project *proModels.Project) (int64, error)

AddProject put here is to avoid import cycle

func (*Suite) Context

func (suite *Suite) Context() context.Context

Context ...

func (*Suite) DeleteProject

func (suite *Suite) DeleteProject(ctx context.Context, projectName string, projectID int64) error

DeleteProject put here is to avoid import cycle

func (*Suite) Digest

func (suite *Suite) Digest() digest.Digest

Digest ...

func (*Suite) DigestString

func (suite *Suite) DigestString() string

DigestString ...

func (*Suite) ExecSQL

func (suite *Suite) ExecSQL(query string, args ...interface{})

ExecSQL ...

func (*Suite) IsNotFoundErr

func (suite *Suite) IsNotFoundErr(err error) bool

IsNotFoundErr ...

func (*Suite) NewRequest

func (suite *Suite) NewRequest(method, target string, body io.Reader, queries ...map[string]string) *http.Request

NewRequest ...

func (*Suite) NextHandler

func (suite *Suite) NextHandler(statusCode int, headers map[string]string) http.Handler

NextHandler ...

func (*Suite) RandString

func (suite *Suite) RandString(n int, letters ...string) string

RandString ...

func (*Suite) SetupSuite

func (suite *Suite) SetupSuite()

SetupSuite ...

func (*Suite) TearDownSuite

func (suite *Suite) TearDownSuite()

TearDownSuite ...

func (*Suite) WithProject

func (suite *Suite) WithProject(f func(int64, string), projectNames ...string)

WithProject ...

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL