Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue #984] fix lint issues, update golangci-lint and action versions #993

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v2
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.23.1"
- name: Install pcap
run: sudo apt-get install libpcap-dev
- name: Run coverage
run: make test
- name: Codecov
uses: codecov/codecov-action@v3.1.0
uses: codecov/codecov-action@v4
with:
files: ./coverage_tdengine.out,./coverage.out
name: codecov-shifu
fail_ci_if_error: true
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }} # required
verbose: true
6 changes: 3 additions & 3 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v5
with:
go-version: 1.23.1
- name: Install pcap
run: sudo apt-get install libpcap-dev
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --timeout=5m
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
generate_changelog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.23.1"
- name: set version
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ buildx-build-image-deviceshifu: \

buildx-build-image-telemetry-service:
docker buildx build --platform=linux/$(shell go env GOARCH) -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.telemetryservice\
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" --build-arg GODEBUG=x509negativeserial=1 ${PROJECT_ROOT} \
-t edgehub/telemetryservice:${IMAGE_VERSION} --load

.PHONY: download-demo-files
Expand Down
31 changes: 16 additions & 15 deletions azure-pipelines/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -383,22 +383,29 @@ stages:
-e TARGET_SQLSERVER_SERVER_ADDRESS=localhost:1433 \
--name mockclient edgehub/mockclient:$(tag)
displayName: build mockClient
- script: |
docker run -itd --network host --name nginx nginx:1.21
displayName: docker run nginx
- script: |
set -e
docker run -itd --network host --name sqlserver -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=YourStrong@Passw0rd" \
--health-cmd="/opt/mssql-tools18/bin/sqlcmd -U sa -C -P YourStrong@Passw0rd -Q 'select name from sys.databases'" --health-interval=5s --health-timeout=5s --health-retries=20 \
mcr.microsoft.com/mssql/server:2022-latest
bash $(System.DefaultWorkingDirectory)/examples/telemetryservice/sqlserver/checkoutput.sh
docker rm -f sqlserver
displayName: docker run sqlserver and checkoutput
- script: |
docker buildx build --platform=linux/amd64 \
-f $(System.DefaultWorkingDirectory)/examples/telemetryservice/mockserver/Dockerfile.mockserver \
--build-arg PROJECT_ROOT="$(System.DefaultWorkingDirectory)" $(System.DefaultWorkingDirectory) \
-t edgehub/mockserver:$(tag) --load
displayName: build and run mockServer
- script: |
docker run -itd --network host --name nginx nginx:1.21
displayName: docker run nginx
displayName: build mockServer
- script: |
set -e
docker run -itd --network host --name mosquitto eclipse-mosquitto:2.0.15
docker run -itd --network host --name mockserver edgehub/mockserver:$(tag)
bash $(System.DefaultWorkingDirectory)/examples/telemetryservice/mqtt/checkoutput.sh
docker stop mosquitto mockserver
docker rm mosquitto mockserver
docker rm -f mosquitto mockserver
displayName: e2e_test_mqtt and checkoutput
- script: |
set -e
Expand All @@ -411,30 +418,24 @@ stages:
-e MQTT_PASSWORD=mosquitto \
edgehub/mockserver:$(tag)
bash $(System.DefaultWorkingDirectory)/examples/telemetryservice/mqtt/checkoutput_auth.sh
docker stop mosquitto mockserver
docker rm mosquitto mockserver
docker rm -f mosquitto mockserver
displayName: e2e_test_mqtt_with_auth and checkoutput
- script: |
set -e
docker run -itd --network host --name tdengine \
-v $(System.DefaultWorkingDirectory)/examples/telemetryservice/tdengine/init.sql:/root/init.sql \
tdengine/tdengine:3.0.1.4
bash $(System.DefaultWorkingDirectory)/examples/telemetryservice/tdengine/checkoutput.sh
docker rm -f tdengine
displayName: docker run tdengine and checkoutput
- script: |
set -e
docker run -itd --network host --name mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=yes \
--health-cmd='mysqladmin ping -h localhost -uroot' --health-interval=5s --health-timeout=5s --health-retries=20 \
mysql:8.1.0
bash $(System.DefaultWorkingDirectory)/examples/telemetryservice/mysql/checkoutput.sh
docker rm -f mysql
displayName: docker run mysql and checkoutput
- script: |
set -e
docker run -d -p 1433:1433 --name sqlserver -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=YourStrong@Passw0rd" \
--health-cmd="/opt/mssql-tools18/bin/sqlcmd -U sa -C -P YourStrong@Passw0rd -Q 'select name from sys.databases'" --health-interval=5s --health-timeout=5s --health-retries=20 \
mcr.microsoft.com/mssql/server:2022-latest
bash $(System.DefaultWorkingDirectory)/examples/telemetryservice/sqlserver/checkoutput.sh
displayName: docker run sqlserver and checkoutput

- stage: docker_build_muiltiarch_and_push
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'), not(startsWith(variables['Build.SourceBranchName'],'release')))
Expand Down
4 changes: 2 additions & 2 deletions cmd/httpstub/powershellstub/powershellstub.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ func httpFileServeHandler(resp http.ResponseWriter, req *http.Request) {
} else if errors.Is(err, os.ErrNotExist) {
logger.Errorf("File does not exist: %v", fileLocationString)
resp.WriteHeader(http.StatusNotFound)
fmt.Fprintf(resp, "File does not exist: "+fileLocationString+"\n")
fmt.Fprint(resp, "File does not exist: "+fileLocationString+"\n")
} else {
logger.Errorf("File may not exist: %v", fileLocationString)
resp.WriteHeader(http.StatusNotFound)
fmt.Fprintf(resp, "File may not exist: "+fileLocationString+"\n")
fmt.Fprint(resp, "File may not exist: "+fileLocationString+"\n")
}
}

Expand Down
3 changes: 3 additions & 0 deletions dockerfiles/Dockerfile.telemetryservice
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ RUN go mod download
# Build the Go app
ARG TARGETOS
ARG TARGETARCH
ARG GODEBUG

ENV GODEBUG=$GODEBUG

RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -o /output/telemetryservice cmd/telemetryservice/main.go

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ COPY go.mod go.mod
COPY go.sum go.sum
COPY pkg/logger pkg/logger

RUN go mod download -x
RUN go mod download

RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a \
-o /output/mockclient \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ COPY go.mod go.mod
COPY go.sum go.sum
COPY pkg/logger pkg/logger

RUN go mod download -x
RUN go mod download

RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a \
-o /output/mockserver \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestNewDeviceShifuConfig(t *testing.T) {

mockdsc, err := NewDeviceShifuConfig(MockDeviceConfigFolder)
if err != nil {
t.Errorf(err.Error())
t.Errorf("Error: %v", err)
}

eq := reflect.DeepEqual(DriverProperties, mockdsc.DriverProperties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestNewDeviceShifuConfig(t *testing.T) {

mockdsc, err := deviceshifubase.NewDeviceShifuConfig(MockDeviceConfigFolder)
if err != nil {
t.Errorf(err.Error())
t.Errorf("Error: %v", err)
}

eq := reflect.DeepEqual(DriverProperties, mockdsc.DriverProperties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestNewDeviceShifuConfig(t *testing.T) {

mockdsc, err := deviceshifubase.NewDeviceShifuConfig(MockDeviceConfigFolder)
if err != nil {
t.Errorf(err.Error())
t.Errorf("Error: %v", err)
}

eq := reflect.DeepEqual(DriverProperties, mockdsc.DriverProperties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestNewDeviceShifuConfig(t *testing.T) {

mockdsc, err := deviceshifubase.NewDeviceShifuConfig(MockDeviceConfigFolder)
if err != nil {
t.Errorf(err.Error())
t.Errorf("Error: %v", err)
}

mockintructions := CreateOPCUAInstructions(&mockdsc.Instructions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestNewDeviceShifuConfig(t *testing.T) {

mockdsc, err := deviceshifubase.NewDeviceShifuConfig(MockDeviceConfigFolder)
if err != nil {
t.Errorf(err.Error())
t.Errorf("Error: %v", err)
}

eq := reflect.DeepEqual(DriverProperties, mockdsc.DriverProperties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestNewDeviceShifuConfig(t *testing.T) {

mockdsc, err := deviceshifubase.NewDeviceShifuConfig(MockDeviceConfigFolder)
if err != nil {
t.Errorf(err.Error())
t.Errorf("Error: %v", err)
}

eq := reflect.DeepEqual(DriverProperties, mockdsc.DriverProperties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func instructionHandler(functionName string) http.HandlerFunc {
ypos := strconv.Itoa(rand.Intn(yrange))
fmt.Fprintf(w, "xpos: %v, ypos: %v", xpos, ypos)
case "get_status":
fmt.Fprintf(w, mockdevice.StatusSetList[(rand.Intn(len(mockdevice.StatusSetList)))])
fmt.Fprint(w, mockdevice.StatusSetList[(rand.Intn(len(mockdevice.StatusSetList)))])
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ func instructionHandler(functionName string) http.HandlerFunc {
for i := 0; i < 8; i++ {
for j := 0; j < 12; j++ {
num := fmt.Sprintf("%.2f", rand.Float32()*readingRange)
fmt.Fprintf(w, num+" ")
fmt.Fprint(w, num+" ")
}
fmt.Fprintf(w, "\n")
fmt.Fprint(w, "\n")
}
case "get_status":
fmt.Fprintf(w, mockdevice.StatusSetList[(rand.Intn(len(mockdevice.StatusSetList)))])
fmt.Fprint(w, mockdevice.StatusSetList[(rand.Intn(len(mockdevice.StatusSetList)))])
}
}
}
6 changes: 3 additions & 3 deletions pkg/deviceshifu/mockdevice/mockdevice-plc/mockdevice-plc.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func instructionHandler(functionName string) http.HandlerFunc {
}

w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, dataStorage[rootaddress])
fmt.Fprint(w, dataStorage[rootaddress])
case "sendsinglebit":
query := r.URL.Query()
rootaddress := query.Get(rootAddress)
Expand Down Expand Up @@ -83,11 +83,11 @@ func instructionHandler(functionName string) http.HandlerFunc {
dataStorage[rootaddress] = string(responseValue)
logger.Infof("%v", responseValue)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, dataStorage[rootaddress])
fmt.Fprint(w, dataStorage[rootaddress])
case "get_status":
rand.Seed(time.Now().UnixNano())
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, mockdevice.StatusSetList[(rand.Intn(len(mockdevice.StatusSetList)))])
fmt.Fprint(w, mockdevice.StatusSetList[(rand.Intn(len(mockdevice.StatusSetList)))])
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func instructionHandler(functionName string) http.HandlerFunc {
zpos := strconv.Itoa(rand.Intn(zrange))
fmt.Fprintf(w, "xpos: %v, ypos: %v, zpos: %v", xpos, ypos, zpos)
case "get_status":
fmt.Fprintf(w, mockdevice.StatusSetList[(rand.Intn(len(mockdevice.StatusSetList)))])
fmt.Fprint(w, mockdevice.StatusSetList[(rand.Intn(len(mockdevice.StatusSetList)))])
}
}
}
2 changes: 1 addition & 1 deletion pkg/deviceshifu/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestCopyHeader(t *testing.T) {
url := "http://www.example.com"
resp, err := http.Get(url)
if err != nil {
t.Errorf(err.Error())
t.Errorf("Error: %v", err)
}
responseHeader := resp.Header
responseHeader2 := http.Header{}
Expand Down
Loading