Unverified Commit ab82787d authored by Tomasz Maczukin's avatar Tomasz Maczukin
Browse files

Rename common.BuildCredentials common.JobCredentials

parent 76b65719
......@@ -15,13 +15,13 @@ import (
)
type ArtifactsDownloaderCommand struct {
common.BuildCredentials
common.JobCredentials
retryHelper
network common.Network
}
func (c *ArtifactsDownloaderCommand) download(file string) (bool, error) {
switch c.network.DownloadArtifacts(c.BuildCredentials, file) {
switch c.network.DownloadArtifacts(c.JobCredentials, file) {
case common.DownloadSucceeded:
return false, nil
case common.DownloadNotFound:
......
......@@ -10,7 +10,7 @@ import (
"os"
)
var downloaderCredentials = common.BuildCredentials{
var downloaderCredentials = common.JobCredentials{
ID: 1000,
Token: "test",
URL: "test",
......@@ -30,8 +30,8 @@ func TestArtifactsDownloaderNotFound(t *testing.T) {
downloadState: common.DownloadNotFound,
}
cmd := ArtifactsDownloaderCommand{
BuildCredentials: downloaderCredentials,
network: network,
JobCredentials: downloaderCredentials,
network: network,
}
assert.Panics(t, func() {
......@@ -46,8 +46,8 @@ func TestArtifactsDownloaderForbidden(t *testing.T) {
downloadState: common.DownloadForbidden,
}
cmd := ArtifactsDownloaderCommand{
BuildCredentials: downloaderCredentials,
network: network,
JobCredentials: downloaderCredentials,
network: network,
}
assert.Panics(t, func() {
......@@ -62,8 +62,8 @@ func TestArtifactsDownloaderRetry(t *testing.T) {
downloadState: common.DownloadFailed,
}
cmd := ArtifactsDownloaderCommand{
BuildCredentials: downloaderCredentials,
network: network,
JobCredentials: downloaderCredentials,
network: network,
retryHelper: retryHelper{
Retry: 2,
},
......@@ -81,8 +81,8 @@ func TestArtifactsDownloaderSucceeded(t *testing.T) {
downloadState: common.DownloadSucceeded,
}
cmd := ArtifactsDownloaderCommand{
BuildCredentials: downloaderCredentials,
network: network,
JobCredentials: downloaderCredentials,
network: network,
}
os.Remove(artifactsTestArchivedFile)
......
......@@ -21,7 +21,7 @@ type testNetwork struct {
uploadCalled int
}
func (m *testNetwork) DownloadArtifacts(config common.BuildCredentials, artifactsFile string) common.DownloadState {
func (m *testNetwork) DownloadArtifacts(config common.JobCredentials, artifactsFile string) common.DownloadState {
m.downloadCalled++
if m.downloadState == common.DownloadSucceeded {
......@@ -39,7 +39,7 @@ func (m *testNetwork) DownloadArtifacts(config common.BuildCredentials, artifact
return m.downloadState
}
func (m *testNetwork) UploadRawArtifacts(config common.BuildCredentials, reader io.Reader, baseName string, expireIn string) common.UploadState {
func (m *testNetwork) UploadRawArtifacts(config common.JobCredentials, reader io.Reader, baseName string, expireIn string) common.UploadState {
m.uploadCalled++
if m.uploadState == common.UploadSucceeded {
......
......@@ -17,7 +17,7 @@ import (
)
type ArtifactsUploaderCommand struct {
common.BuildCredentials
common.JobCredentials
fileArchiver
retryHelper
network common.Network
......@@ -39,7 +39,7 @@ func (c *ArtifactsUploaderCommand) createAndUpload() (bool, error) {
artifactsName := path.Base(c.Name) + ".zip"
// Upload the data
switch c.network.UploadRawArtifacts(c.BuildCredentials, pr, artifactsName, c.ExpireIn) {
switch c.network.UploadRawArtifacts(c.JobCredentials, pr, artifactsName, c.ExpireIn) {
case common.UploadSucceeded:
return false, nil
case common.UploadForbidden:
......
......@@ -11,7 +11,7 @@ import (
"io/ioutil"
)
var UploaderCredentials = common.BuildCredentials{
var UploaderCredentials = common.JobCredentials{
ID: 1000,
Token: "test",
URL: "test",
......@@ -31,8 +31,8 @@ func TestArtifactsUploaderTooLarge(t *testing.T) {
uploadState: common.UploadTooLarge,
}
cmd := ArtifactsUploaderCommand{
BuildCredentials: UploaderCredentials,
network: network,
JobCredentials: UploaderCredentials,
network: network,
}
assert.Panics(t, func() {
......@@ -47,8 +47,8 @@ func TestArtifactsUploaderForbidden(t *testing.T) {
uploadState: common.UploadForbidden,
}
cmd := ArtifactsUploaderCommand{
BuildCredentials: UploaderCredentials,
network: network,
JobCredentials: UploaderCredentials,
network: network,
}
assert.Panics(t, func() {
......@@ -63,8 +63,8 @@ func TestArtifactsUploaderRetry(t *testing.T) {
uploadState: common.UploadFailed,
}
cmd := ArtifactsUploaderCommand{
BuildCredentials: UploaderCredentials,
network: network,
JobCredentials: UploaderCredentials,
network: network,
retryHelper: retryHelper{
Retry: 2,
},
......@@ -82,8 +82,8 @@ func TestArtifactsUploaderSucceeded(t *testing.T) {
uploadState: common.UploadSucceeded,
}
cmd := ArtifactsUploaderCommand{
BuildCredentials: UploaderCredentials,
network: network,
JobCredentials: UploaderCredentials,
network: network,
fileArchiver: fileArchiver{
Paths: []string{artifactsTestArchivedFile},
},
......
......@@ -124,7 +124,7 @@ func (mr *RunCommand) processRunner(id int, runner *common.RunnerConfig, runners
}
// Make sure to always close output
buildCredentials := &common.BuildCredentials{
buildCredentials := &common.JobCredentials{
ID: buildData.ID,
Token: buildData.Token,
}
......
......@@ -91,7 +91,7 @@ func (r *RunSingleCommand) processBuild(data common.ExecutorData, abortSignal ch
ExecutorData: data,
}
buildCredentials := &common.BuildCredentials{
buildCredentials := &common.JobCredentials{
ID: buildData.ID,
Token: buildData.Token,
}
......
......@@ -50,35 +50,35 @@ func (m *MockNetwork) UpdateBuild(config RunnerConfig, id int, state BuildState,
return r0
}
func (m *MockNetwork) PatchTrace(config RunnerConfig, buildCredentials *BuildCredentials, tracePart BuildTracePatch) UpdateState {
func (m *MockNetwork) PatchTrace(config RunnerConfig, buildCredentials *JobCredentials, tracePart BuildTracePatch) UpdateState {
ret := m.Called(config, buildCredentials, tracePart)
r0 := ret.Get(0).(UpdateState)
return r0
}
func (m *MockNetwork) DownloadArtifacts(config BuildCredentials, artifactsFile string) DownloadState {
func (m *MockNetwork) DownloadArtifacts(config JobCredentials, artifactsFile string) DownloadState {
ret := m.Called(config, artifactsFile)
r0 := ret.Get(0).(DownloadState)
return r0
}
func (m *MockNetwork) UploadRawArtifacts(config BuildCredentials, reader io.Reader, baseName string, expireIn string) UploadState {
func (m *MockNetwork) UploadRawArtifacts(config JobCredentials, reader io.Reader, baseName string, expireIn string) UploadState {
ret := m.Called(config, reader, baseName, expireIn)
r0 := ret.Get(0).(UploadState)
return r0
}
func (m *MockNetwork) UploadArtifacts(config BuildCredentials, artifactsFile string) UploadState {
func (m *MockNetwork) UploadArtifacts(config JobCredentials, artifactsFile string) UploadState {
ret := m.Called(config, artifactsFile)
r0 := ret.Get(0).(UploadState)
return r0
}
func (m *MockNetwork) ProcessBuild(config RunnerConfig, buildCredentials *BuildCredentials) BuildTrace {
func (m *MockNetwork) ProcessBuild(config RunnerConfig, buildCredentials *JobCredentials) BuildTrace {
ret := m.Called(config, buildCredentials)
r0 := ret.Get(0).(BuildTrace)
......
......@@ -141,22 +141,22 @@ type UpdateBuildRequest struct {
Trace *string `json:"trace,omitempty"`
}
type BuildCredentials struct {
type JobCredentials struct {
ID int `long:"id" env:"CI_BUILD_ID" description:"The build ID to upload artifacts for"`
Token string `long:"token" env:"CI_BUILD_TOKEN" required:"true" description:"Build token"`
URL string `long:"url" env:"CI_SERVER_URL" required:"true" description:"GitLab CI URL"`
TLSCAFile string `long:"tls-ca-file" env:"CI_SERVER_TLS_CA_FILE" description:"File containing the certificates to verify the peer when using HTTPS"`
}
func (j *BuildCredentials) GetURL() string {
func (j *JobCredentials) GetURL() string {
return j.URL
}
func (j *BuildCredentials) GetTLSCAFile() string {
func (j *JobCredentials) GetTLSCAFile() string {
return j.TLSCAFile
}
func (j *BuildCredentials) GetToken() string {
func (j *JobCredentials) GetToken() string {
return j.Token
}
......@@ -182,9 +182,9 @@ type Network interface {
UnregisterRunner(config RunnerCredentials) bool
GetBuild(config RunnerConfig) (*GetBuildResponse, bool)
UpdateBuild(config RunnerConfig, id int, state BuildState, trace *string) UpdateState
PatchTrace(config RunnerConfig, buildCredentials *BuildCredentials, tracePart BuildTracePatch) UpdateState
DownloadArtifacts(config BuildCredentials, artifactsFile string) DownloadState
UploadRawArtifacts(config BuildCredentials, reader io.Reader, baseName string, expireIn string) UploadState
UploadArtifacts(config BuildCredentials, artifactsFile string) UploadState
ProcessBuild(config RunnerConfig, buildCredentials *BuildCredentials) BuildTrace
PatchTrace(config RunnerConfig, buildCredentials *JobCredentials, tracePart BuildTracePatch) UpdateState
DownloadArtifacts(config JobCredentials, artifactsFile string) DownloadState
UploadRawArtifacts(config JobCredentials, reader io.Reader, baseName string, expireIn string) UploadState
UploadArtifacts(config JobCredentials, artifactsFile string) UploadState
ProcessBuild(config RunnerConfig, buildCredentials *JobCredentials) BuildTrace
}
......@@ -65,7 +65,7 @@ type clientBuildTrace struct {
client common.Network
config common.RunnerConfig
buildCredentials *common.BuildCredentials
buildCredentials *common.JobCredentials
id int
limit int64
abortCh chan interface{}
......@@ -240,7 +240,7 @@ func (c *clientBuildTrace) incrementalUpdate() common.UpdateState {
return update
}
func (c *clientBuildTrace) resendPatch(id int, config common.RunnerConfig, buildCredentials *common.BuildCredentials, tracePatch common.BuildTracePatch) (update common.UpdateState) {
func (c *clientBuildTrace) resendPatch(id int, config common.RunnerConfig, buildCredentials *common.JobCredentials, tracePatch common.BuildTracePatch) (update common.UpdateState) {
if !tracePatch.ValidateRange() {
config.Log().Warningln(id, "Full build update is needed")
fullTrace := c.log.String()
......@@ -309,7 +309,7 @@ func (c *clientBuildTrace) watch() {
}
}
func newBuildTrace(client common.Network, config common.RunnerConfig, buildCredentials *common.BuildCredentials) *clientBuildTrace {
func newBuildTrace(client common.Network, config common.RunnerConfig, buildCredentials *common.JobCredentials) *clientBuildTrace {
return &clientBuildTrace{
client: client,
config: config,
......
......@@ -53,13 +53,13 @@ func (m *updateTraceNetwork) UpdateBuild(config common.RunnerConfig, id int, sta
}
}
func (m *updateTraceNetwork) PatchTrace(config common.RunnerConfig, buildCredentials *common.BuildCredentials, tracePatch common.BuildTracePatch) common.UpdateState {
func (m *updateTraceNetwork) PatchTrace(config common.RunnerConfig, buildCredentials *common.JobCredentials, tracePatch common.BuildTracePatch) common.UpdateState {
return common.UpdateNotFound
}
func TestBuildTraceSuccess(t *testing.T) {
u := &updateTraceNetwork{}
buildCredentials := &common.BuildCredentials{
buildCredentials := &common.JobCredentials{
ID: successID,
}
b := newBuildTrace(u, buildConfig, buildCredentials)
......@@ -72,7 +72,7 @@ func TestBuildTraceSuccess(t *testing.T) {
func TestBuildTraceFailure(t *testing.T) {
u := &updateTraceNetwork{}
buildCredentials := &common.BuildCredentials{
buildCredentials := &common.JobCredentials{
ID: successID,
}
b := newBuildTrace(u, buildConfig, buildCredentials)
......@@ -85,7 +85,7 @@ func TestBuildTraceFailure(t *testing.T) {
func TestIgnoreStatusChange(t *testing.T) {
u := &updateTraceNetwork{}
buildCredentials := &common.BuildCredentials{
buildCredentials := &common.JobCredentials{
ID: successID,
}
b := newBuildTrace(u, buildConfig, buildCredentials)
......@@ -99,7 +99,7 @@ func TestBuildAbort(t *testing.T) {
traceUpdateInterval = 0
u := &updateTraceNetwork{}
buildCredentials := &common.BuildCredentials{
buildCredentials := &common.JobCredentials{
ID: cancelID,
}
b := newBuildTrace(u, buildConfig, buildCredentials)
......@@ -110,7 +110,7 @@ func TestBuildAbort(t *testing.T) {
func TestBuildOutputLimit(t *testing.T) {
u := &updateTraceNetwork{}
buildCredentials := &common.BuildCredentials{
buildCredentials := &common.JobCredentials{
ID: successID,
}
b := newBuildTrace(u, buildOutputLimit, buildCredentials)
......@@ -129,7 +129,7 @@ func TestBuildFinishRetry(t *testing.T) {
traceFinishRetryInterval = time.Microsecond
u := &updateTraceNetwork{}
buildCredentials := &common.BuildCredentials{
buildCredentials := &common.JobCredentials{
ID: retryID,
}
b := newBuildTrace(u, buildOutputLimit, buildCredentials)
......@@ -144,7 +144,7 @@ func TestBuildForceSend(t *testing.T) {
traceForceSendInterval = time.Minute
u := &updateTraceNetwork{}
buildCredentials := &common.BuildCredentials{
buildCredentials := &common.JobCredentials{
ID: successID,
}
b := newBuildTrace(u, buildOutputLimit, buildCredentials)
......
......@@ -228,7 +228,7 @@ func (n *GitLabClient) UpdateBuild(config common.RunnerConfig, id int, state com
}
}
func (n *GitLabClient) PatchTrace(config common.RunnerConfig, buildCredentials *common.BuildCredentials, tracePatch common.BuildTracePatch) common.UpdateState {
func (n *GitLabClient) PatchTrace(config common.RunnerConfig, buildCredentials *common.JobCredentials, tracePatch common.BuildTracePatch) common.UpdateState {
id := buildCredentials.ID
contentRange := fmt.Sprintf("%d-%d", tracePatch.Offset(), tracePatch.Limit())
......@@ -293,7 +293,7 @@ func (n *GitLabClient) createArtifactsForm(mpw *multipart.Writer, reader io.Read
return nil
}
func (n *GitLabClient) UploadRawArtifacts(config common.BuildCredentials, reader io.Reader, baseName string, expireIn string) common.UploadState {
func (n *GitLabClient) UploadRawArtifacts(config common.JobCredentials, reader io.Reader, baseName string, expireIn string) common.UploadState {
pr, pw := io.Pipe()
defer pr.Close()
......@@ -349,7 +349,7 @@ func (n *GitLabClient) UploadRawArtifacts(config common.BuildCredentials, reader
}
}
func (n *GitLabClient) UploadArtifacts(config common.BuildCredentials, artifactsFile string) common.UploadState {
func (n *GitLabClient) UploadArtifacts(config common.JobCredentials, artifactsFile string) common.UploadState {
log := logrus.WithFields(logrus.Fields{
"id": config.ID,
"token": helpers.ShortenToken(config.Token),
......@@ -376,7 +376,7 @@ func (n *GitLabClient) UploadArtifacts(config common.BuildCredentials, artifacts
return n.UploadRawArtifacts(config, file, baseName, "")
}
func (n *GitLabClient) DownloadArtifacts(config common.BuildCredentials, artifactsFile string) common.DownloadState {
func (n *GitLabClient) DownloadArtifacts(config common.JobCredentials, artifactsFile string) common.DownloadState {
headers := make(http.Header)
headers.Set("BUILD-TOKEN", config.Token)
res, err := n.doRaw(&config, "GET", fmt.Sprintf("builds/%d/artifacts", config.ID), nil, "", headers)
......@@ -424,7 +424,7 @@ func (n *GitLabClient) DownloadArtifacts(config common.BuildCredentials, artifac
}
}
func (n *GitLabClient) ProcessBuild(config common.RunnerConfig, buildCredentials *common.BuildCredentials) common.BuildTrace {
func (n *GitLabClient) ProcessBuild(config common.RunnerConfig, buildCredentials *common.JobCredentials) common.BuildTrace {
trace := newBuildTrace(n, config, buildCredentials)
trace.start()
return trace
......
......@@ -471,12 +471,12 @@ func TestArtifactsUpload(t *testing.T) {
s := httptest.NewServer(http.HandlerFunc(handler))
defer s.Close()
config := BuildCredentials{
config := JobCredentials{
ID: 10,
URL: s.URL,
Token: "token",
}
invalidToken := BuildCredentials{
invalidToken := JobCredentials{
ID: 10,
URL: s.URL,
Token: "invalid-token",
......@@ -559,7 +559,7 @@ func TestUnknownPatchTrace(t *testing.T) {
defer server.Close()
tracePatch := getTracePatch(patchTraceString, 0)
state := client.PatchTrace(config, &BuildCredentials{ID: 1, Token: patchToken}, tracePatch)
state := client.PatchTrace(config, &JobCredentials{ID: 1, Token: patchToken}, tracePatch)
assert.Equal(t, UpdateNotFound, state)
}
......@@ -572,7 +572,7 @@ func TestForbiddenPatchTrace(t *testing.T) {
defer server.Close()
tracePatch := getTracePatch(patchTraceString, 0)
state := client.PatchTrace(config, &BuildCredentials{ID: 1, Token: patchToken}, tracePatch)
state := client.PatchTrace(config, &JobCredentials{ID: 1, Token: patchToken}, tracePatch)
assert.Equal(t, UpdateAbort, state)
}
......@@ -587,15 +587,15 @@ func TestPatchTrace(t *testing.T) {
defer server.Close()
tracePatch := getTracePatch(patchTraceString, 0)
state := client.PatchTrace(config, &BuildCredentials{ID: 1, Token: patchToken}, tracePatch)
state := client.PatchTrace(config, &JobCredentials{ID: 1, Token: patchToken}, tracePatch)
assert.Equal(t, UpdateSucceeded, state)
tracePatch = getTracePatch(patchTraceString, 3)
state = client.PatchTrace(config, &BuildCredentials{ID: 1, Token: patchToken}, tracePatch)
state = client.PatchTrace(config, &JobCredentials{ID: 1, Token: patchToken}, tracePatch)
assert.Equal(t, UpdateSucceeded, state)
tracePatch = getTracePatch(patchTraceString[:10], 3)
state = client.PatchTrace(config, &BuildCredentials{ID: 1, Token: patchToken}, tracePatch)
state = client.PatchTrace(config, &JobCredentials{ID: 1, Token: patchToken}, tracePatch)
assert.Equal(t, UpdateSucceeded, state)
}
......@@ -613,15 +613,15 @@ func TestRangeMismatchPatchTrace(t *testing.T) {
defer server.Close()
tracePatch := getTracePatch(patchTraceString, 11)
state := client.PatchTrace(config, &BuildCredentials{ID: 1, Token: patchToken}, tracePatch)
state := client.PatchTrace(config, &JobCredentials{ID: 1, Token: patchToken}, tracePatch)
assert.Equal(t, UpdateRangeMismatch, state)
tracePatch = getTracePatch(patchTraceString, 15)
state = client.PatchTrace(config, &BuildCredentials{ID: 1, Token: patchToken}, tracePatch)
state = client.PatchTrace(config, &JobCredentials{ID: 1, Token: patchToken}, tracePatch)
assert.Equal(t, UpdateRangeMismatch, state)
tracePatch = getTracePatch(patchTraceString, 5)
state = client.PatchTrace(config, &BuildCredentials{ID: 1, Token: patchToken}, tracePatch)
state = client.PatchTrace(config, &JobCredentials{ID: 1, Token: patchToken}, tracePatch)
assert.Equal(t, UpdateSucceeded, state)
}
......@@ -639,10 +639,10 @@ func TestResendPatchTrace(t *testing.T) {
defer server.Close()
tracePatch := getTracePatch(patchTraceString, 11)
state := client.PatchTrace(config, &BuildCredentials{ID: 1, Token: patchToken}, tracePatch)
state := client.PatchTrace(config, &JobCredentials{ID: 1, Token: patchToken}, tracePatch)
assert.Equal(t, UpdateRangeMismatch, state)
state = client.PatchTrace(config, &BuildCredentials{ID: 1, Token: patchToken}, tracePatch)
state = client.PatchTrace(config, &JobCredentials{ID: 1, Token: patchToken}, tracePatch)
assert.Equal(t, UpdateSucceeded, state)
}
......@@ -665,7 +665,7 @@ func TestResendDoubledBuildPatchTrace(t *testing.T) {
defer server.Close()
tracePatch := getTracePatch(patchTraceString, 11)
state := client.PatchTrace(config, &BuildCredentials{ID: 1, Token: patchToken}, tracePatch)
state := client.PatchTrace(config, &JobCredentials{ID: 1, Token: patchToken}, tracePatch)
assert.Equal(t, UpdateRangeMismatch, state)
assert.False(t, tracePatch.ValidateRange())
}
......@@ -680,6 +680,6 @@ func TestBuildFailedStatePatchTrace(t *testing.T) {
defer server.Close()
tracePatch := getTracePatch(patchTraceString, 0)
state := client.PatchTrace(config, &BuildCredentials{ID: 1, Token: patchToken}, tracePatch)
state := client.PatchTrace(config, &JobCredentials{ID: 1, Token: patchToken}, tracePatch)
assert.Equal(t, UpdateAbort, state)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment