File: adapter.go

package info (click to toggle)
gitlab-ci-multi-runner 14.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 31,248 kB
  • sloc: sh: 1,694; makefile: 384; asm: 79; ruby: 68
file content (72 lines) | stat: -rw-r--r-- 1,452 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package test

import (
	"net/http"
	"net/url"
	"time"

	"gitlab.com/gitlab-org/gitlab-runner/cache"
	"gitlab.com/gitlab-org/gitlab-runner/common"
)

type testAdapter struct {
	objectName string
	useGoCloud bool
}

func (t *testAdapter) GetDownloadURL() *url.URL {
	return t.getURL("download")
}

func (t *testAdapter) GetUploadURL() *url.URL {
	return t.getURL("upload")
}

func (t *testAdapter) GetUploadHeaders() http.Header {
	headers := http.Header{}
	headers.Set("header-1", "a value")

	return headers
}

func (t *testAdapter) GetGoCloudURL() *url.URL {
	if t.useGoCloud {
		u, _ := url.Parse("gocloud://test")
		return u
	}

	return nil
}

func (t *testAdapter) GetUploadEnv() map[string]string {
	return map[string]string{
		"FIRST_VAR":  "123",
		"SECOND_VAR": "456",
	}
}

func (t *testAdapter) getURL(operation string) *url.URL {
	return &url.URL{
		Scheme: "test",
		Host:   operation,
		Path:   t.objectName,
	}
}

func New(_ *common.CacheConfig, _ time.Duration, objectName string) (cache.Adapter, error) {
	return &testAdapter{objectName: objectName}, nil
}

func NewGoCloudAdapter(_ *common.CacheConfig, _ time.Duration, objectName string) (cache.Adapter, error) {
	return &testAdapter{objectName: objectName, useGoCloud: true}, nil
}

func init() {
	if err := cache.Factories().Register("test", New); err != nil {
		panic(err)
	}

	if err := cache.Factories().Register("goCloudTest", NewGoCloudAdapter); err != nil {
		panic(err)
	}
}