mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 05:19:39 +02:00
chore(ci): run lint and test on all pkgs [EE-6201] (#10481)
This commit is contained in:
parent
2e15cad048
commit
82951093b5
13 changed files with 35 additions and 66 deletions
3
.github/workflows/lint.yml
vendored
3
.github/workflows/lint.yml
vendored
|
@ -45,6 +45,5 @@ jobs:
|
||||||
- name: GolangCI-Lint
|
- name: GolangCI-Lint
|
||||||
uses: golangci/golangci-lint-action@v3
|
uses: golangci/golangci-lint-action@v3
|
||||||
with:
|
with:
|
||||||
version: v1.54.1
|
version: v1.55.2
|
||||||
working-directory: api
|
|
||||||
args: --timeout=10m -c .golangci.yaml
|
args: --timeout=10m -c .golangci.yaml
|
||||||
|
|
8
Makefile
8
Makefile
|
@ -7,7 +7,7 @@ ARCH=$(shell go env GOARCH)
|
||||||
# build target, can be one of "production", "testing", "development"
|
# build target, can be one of "production", "testing", "development"
|
||||||
ENV=development
|
ENV=development
|
||||||
WEBPACK_CONFIG=webpack/webpack.$(ENV).js
|
WEBPACK_CONFIG=webpack/webpack.$(ENV).js
|
||||||
TAG=latest
|
TAG=local
|
||||||
|
|
||||||
SWAG=go run github.com/swaggo/swag/cmd/swag@v1.8.11
|
SWAG=go run github.com/swaggo/swag/cmd/swag@v1.8.11
|
||||||
GOTESTSUM=go run gotest.tools/gotestsum@latest
|
GOTESTSUM=go run gotest.tools/gotestsum@latest
|
||||||
|
@ -68,7 +68,7 @@ test-client: ## Run client tests
|
||||||
yarn test $(ARGS)
|
yarn test $(ARGS)
|
||||||
|
|
||||||
test-server: ## Run server tests
|
test-server: ## Run server tests
|
||||||
cd api && $(GOTESTSUM) --format pkgname-and-test-fails --format-hide-empty-pkg --hide-summary skipped -- -cover ./...
|
$(GOTESTSUM) --format pkgname-and-test-fails --format-hide-empty-pkg --hide-summary skipped -- -cover ./...
|
||||||
|
|
||||||
##@ Dev
|
##@ Dev
|
||||||
.PHONY: dev dev-client dev-server
|
.PHONY: dev dev-client dev-server
|
||||||
|
@ -92,7 +92,7 @@ format-client: ## Format client code
|
||||||
yarn format
|
yarn format
|
||||||
|
|
||||||
format-server: ## Format server code
|
format-server: ## Format server code
|
||||||
cd api && go fmt ./...
|
go fmt ./...
|
||||||
|
|
||||||
##@ Lint
|
##@ Lint
|
||||||
.PHONY: lint lint-client lint-server
|
.PHONY: lint lint-client lint-server
|
||||||
|
@ -102,7 +102,7 @@ lint-client: ## Lint client code
|
||||||
yarn lint
|
yarn lint
|
||||||
|
|
||||||
lint-server: ## Lint server code
|
lint-server: ## Lint server code
|
||||||
cd api && go vet ./...
|
golangci-lint run --timeout=10m -c .golangci.yaml
|
||||||
|
|
||||||
|
|
||||||
##@ Extension
|
##@ Extension
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
portainer "github.com/portainer/portainer/api"
|
portainer "github.com/portainer/portainer/api"
|
||||||
"github.com/portainer/portainer/api/internal/testhelpers"
|
|
||||||
"github.com/portainer/portainer/pkg/libstack/compose"
|
"github.com/portainer/portainer/pkg/libstack/compose"
|
||||||
|
"github.com/portainer/portainer/pkg/testhelpers"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
|
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
cd api
|
|
||||||
if golangci-lint run --timeout=10m -c .golangci.yaml
|
|
||||||
then
|
|
||||||
echo "golangci-lint run successfully"
|
|
||||||
else
|
|
||||||
echo "golangci-lint run failed"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
|
@ -2,5 +2,5 @@ module.exports = {
|
||||||
'*.(js|ts){,x}': 'eslint --cache --fix',
|
'*.(js|ts){,x}': 'eslint --cache --fix',
|
||||||
'*.(ts){,x}': () => 'tsc --noEmit',
|
'*.(ts){,x}': () => 'tsc --noEmit',
|
||||||
'*.{js,ts,tsx,css,md,html,json}': 'prettier --write',
|
'*.{js,ts,tsx,css,md,html,json}': 'prettier --write',
|
||||||
'*.go': 'bash golangci-lint.sh',
|
'*.go': () => 'make lint-server',
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,7 +14,7 @@ func Test_enableFeaturesFromFlags(t *testing.T) {
|
||||||
supportedFeatures := []Feature{"supported", "supported2", "supported3", "supported4", "supported5"}
|
supportedFeatures := []Feature{"supported", "supported2", "supported3", "supported4", "supported5"}
|
||||||
|
|
||||||
t.Run("supported features should be supported", func(t *testing.T) {
|
t.Run("supported features should be supported", func(t *testing.T) {
|
||||||
Init(supportedFeatures)
|
initSupportedFeatures(supportedFeatures)
|
||||||
|
|
||||||
for _, featureFlag := range supportedFeatures {
|
for _, featureFlag := range supportedFeatures {
|
||||||
is.True(IsSupported(featureFlag))
|
is.True(IsSupported(featureFlag))
|
||||||
|
@ -22,7 +22,7 @@ func Test_enableFeaturesFromFlags(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("unsupported features should not be supported", func(t *testing.T) {
|
t.Run("unsupported features should not be supported", func(t *testing.T) {
|
||||||
Init(supportedFeatures)
|
initSupportedFeatures(supportedFeatures)
|
||||||
|
|
||||||
is.False(IsSupported("unsupported"))
|
is.False(IsSupported("unsupported"))
|
||||||
})
|
})
|
||||||
|
@ -35,13 +35,12 @@ func Test_enableFeaturesFromFlags(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
Init(supportedFeatures)
|
|
||||||
|
|
||||||
os.Unsetenv("PORTAINER_FEATURE_FLAGS")
|
os.Unsetenv("PORTAINER_FEATURE_FLAGS")
|
||||||
os.Setenv("PORTAINER_FEATURE_FLAGS", strings.Join(test.envFeatureFlags, ","))
|
os.Setenv("PORTAINER_FEATURE_FLAGS", strings.Join(test.envFeatureFlags, ","))
|
||||||
|
|
||||||
t.Run("testing", func(t *testing.T) {
|
t.Run("testing", func(t *testing.T) {
|
||||||
Parse(test.cliFeatureFlags)
|
Parse(test.cliFeatureFlags, supportedFeatures)
|
||||||
supported := toFeatureMap(test.cliFeatureFlags, test.envFeatureFlags)
|
supported := toFeatureMap(test.cliFeatureFlags, test.envFeatureFlags)
|
||||||
|
|
||||||
// add env flags to supported flags
|
// add env flags to supported flags
|
||||||
|
|
|
@ -63,9 +63,6 @@ type Chart struct {
|
||||||
// Files are miscellaneous files in a chart archive,
|
// Files are miscellaneous files in a chart archive,
|
||||||
// e.g. README, LICENSE, etc.
|
// e.g. README, LICENSE, etc.
|
||||||
Files []*File `json:"files"`
|
Files []*File `json:"files"`
|
||||||
|
|
||||||
parent *Chart
|
|
||||||
dependencies []*Chart
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// File represents a file as a name/value pair.
|
// File represents a file as a name/value pair.
|
||||||
|
|
|
@ -2,7 +2,6 @@ package compose_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
@ -13,12 +12,11 @@ import (
|
||||||
|
|
||||||
"github.com/portainer/portainer/pkg/libstack"
|
"github.com/portainer/portainer/pkg/libstack"
|
||||||
"github.com/portainer/portainer/pkg/libstack/compose"
|
"github.com/portainer/portainer/pkg/libstack/compose"
|
||||||
|
"github.com/portainer/portainer/pkg/testhelpers"
|
||||||
)
|
)
|
||||||
|
|
||||||
func checkPrerequisites(t *testing.T) {
|
func checkPrerequisites(t *testing.T) {
|
||||||
if _, err := os.Stat("docker-compose"); errors.Is(err, os.ErrNotExist) {
|
testhelpers.IntegrationTest(t)
|
||||||
t.Fatal("docker-compose binary not found, please run download.sh and re-run this suite")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_UpAndDown(t *testing.T) {
|
func Test_UpAndDown(t *testing.T) {
|
||||||
|
@ -31,7 +29,7 @@ func Test_UpAndDown(t *testing.T) {
|
||||||
services:
|
services:
|
||||||
busybox:
|
busybox:
|
||||||
image: "alpine:3.7"
|
image: "alpine:3.7"
|
||||||
container_name: "test_container_one"
|
container_name: "binarytest_container_one"
|
||||||
`
|
`
|
||||||
|
|
||||||
const overrideComposeFileContent = `
|
const overrideComposeFileContent = `
|
||||||
|
@ -39,10 +37,10 @@ func Test_UpAndDown(t *testing.T) {
|
||||||
services:
|
services:
|
||||||
busybox:
|
busybox:
|
||||||
image: "alpine:latest"
|
image: "alpine:latest"
|
||||||
container_name: "test_container_two"
|
container_name: "binarytest_container_two"
|
||||||
`
|
`
|
||||||
|
|
||||||
const composeContainerName = "test_container_two"
|
const composeContainerName = "binarytest_container_two"
|
||||||
|
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
|
@ -57,8 +55,13 @@ func Test_UpAndDown(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
projectName := "binarytest"
|
||||||
|
|
||||||
err = deployer.Deploy(ctx, []string{filePathOriginal, filePathOverride}, libstack.DeployOptions{})
|
err = deployer.Deploy(ctx, []string{filePathOriginal, filePathOverride}, libstack.DeployOptions{
|
||||||
|
Options: libstack.Options{
|
||||||
|
ProjectName: projectName,
|
||||||
|
},
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -67,7 +70,7 @@ func Test_UpAndDown(t *testing.T) {
|
||||||
t.Fatal("container should exist")
|
t.Fatal("container should exist")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = deployer.Remove(ctx, "", []string{filePathOriginal, filePathOverride}, libstack.Options{})
|
err = deployer.Remove(ctx, projectName, []string{filePathOriginal, filePathOverride}, libstack.Options{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
PLATFORM=$(go env GOOS)
|
|
||||||
ARCH=$(go env GOARCH)
|
|
||||||
COMPOSE_VERSION=v2.5.1
|
|
||||||
|
|
||||||
|
|
||||||
if [[ ${ARCH} == "amd64" ]]; then
|
|
||||||
ARCH="x86_64"
|
|
||||||
elif [[ ${ARCH} == "arm" ]]; then
|
|
||||||
ARCH="armv7"
|
|
||||||
elif [[ ${ARCH} == "arm64" ]]; then
|
|
||||||
ARCH="aarch64"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
if [[ "$PLATFORM" == "windows" ]]; then
|
|
||||||
wget --tries=3 --waitretry=30 --quiet -O "docker-compose.exe" "https://github.com/docker/compose/releases/download/$COMPOSE_VERSION/docker-compose-windows-${ARCH}.exe"
|
|
||||||
chmod +x "docker-compose.exe"
|
|
||||||
else
|
|
||||||
wget --tries=3 --waitretry=30 --quiet -O "docker-compose" "https://github.com/docker/compose/releases/download/$COMPOSE_VERSION/docker-compose-${PLATFORM}-${ARCH}"
|
|
||||||
chmod +x "docker-compose"
|
|
||||||
fi
|
|
||||||
|
|
|
@ -66,15 +66,15 @@ func Test_UpAndDown(t *testing.T) {
|
||||||
services:
|
services:
|
||||||
busybox:
|
busybox:
|
||||||
image: "alpine:3.7"
|
image: "alpine:3.7"
|
||||||
container_name: "test_container_one"`
|
container_name: "plugintest_container_one"`
|
||||||
|
|
||||||
const overrideComposeFileContent = `version: "3.9"
|
const overrideComposeFileContent = `version: "3.9"
|
||||||
services:
|
services:
|
||||||
busybox:
|
busybox:
|
||||||
image: "alpine:latest"
|
image: "alpine:latest"
|
||||||
container_name: "test_container_two"`
|
container_name: "plugintest_container_two"`
|
||||||
|
|
||||||
const composeContainerName = "test_container_two"
|
const composeContainerName = "plugintest_container_two"
|
||||||
|
|
||||||
w := setup(t)
|
w := setup(t)
|
||||||
|
|
||||||
|
@ -90,8 +90,14 @@ services:
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
projectName := "plugintest"
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
err = w.Deploy(ctx, []string{filePathOriginal, filePathOverride}, libstack.DeployOptions{})
|
err = w.Deploy(ctx, []string{filePathOriginal, filePathOverride}, libstack.DeployOptions{
|
||||||
|
Options: libstack.Options{
|
||||||
|
ProjectName: projectName,
|
||||||
|
},
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -100,7 +106,7 @@ services:
|
||||||
t.Fatal("container should exist")
|
t.Fatal("container should exist")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = w.Remove(ctx, "", []string{filePathOriginal, filePathOverride}, libstack.Options{})
|
err = w.Remove(ctx, projectName, []string{filePathOriginal, filePathOverride}, libstack.Options{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package composeplugin
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
@ -143,7 +144,7 @@ func (wrapper *PluginWrapper) WaitForStatus(ctx context.Context, name string, st
|
||||||
var svc service
|
var svc service
|
||||||
|
|
||||||
err := dec.Decode(&svc)
|
err := dec.Decode(&svc)
|
||||||
if err == io.EOF {
|
if errors.Is(err, io.EOF) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue