From 3a88a98cdd5f91ad50ac439789f05a2c6d66ee16 Mon Sep 17 00:00:00 2001 From: Azuki-bar <42642269+Azuki-bar@users.noreply.github.com> Date: Thu, 9 Nov 2023 22:25:14 +0900 Subject: [PATCH 1/4] add linter --- .github/workflows/test-go.yaml | 24 ++++++++++++++++++++++++ .golangci.yaml | 16 ++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 .github/workflows/test-go.yaml create mode 100644 .golangci.yaml diff --git a/.github/workflows/test-go.yaml b/.github/workflows/test-go.yaml new file mode 100644 index 00000000..77faaa2f --- /dev/null +++ b/.github/workflows/test-go.yaml @@ -0,0 +1,24 @@ +name: Lint and Test golang + + +on: + pull_request: + push: + branches: + - main + - develop + + jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: '1.21' + cache: false + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.54 diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 00000000..e7189369 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,16 @@ +linters: + disable-all: true + enable: + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - typecheck + - unused + - gosec + - godot + - forbidigo + - gocritic + - revive + - gofmt From 79eb9c2c71d81e6e656d491562321c8513fb60ce Mon Sep 17 00:00:00 2001 From: Azuki-bar <42642269+Azuki-bar@users.noreply.github.com> Date: Thu, 9 Nov 2023 22:26:17 +0900 Subject: [PATCH 2/4] fiix --- .github/workflows/test-go.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test-go.yaml b/.github/workflows/test-go.yaml index 77faaa2f..a0ca101e 100644 --- a/.github/workflows/test-go.yaml +++ b/.github/workflows/test-go.yaml @@ -1,6 +1,5 @@ name: Lint and Test golang - on: pull_request: push: @@ -8,7 +7,7 @@ on: - main - develop - jobs: +jobs: golangci: name: lint runs-on: ubuntu-latest From 0c3b04c33882f7022ddcace54617179b7d61ed7a Mon Sep 17 00:00:00 2001 From: Azuki-bar <42642269+Azuki-bar@users.noreply.github.com> Date: Sun, 12 Nov 2023 23:14:20 +0900 Subject: [PATCH 3/4] add test --- .github/workflows/test-go.yaml | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-go.yaml b/.github/workflows/test-go.yaml index a0ca101e..2e6509ff 100644 --- a/.github/workflows/test-go.yaml +++ b/.github/workflows/test-go.yaml @@ -8,16 +8,30 @@ on: - develop jobs: - golangci: - name: lint + # golangci: + # name: lint + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v4 + # - uses: actions/setup-go@v4 + # with: + # go-version: '1.21' + # cache: false + # - name: golangci-lint + # uses: golangci/golangci-lint-action@v3 + # with: + # version: v1.54 + test: + name: Test runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: go-version: '1.21' - cache: false - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 - with: - version: v1.54 + - name: Build State manager + run: | + go build -race backend/state-manager/cmd/main.go + - name: Test + run: | + go test -v ./... From ce7a38135e79953ce89f056689bbded8f036b535 Mon Sep 17 00:00:00 2001 From: Azuki-bar <42642269+Azuki-bar@users.noreply.github.com> Date: Mon, 13 Nov 2023 01:00:21 +0900 Subject: [PATCH 4/4] fix test --- .github/workflows/test-go.yaml | 7 ++++--- backend/state-manager/pkg/db/db_test.go | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test-go.yaml b/.github/workflows/test-go.yaml index 2e6509ff..d9f92019 100644 --- a/.github/workflows/test-go.yaml +++ b/.github/workflows/test-go.yaml @@ -29,9 +29,10 @@ jobs: - uses: actions/setup-go@v4 with: go-version: '1.21' - - name: Build State manager - run: | - go build -race backend/state-manager/cmd/main.go - name: Test run: | go test -v ./... + - name: Build State manager + run: | + go build backend/state-manager/cmd/main.go + diff --git a/backend/state-manager/pkg/db/db_test.go b/backend/state-manager/pkg/db/db_test.go index 59183621..16750b98 100644 --- a/backend/state-manager/pkg/db/db_test.go +++ b/backend/state-manager/pkg/db/db_test.go @@ -16,14 +16,14 @@ func Test_ConnectDB(t *testing.T) { Open() } -func Test_SetPoint(t *testing.T) { +func Test_UpdatePoint(t *testing.T) { defer C() err := godotenv.Load("../../cmd/.env") if err != nil { panic(err) } Open() - SetPoint(&statev1.PointAndState{ + UpdatePoint(&statev1.PointAndState{ Id: "test", State: statev1.PointStateEnum_POINT_STATE_REVERSE, }) @@ -36,14 +36,14 @@ func Test_SetPoint(t *testing.T) { } } -func Test_SetStop(t *testing.T) { +func Test_UpdateStop(t *testing.T) { defer C() err := godotenv.Load("../../cmd/.env") if err != nil { panic(err) } Open() - SetStop(&statev1.StopAndState{ + UpdateStop(&statev1.StopAndState{ Id: "test", State: statev1.StopStateEnum_STOP_STATE_GO, }) @@ -63,11 +63,11 @@ func Test_GetPoints(t *testing.T) { panic(err) } Open() - SetPoint(&statev1.PointAndState{ + UpdatePoint(&statev1.PointAndState{ Id: "test", State: statev1.PointStateEnum_POINT_STATE_REVERSE, }) - SetPoint(&statev1.PointAndState{ + UpdatePoint(&statev1.PointAndState{ Id: "test2", State: statev1.PointStateEnum_POINT_STATE_NORMAL, }) @@ -84,11 +84,11 @@ func Test_GetStops(t *testing.T) { panic(err) } Open() - SetStop(&statev1.StopAndState{ + UpdateStop(&statev1.StopAndState{ Id: "test", State: statev1.StopStateEnum_STOP_STATE_GO, }) - SetStop(&statev1.StopAndState{ + UpdateStop(&statev1.StopAndState{ Id: "test2", State: statev1.StopStateEnum_STOP_STATE_STOP, }) @@ -105,14 +105,14 @@ func Test_GetBlocks(t *testing.T) { panic(err) } Open() - err = SetBlock(&statev1.BlockState{ + err = UpdateBlock(&statev1.BlockState{ BlockId: "test", State: statev1.BlockStateEnum_BLOCK_STATE_OPEN, }) if err != nil { t.Fatal("error") } - err = SetBlock(&statev1.BlockState{ + err = UpdateBlock(&statev1.BlockState{ BlockId: "test2", State: statev1.BlockStateEnum_BLOCK_STATE_CLOSE, })