Commit aa23dbcf authored by Steve Azzopardi's avatar Steve Azzopardi

Merge branch 'fix-error-check' into 'master'

Fix some linting issues

See merge request gitlab-org/gitlab-runner!1424
parents 215227b4 133b7113
......@@ -70,7 +70,8 @@ func TestCreateAdapter(t *testing.T) {
adapterTypeName := "test"
if test.adapter != nil {
factories.Register(adapterTypeName, makeTestFactory(test))
err := factories.Register(adapterTypeName, makeTestFactory(test))
assert.NoError(t, err)
}
factories.Register("additional-adapter", func(config *common.CacheConfig, timeout time.Duration, objectName string) (Adapter, error) {
......
......@@ -19,7 +19,10 @@ type bucketLocationTripper struct {
// the library.
func (b *bucketLocationTripper) RoundTrip(req *http.Request) (res *http.Response, err error) {
var buffer bytes.Buffer
xml.NewEncoder(&buffer).Encode(b.bucketLocation)
err = xml.NewEncoder(&buffer).Encode(b.bucketLocation)
if err != nil {
return
}
res = &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(&buffer),
......
......@@ -39,7 +39,9 @@ func TestCacheArchiverIsUpToDate(t *testing.T) {
// We need to wait one second, since the FS doesn't save milliseconds
time.Sleep(time.Second)
os.Chtimes(cacheArchiverTestArchivedFile, time.Now(), time.Now())
err := os.Chtimes(cacheArchiverTestArchivedFile, time.Now(), time.Now())
assert.NoError(t, err)
cmd.Execute(nil)
fi3, _ := os.Stat(cacheArchiverArchive)
assert.NotEqual(t, fi.ModTime(), fi3.ModTime(), "archive should get updated")
......
......@@ -13,7 +13,7 @@ import (
"gitlab.com/gitlab-org/gitlab-runner/common"
"gitlab.com/gitlab-org/gitlab-runner/helpers/archives"
"gitlab.com/gitlab-org/gitlab-runner/helpers/url"
url_helpers "gitlab.com/gitlab-org/gitlab-runner/helpers/url"
"gitlab.com/gitlab-org/gitlab-runner/log"
)
......@@ -41,7 +41,10 @@ func checkIfUpToDate(path string, resp *http.Response) (bool, time.Time) {
}
func (c *CacheExtractorCommand) download() error {
os.MkdirAll(filepath.Dir(c.File), 0700)
err := os.MkdirAll(filepath.Dir(c.File), 0700)
if err != nil {
return err
}
resp, err := c.getCache()
if err != nil {
......@@ -68,7 +71,10 @@ func (c *CacheExtractorCommand) download() error {
if err != nil {
return retryableErr{err: err}
}
os.Chtimes(file.Name(), time.Now(), date)
err = os.Chtimes(file.Name(), time.Now(), date)
if err != nil {
return err
}
err = file.Close()
if err != nil {
......
......@@ -26,7 +26,9 @@ func TestCacheExtractorValidArchive(t *testing.T) {
defer os.Remove(cacheExtractorTestArchivedFile)
archive := zip.NewWriter(file)
archive.Create(cacheExtractorTestArchivedFile)
_, err = archive.Create(cacheExtractorTestArchivedFile)
assert.NoError(t, err)
archive.Close()
_, err = os.Stat(cacheExtractorTestArchivedFile)
......@@ -163,7 +165,9 @@ func TestCacheExtractorRemoteServer(t *testing.T) {
_, err := os.Stat(cacheExtractorTestArchivedFile)
assert.NoError(t, err)
os.Chtimes(cacheExtractorArchive, time.Now().Add(time.Hour), time.Now().Add(time.Hour))
err = os.Chtimes(cacheExtractorArchive, time.Now().Add(time.Hour), time.Now().Add(time.Hour))
assert.NoError(t, err)
assert.NotPanics(t, func() {
cmd.Execute(nil)
}, "archive is up to date")
......
......@@ -87,14 +87,15 @@ func TestProcessRunner_BuildLimit(t *testing.T) {
runners := make(chan *common.RunnerConfig)
// Start 5 builds.
// Start 2 builds.
wg := sync.WaitGroup{}
wg.Add(5)
for i := 0; i < 5; i++ {
wg.Add(2)
for i := 0; i < 2; i++ {
go func(i int) {
defer wg.Done()
cmd.processRunner(i, &cfg, runners)
err := cmd.processRunner(i, &cfg, runners)
assert.NoError(t, err)
}(i)
}
......@@ -103,7 +104,7 @@ func TestProcessRunner_BuildLimit(t *testing.T) {
time.Sleep(10 * time.Millisecond)
}
err := cmd.processRunner(6, &cfg, runners)
err := cmd.processRunner(3, &cfg, runners)
assert.EqualError(t, err, "failed to request job, runner limit met")
// Wait for all builds to finish.
......
......@@ -332,7 +332,10 @@ func (s *RegisterCommand) Execute(context *cli.Context) {
s.askExecutor()
s.askExecutorOptions()
s.addRunner(&s.RunnerConfig)
s.saveConfig()
err = s.saveConfig()
if err != nil {
logrus.Panicln(err)
}
logrus.Printf("Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!")
}
......
......@@ -671,7 +671,10 @@ func (c *Config) SaveConfig(configFile string) error {
}
// create directory to store configuration
os.MkdirAll(filepath.Dir(configFile), 0700)
err := os.MkdirAll(filepath.Dir(configFile), 0700)
if err != nil {
return err
}
// write config file
if err := ioutil.WriteFile(configFile, newConfig.Bytes(), 0600); err != nil {
......
......@@ -26,9 +26,7 @@ const (
func (s *ShellConfiguration) GetCommandWithArguments() []string {
parts := []string{s.Command}
for _, arg := range s.Arguments {
parts = append(parts, arg)
}
parts = append(parts, s.Arguments...)
return parts
}
......
......@@ -1123,7 +1123,8 @@ func getAuthConfigTestExecutor(t *testing.T, precreateConfigFile bool) executor
if precreateConfigFile {
dockerConfigFile := path.Join(tempHomeDir, ".dockercfg")
ioutil.WriteFile(dockerConfigFile, []byte(testFileAuthConfigs), 0600)
err = ioutil.WriteFile(dockerConfigFile, []byte(testFileAuthConfigs), 0600)
require.NoError(t, err)
docker_helpers.HomeDirectory = tempHomeDir
} else {
docker_helpers.HomeDirectory = ""
......
......@@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/assert"
"gitlab.com/gitlab-org/gitlab-runner/common"
"gitlab.com/gitlab-org/gitlab-runner/helpers/docker"
docker_helpers "gitlab.com/gitlab-org/gitlab-runner/helpers/docker"
)
var machineDefaultConfig = &common.RunnerConfig{
......@@ -315,7 +315,8 @@ func TestMachineCreationAndRemoval(t *testing.T) {
assert.NoError(t, <-errCh)
assert.Equal(t, machineStateUsed, d3.State)
p.remove(d.Name)
err := p.remove(d.Name)
assert.NoError(t, err)
assert.Equal(t, machineStateRemoving, d.State)
}
......@@ -435,11 +436,13 @@ func TestMachineLimitMax(t *testing.T) {
config.Limit = 8
d, err = p.Acquire(config)
assert.NoError(t, err)
p.Release(config, d)
assertIdleMachines(t, p, 8, "it should upscale to 8 nodes")
config.Limit = 2
d, err = p.Acquire(config)
assert.NoError(t, err)
p.Release(config, d)
assertIdleMachines(t, p, 2, "it should downscale to 2 nodes")
}
......
......@@ -45,9 +45,9 @@ func (f *fakeRemoteExecutor) Execute(method string, url *url.URL, config *restcl
func TestExec(t *testing.T) {
version, codec := testVersionAndCodec()
tests := []struct {
name, version, podPath, execPath, container string
pod *api.Pod
tty, execErr bool
name, version, podPath, execPath string
pod *api.Pod
tty, execErr bool
}{
{
name: "pod exec",
......
......@@ -47,7 +47,8 @@ func TestGzipArchiveOfMultipleFiles(t *testing.T) {
defer file.Close()
defer os.Remove(file.Name())
file.Write(testZipFileContent)
_, err = file.Write(testZipFileContent)
require.NoError(t, err)
file.Close()
var buffer bytes.Buffer
......@@ -105,6 +106,7 @@ func TestGzipArchivesExistingAndNonExistingFile(t *testing.T) {
var buffer bytes.Buffer
err = CreateGzipArchive(&buffer, []string{filePath, "non-existing-file"})
require.NoError(t, err)
// we have only one stream
testGzipStreams(t, &buffer, [][]byte{testGzipFileContent})
......
......@@ -104,7 +104,10 @@ func CreateZipArchive(w io.Writer, fileNames []string) error {
func CreateZipFile(fileName string, fileNames []string) error {
// create directories to store archive
os.MkdirAll(filepath.Dir(fileName), 0700)
err := os.MkdirAll(filepath.Dir(fileName), 0700)
if err != nil {
return err
}
tempFile, err := ioutil.TempFile(filepath.Dir(fileName), "archive_")
if err != nil {
......
......@@ -31,7 +31,7 @@ func createZipUIDGidField(w io.Writer, fi os.FileInfo) (err error) {
if err == nil {
err = binary.Write(w, binary.LittleEndian, &ugField)
}
return nil
return err
}
func processZipUIDGidField(data []byte, file *zip.FileHeader) error {
......
......@@ -61,7 +61,10 @@ func extractZipFileEntry(file *zip.File) (err error) {
func extractZipFile(file *zip.File) (err error) {
// Create all parents to extract the file
os.MkdirAll(filepath.Dir(file.Name), 0777)
err = os.MkdirAll(filepath.Dir(file.Name), 0777)
if err != nil {
return err
}
switch file.Mode() & os.ModeType {
case os.ModeDir:
......@@ -72,7 +75,7 @@ func extractZipFile(file *zip.File) (err error) {
case os.ModeNamedPipe, os.ModeSocket, os.ModeDevice:
// Ignore the files that of these types
logrus.Warningln("File ignored: %q", file.Name)
logrus.Warningf("File ignored: %q", file.Name)
default:
err = extractZipFileEntry(file)
......
......@@ -16,13 +16,15 @@ import (
func createDefaultArchive(t *testing.T, archive *zip.Writer) {
testFile, err := archive.Create("temporary_file.txt")
require.NoError(t, err)
io.WriteString(testFile, "test file")
_, err = io.WriteString(testFile, "test file")
require.NoError(t, err)
}
func createArchiveWithGitPath(t *testing.T, archive *zip.Writer) {
testGitFile, err := archive.Create(".git/test_file")
require.NoError(t, err)
io.WriteString(testGitFile, "test git file")
_, err = io.WriteString(testGitFile, "test git file")
require.NoError(t, err)
}
func testOnArchive(t *testing.T, createArchive func(t *testing.T, archive *zip.Writer), testCase func(t *testing.T, fileName string)) {
......
......@@ -17,6 +17,7 @@ func TestCertificate(t *testing.T) {
gen := X509Generator{}
cert, pem, err := gen.Generate("127.0.0.1")
require.NoError(t, err)
tlsConfig := tls.Config{
Certificates: []tls.Certificate{cert},
......
......@@ -10,9 +10,8 @@ import (
func TestGetInfo(t *testing.T) {
tests := []struct {
osType string
expectedHelperImageType interface{}
expectedError interface{}
osType string
expectedError error
}{
{osType: OSTypeLinux, expectedError: nil},
{osType: OSTypeWindows, expectedError: ErrUnsupportedOSVersion},
......
......@@ -152,7 +152,7 @@ func (b *CmdWriter) IfCmd(cmd string, arguments ...string) {
func (b *CmdWriter) IfCmdWithOutput(cmd string, arguments ...string) {
cmdline := b.buildCommand(cmd, arguments...)
b.Line(fmt.Sprintf("%s", cmdline))
b.Line(cmdline)
errCheck := "IF !errorlevel! EQU 0 ("
b.Line(b.updateErrLevelCheck(errCheck))
b.Indent()
......
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