Skip to content

Commit

Permalink
Fixed lint issues (#1739)
Browse files Browse the repository at this point in the history
  • Loading branch information
simster7 authored and sarabala1979 committed Nov 14, 2019
1 parent 63e12d0 commit e66fa32
Show file tree
Hide file tree
Showing 19 changed files with 239 additions and 265 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ endif
.PHONY: lint
lint:
ifdef GOLANGCI_EXISTS
golangci-lint run --config golangci.yml
golangci-lint run --fix --verbose --config golangci.yml
else
# Remove gometalinter after a migration time.
gometalinter --config gometalinter.json ./...
Expand Down
15 changes: 2 additions & 13 deletions golangci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
run:
deadline: 8m
tests: false
deadline: 30m
skip-files:
- "pkg/client"
deadline: 10m
output:
format: colored-line-number
print-issued-lines: true
print-linter-name: true
linters:
enable:
- gofmt
- goimports
- unconvert
- misspell
fast: false
- "vendor/"
29 changes: 14 additions & 15 deletions pkg/apis/workflow/v1alpha1/item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,28 @@ import (

func TestItem(t *testing.T) {
testData := map[string]Type{
"0": Number,
"3.141": Number,
"true": Bool,
"\"hello\"": String,
"{\"val\":\"123\"}": Map,
"[\"1\",\"2\",\"3\",\"4\",\"5\"]" : List,
"0": Number,
"3.141": Number,
"true": Bool,
"\"hello\"": String,
"{\"val\":\"123\"}": Map,
"[\"1\",\"2\",\"3\",\"4\",\"5\"]": List,
}

for data, expectedType := range testData {
var itm Item
err := json.Unmarshal([]byte(data), &itm)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, itm.Type, expectedType)
jsonBytes, err := json.Marshal(itm)
assert.Equal(t, string(data), string(jsonBytes))
assert.NoError(t, err)
assert.Equal(t, data, string(jsonBytes))
if itm.Type == String {
assert.Equal(t, string(data), fmt.Sprintf("\"%v\"", itm))
assert.Equal(t, string(data), fmt.Sprintf("\"%s\"", itm))
}else {
assert.Equal(t, string(data), fmt.Sprintf("%v", itm))
assert.Equal(t, string(data), fmt.Sprintf("%s", itm))
assert.Equal(t, data, fmt.Sprintf("\"%v\"", itm))
assert.Equal(t, data, fmt.Sprintf("\"%s\"", itm))
} else {
assert.Equal(t, data, fmt.Sprintf("%v", itm))
assert.Equal(t, data, fmt.Sprintf("%s", itm))
}
}
}


5 changes: 4 additions & 1 deletion test/e2e/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ spec:
assert.Equal(t, false, wf.Status.FinishedAt.IsZero())

deleteOptions := metav1.DeleteOptions{}
wfClient.Delete(workflowName, &deleteOptions)
err = wfClient.Delete(workflowName, &deleteOptions)
if err != nil {
log.Fatal(err)
}
}

func TestWaitCmd(t *testing.T) {
Expand Down
8 changes: 5 additions & 3 deletions test/e2e/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ spec:
if err != nil {
log.Fatal(err)
}
var allCompleted bool
allCompleted = true
allCompleted := true
for k, v := range wf.Status.Nodes {
if !v.Completed() {
fmt.Printf("Status of %s: %v\n", k, v.Phase)
Expand All @@ -89,7 +88,10 @@ spec:
}

deleteOptions := metav1.DeleteOptions{}
wfClient.Delete(workflowName, &deleteOptions)
err = wfClient.Delete(workflowName, &deleteOptions)
if err != nil {
log.Fatal(err)
}
}

func TestArgoWorkflows(t *testing.T) {
Expand Down
28 changes: 17 additions & 11 deletions util/archive/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,51 @@ func tempFile(dir, prefix, suffix string) (*os.File, error) {
if dir == "" {
dir = os.TempDir()
} else {
os.MkdirAll(dir, 0700)
err := os.MkdirAll(dir, 0700)
if err != nil {
return nil, err
}
}
randBytes := make([]byte, 16)
rand.Read(randBytes)
_, err := rand.Read(randBytes)
if err != nil {
return nil, err
}
filePath := filepath.Join(dir, prefix+hex.EncodeToString(randBytes)+suffix)
return os.Create(filePath)
}

func TestTarDirectory(t *testing.T) {
f, err := tempFile(os.TempDir()+"/argo-test", "dir-", ".tgz")
assert.Nil(t, err)
assert.NoError(t, err)
log.Infof("Taring to %s", f.Name())
w := bufio.NewWriter(f)

err = TarGzToWriter("../../test/e2e", w)
assert.Nil(t, err)
assert.NoError(t, err)

err = f.Close()
assert.Nil(t, err)
assert.NoError(t, err)
}

func TestTarFile(t *testing.T) {
data, err := tempFile(os.TempDir()+"/argo-test", "file-", "")
assert.Nil(t, err)
assert.NoError(t, err)
_, err = data.WriteString("hello world")
assert.Nil(t, err)
assert.NoError(t, err)
data.Close()

dataTarPath := data.Name() + ".tgz"
f, err := os.Create(dataTarPath)
assert.Nil(t, err)
assert.NoError(t, err)
log.Infof("Taring to %s", f.Name())
w := bufio.NewWriter(f)

err = TarGzToWriter(data.Name(), w)
assert.Nil(t, err)
assert.NoError(t, err)
err = os.Remove(data.Name())
assert.Nil(t, err)
assert.NoError(t, err)

err = f.Close()
assert.Nil(t, err)
assert.NoError(t, err)
}
6 changes: 3 additions & 3 deletions util/file/fileutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ func TestExistsInTar(t *testing.T) {
}
hdr := tar.Header{Name: f.name, Mode: int64(mode), Size: int64(len(f.body))}
err := writer.WriteHeader(&hdr)
assert.Nil(t, err)
assert.NoError(t, err)
_, err = writer.Write([]byte(f.body))
assert.Nil(t, err)
assert.NoError(t, err)
}
err := writer.Close()
assert.Nil(t, err)
assert.NoError(t, err)
return tar.NewReader(&buf)
}

Expand Down
16 changes: 9 additions & 7 deletions workflow/artifacts/artifactory/artifactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ func TestSaveAndLoad(t *testing.T) {

// create file to test save
lf, err := ioutil.TempFile("", LoadFileName)
assert.Nil(t, err)
assert.NoError(t, err)
defer os.Remove(lf.Name())
// load file with test content
content := []byte(fileContent)
_, err = lf.Write(content)
assert.Nil(t, err)
assert.NoError(t, err)
err = lf.Close()
assert.Nil(t, err)
assert.NoError(t, err)

// create file to test load
sf, err := ioutil.TempFile("", SaveFileName)
assert.Nil(t, err)
assert.NoError(t, err)
defer os.Remove(sf.Name())

artL := &wfv1.Artifact{}
Expand All @@ -49,10 +49,12 @@ func TestSaveAndLoad(t *testing.T) {
Username: Username,
Password: Password,
}
driver.Save(lf.Name(), artL)
driver.Load(artL, sf.Name())
err = driver.Save(lf.Name(), artL)
assert.NoError(t, err)
err = driver.Load(artL, sf.Name())
assert.NoError(t, err)

dat, err := ioutil.ReadFile(sf.Name())
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, fileContent, string(dat))
}
7 changes: 4 additions & 3 deletions workflow/artifacts/raw/raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ func TestLoad(t *testing.T) {

content := "time: " + string(time.Now().UnixNano())
lf, err := ioutil.TempFile("", LoadFileName)
assert.Nil(t, err)
assert.NoError(t, err)
defer os.Remove(lf.Name())

art := &wfv1.Artifact{}
art.Raw = &wfv1.RawArtifact{
Data: content,
}
driver := &raw.RawArtifactDriver{}
driver.Load(art, lf.Name())
err = driver.Load(art, lf.Name())
assert.NoError(t, err)

dat, err := ioutil.ReadFile(lf.Name())
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, content, string(dat))

}
8 changes: 4 additions & 4 deletions workflow/common/ancestry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ func TestGetTaskAncestryForGlobalArtifacts(t *testing.T) {
ctx := &testContext{
status: map[string]*wfv1.NodeStatus{
"task1": {
FinishedAt: v1.Time{time.Now().Add(1 * time.Minute)},
FinishedAt: v1.Time{Time: time.Now().Add(1 * time.Minute)},
},
"task2": {
FinishedAt: v1.Time{time.Now().Add(3 * time.Minute)},
FinishedAt: v1.Time{Time: time.Now().Add(3 * time.Minute)},
},
"task3": {
FinishedAt: v1.Time{time.Now().Add(2 * time.Minute)},
FinishedAt: v1.Time{Time: time.Now().Add(2 * time.Minute)},
},
"task4": {
FinishedAt: v1.Time{time.Now().Add(4 * time.Minute)},
FinishedAt: v1.Time{Time: time.Now().Add(4 * time.Minute)},
},
},
}
Expand Down
16 changes: 2 additions & 14 deletions workflow/controller/controller_test.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package controller

import (
"bytes"
"context"
"encoding/json"
"io"
"io/ioutil"
"k8s.io/client-go/util/workqueue"
"testing"
"time"

"sigs.k8s.io/yaml"
"github.com/stretchr/testify/assert"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/tools/cache"
"sigs.k8s.io/yaml"

wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
fakewfclientset "github.com/argoproj/argo/pkg/client/clientset/versioned/fake"
Expand Down Expand Up @@ -67,14 +63,6 @@ func newController() *WorkflowController {
}
}

func marshallBody(b interface{}) io.ReadCloser {
result, err := json.Marshal(b)
if err != nil {
panic(err)
}
return ioutil.NopCloser(bytes.NewReader(result))
}

func unmarshalWF(yamlStr string) *wfv1.Workflow {
var wf wfv1.Workflow
err := yaml.Unmarshal([]byte(yamlStr), &wf)
Expand All @@ -88,7 +76,7 @@ func unmarshalWF(yamlStr string) *wfv1.Workflow {
func makePodsRunning(t *testing.T, kubeclientset kubernetes.Interface, namespace string) {
podcs := kubeclientset.CoreV1().Pods(namespace)
pods, err := podcs.List(metav1.ListOptions{})
assert.Nil(t, err)
assert.NoError(t, err)
for _, pod := range pods.Items {
pod.Status.Phase = apiv1.PodRunning
_, _ = podcs.Update(&pod)
Expand Down
16 changes: 4 additions & 12 deletions workflow/controller/operator_persist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ func TestPersistWithoutLargeWfSupport(t *testing.T) {
wfcset := controller.wfclientset.ArgoprojV1alpha1().Workflows("")
wf := unmarshalWF(helloWorldWfPersist)
wf, err := wfcset.Create(wf)
if err != nil {

}
assert.NoError(t, err)
controller.wfDBctx = getMockDBCtx(sqldb.DBUpdateNoRowFoundError(nil, "test"), false, false)
woc := newWorkflowOperationCtx(wf, controller)
woc.operate()
Expand All @@ -66,9 +64,7 @@ func TestPersistErrorWithoutLargeWfSupport(t *testing.T) {
wfcset := controller.wfclientset.ArgoprojV1alpha1().Workflows("")
wf := unmarshalWF(helloWorldWfPersist)
wf, err := wfcset.Create(wf)
if err != nil {

}
assert.NoError(t, err)
var err1 error = errors.New("23324", "test")
controller.wfDBctx = getMockDBCtx(sqldb.DBUpdateNoRowFoundError(err1, "test"), false, false)
woc := newWorkflowOperationCtx(wf, controller)
Expand All @@ -84,9 +80,7 @@ func TestPersistWithLargeWfSupport(t *testing.T) {
wfcset := controller.wfclientset.ArgoprojV1alpha1().Workflows("")
wf := unmarshalWF(helloWorldWfPersist)
wf, err := wfcset.Create(wf)
if err != nil {

}
assert.NoError(t, err)
controller.wfDBctx = getMockDBCtx(sqldb.DBUpdateNoRowFoundError(nil, "test"), true, true)
woc := newWorkflowOperationCtx(wf, controller)
woc.operate()
Expand All @@ -100,9 +94,7 @@ func TestPersistErrorWithLargeWfSupport(t *testing.T) {
wfcset := controller.wfclientset.ArgoprojV1alpha1().Workflows("")
wf := unmarshalWF(helloWorldWfPersist)
wf, err := wfcset.Create(wf)
if err != nil {

}
assert.NoError(t, err)
var err1 error = errors.New("23324", "test")
controller.wfDBctx = getMockDBCtx(sqldb.DBUpdateNoRowFoundError(err1, "test"), true, false)
woc := newWorkflowOperationCtx(wf, controller)
Expand Down
Loading

0 comments on commit e66fa32

Please sign in to comment.