Skip to content

Commit

Permalink
Merge pull request #66 from peng225/enable-lint
Browse files Browse the repository at this point in the history
enable lint and fix lint errors
  • Loading branch information
peng225 authored Oct 25, 2023
2 parents ce1a4da + 6dbceba commit 59e376e
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 12 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Main

on:
push:
branches: [ "main" ]
paths-ignore:
- '**.md'
pull_request:
branches: [ "main" ]
paths-ignore:
- '**.md'

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.20"

- name: Lint
run: make lint
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ MINIO_CERTDIR := $(shell git rev-parse --show-toplevel)/test/certs
CERTGEN_VERSION := v1.2.1
CERTGEN := $(BINDIR)/certgen-$(CERTGEN_VERSION)

GOLANGCI_LINT_VERSION := v1.55.1
GOLANGCI_LINT := $(BINDIR)/golangci-lint-$(GOLANGCI_LINT_VERSION)

S3_ENDPOINT ?= http://localhost:9000
CERT_CONFIG ?= ""

Expand All @@ -31,6 +34,14 @@ $(MINIO_CERTDIR):
image:
docker build . --file Dockerfile --tag $(IMAGE_NAME)

$(GOLANGCI_LINT): | $(BINDIR)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b . $(GOLANGCI_LINT_VERSION)
mv golangci-lint $(GOLANGCI_LINT)

.PHONY: lint
lint: | $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run

.PHONY: test
test: $(OVAL)
go test -v ./...
Expand Down
2 changes: 1 addition & 1 deletion argparser/ope_ratio.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func ParseOpeRatio(opeRatioStr string) ([]float64, error) {
ratio[i] = float64(intV)
sum += ratio[i]
}
for i, _ := range ratio {
for i := range ratio {
ratio[i] /= sum
}
return ratio, nil
Expand Down
5 changes: 4 additions & 1 deletion cmd/follower.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@ func init() {
followerCmd.Flags().IntVar(&followerPort, "follower_port", invalidPortNumber, "TCP port number to which the follower listens.")
followerCmd.Flags().StringVar(&caCertFileName, "cacert", "", "File name of CA certificate.")

followerCmd.MarkFlagRequired("follower_port")
err := followerCmd.MarkFlagRequired("follower_port")
if err != nil {
log.Fatal(err)
}
}
9 changes: 7 additions & 2 deletions pattern/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ func generateDataUnit(unitCount, workerID int, bucketName string, obj *object.Ob
unixTime := dt.UnixMicro()
binary.LittleEndian.PutUint32(numBinBuf[8:], uint32(workerID))
binary.LittleEndian.PutUint64(numBinBuf[12:], uint64(unixTime))
writer.Write(numBinBuf)
n, err = writer.Write(numBinBuf)
if err != nil {
return err
}
if n != dataUnitHeaderSizeWithoutBucketAndKey {
return fmt.Errorf("the data unit header without bucket name and key was not written correctly. n = %d", n)
}

unitBodyStartPos := object.MaxBucketNameLength + object.MaxKeyLength + dataUnitHeaderSizeWithoutBucketAndKey
tmpData := make([]byte, 4)
Expand Down Expand Up @@ -186,7 +192,6 @@ func validDataUnit(unitCount, workerID int, expectedBucketName string, obj *obje
}

actualWorkerID := int(binary.LittleEndian.Uint32(data[current : current+4]))
current = current + 4
if workerID != actualWorkerID {
errMsg += fmt.Sprintf("- WorkerID is wrong. (expected = \"%d\", actual = \"%d\")\n",
workerID, actualWorkerID)
Expand Down
7 changes: 4 additions & 3 deletions pattern/pattern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func (suite *PatternSuite) TestGenerateDataUnitSuccess() {
workerID := 100

suite.Equal(nil, generateDataUnit(4, workerID, testBucketName, obj, suite.f))
suite.f.Seek(0, 0)
_, err := suite.f.Seek(0, 0)
suite.NoError(err)
data, err := io.ReadAll(suite.f)
suite.NoError(err)
suite.Equal(dataUnitSize, len(data))
Expand Down Expand Up @@ -129,7 +130,7 @@ func (suite *PatternSuite) TestGenerateLongBucketName() {

// 1st data unit
// bucketName
suite.Equal(append([]byte(testLongBucketName[:object.MaxBucketNameLength])),
suite.Equal([]byte(testLongBucketName[:object.MaxBucketNameLength]),
data[0:object.MaxBucketNameLength])
current := object.MaxBucketNameLength
// keyName
Expand All @@ -147,7 +148,7 @@ func (suite *PatternSuite) TestGenerateLongBucketName() {
// 2nd data unit
current = dataUnitSize
// bucketName
suite.Equal(append([]byte(testLongBucketName[:object.MaxBucketNameLength])),
suite.Equal([]byte(testLongBucketName[:object.MaxBucketNameLength]),
data[current:current+object.MaxBucketNameLength])
current += object.MaxBucketNameLength
// keyName
Expand Down
11 changes: 6 additions & 5 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ func loadSavedContext(loadFileName string) *ExecutionContext {
log.Fatal(err)
}
ec := &ExecutionContext{}
json.Unmarshal(savedContext, ec)
err = json.Unmarshal(savedContext, ec)
if err != nil {
log.Fatal(err)
}
return ec
}

Expand Down Expand Up @@ -123,7 +126,6 @@ func (r *Runner) init() {

if r.loadFileName == "" {
r.execContext.Workers = make([]Worker, r.execContext.NumWorker)
rand.Seed(time.Now().UnixNano())
startID := rand.Intn(maxWorkerID)
r.execContext.StartWorkerID = startID
for i := range r.execContext.Workers {
Expand All @@ -144,13 +146,13 @@ func (r *Runner) init() {
r.execContext.Workers[i].ShowInfo()
}
} else {
for i, _ := range r.execContext.Workers {
for i := range r.execContext.Workers {
r.execContext.Workers[i].id = (r.execContext.StartWorkerID + i) % maxWorkerID
r.execContext.Workers[i].minSize = r.execContext.MinSize
r.execContext.Workers[i].maxSize = r.execContext.MaxSize
r.execContext.Workers[i].client = r.client
r.execContext.Workers[i].st = &r.st
for j, _ := range r.execContext.Workers[i].BucketsWithObject {
for j := range r.execContext.Workers[i].BucketsWithObject {
r.execContext.Workers[i].BucketsWithObject[j].ObjectMeta.TidyUp()
}
r.execContext.Workers[i].ShowInfo()
Expand Down Expand Up @@ -227,7 +229,6 @@ const (
)

func (r *Runner) selectOperation() Operation {
rand.Seed(time.Now().UnixNano())
randVal := rand.Float64()
if randVal < r.opeRatio[0] {
return Put
Expand Down

0 comments on commit 59e376e

Please sign in to comment.