From 82951093b5c5a74a8dbe3d297bd9931f2cad1ea9 Mon Sep 17 00:00:00 2001 From: Chaim Lev-Ari Date: Tue, 2 Jan 2024 10:59:49 +0700 Subject: [PATCH] chore(ci): run lint and test on all pkgs [EE-6201] (#10481) --- .github/workflows/lint.yml | 3 +-- api/.golangci.yaml => .golangci.yaml | 0 Makefile | 8 +++--- api/exec/compose_stack_integration_test.go | 2 +- golangci-lint.sh | 11 -------- lint-staged.config.js | 2 +- pkg/featureflags/featureflags_test.go | 7 +++--- pkg/libhelm/release/release.go | 3 --- pkg/libstack/compose/compose_test.go | 21 +++++++++------- pkg/libstack/compose/download.sh | 25 ------------------- .../composeplugin/composeplugin_test.go | 16 ++++++++---- .../compose/internal/composeplugin/status.go | 3 ++- .../testhelpers/integration.go | 0 13 files changed, 35 insertions(+), 66 deletions(-) rename api/.golangci.yaml => .golangci.yaml (100%) delete mode 100755 golangci-lint.sh delete mode 100755 pkg/libstack/compose/download.sh rename {api/internal => pkg}/testhelpers/integration.go (100%) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 9aa865871..28e209c23 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -45,6 +45,5 @@ jobs: - name: GolangCI-Lint uses: golangci/golangci-lint-action@v3 with: - version: v1.54.1 - working-directory: api + version: v1.55.2 args: --timeout=10m -c .golangci.yaml diff --git a/api/.golangci.yaml b/.golangci.yaml similarity index 100% rename from api/.golangci.yaml rename to .golangci.yaml diff --git a/Makefile b/Makefile index 3fd0729fb..cdb0952a7 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ ARCH=$(shell go env GOARCH) # build target, can be one of "production", "testing", "development" ENV=development WEBPACK_CONFIG=webpack/webpack.$(ENV).js -TAG=latest +TAG=local SWAG=go run github.com/swaggo/swag/cmd/swag@v1.8.11 GOTESTSUM=go run gotest.tools/gotestsum@latest @@ -68,7 +68,7 @@ test-client: ## Run client tests yarn test $(ARGS) 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 .PHONY: dev dev-client dev-server @@ -92,7 +92,7 @@ format-client: ## Format client code yarn format format-server: ## Format server code - cd api && go fmt ./... + go fmt ./... ##@ Lint .PHONY: lint lint-client lint-server @@ -102,7 +102,7 @@ lint-client: ## Lint client code yarn lint lint-server: ## Lint server code - cd api && go vet ./... + golangci-lint run --timeout=10m -c .golangci.yaml ##@ Extension diff --git a/api/exec/compose_stack_integration_test.go b/api/exec/compose_stack_integration_test.go index 50da058b4..9c3272a82 100644 --- a/api/exec/compose_stack_integration_test.go +++ b/api/exec/compose_stack_integration_test.go @@ -10,8 +10,8 @@ import ( "testing" 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/testhelpers" "github.com/rs/zerolog/log" ) diff --git a/golangci-lint.sh b/golangci-lint.sh deleted file mode 100755 index 412146787..000000000 --- a/golangci-lint.sh +++ /dev/null @@ -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 diff --git a/lint-staged.config.js b/lint-staged.config.js index e0267a2a2..2dca01137 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -2,5 +2,5 @@ module.exports = { '*.(js|ts){,x}': 'eslint --cache --fix', '*.(ts){,x}': () => 'tsc --noEmit', '*.{js,ts,tsx,css,md,html,json}': 'prettier --write', - '*.go': 'bash golangci-lint.sh', + '*.go': () => 'make lint-server', }; diff --git a/pkg/featureflags/featureflags_test.go b/pkg/featureflags/featureflags_test.go index 9bfedf90f..b3e1f49ed 100644 --- a/pkg/featureflags/featureflags_test.go +++ b/pkg/featureflags/featureflags_test.go @@ -14,7 +14,7 @@ func Test_enableFeaturesFromFlags(t *testing.T) { supportedFeatures := []Feature{"supported", "supported2", "supported3", "supported4", "supported5"} t.Run("supported features should be supported", func(t *testing.T) { - Init(supportedFeatures) + initSupportedFeatures(supportedFeatures) for _, featureFlag := range supportedFeatures { 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) { - Init(supportedFeatures) + initSupportedFeatures(supportedFeatures) is.False(IsSupported("unsupported")) }) @@ -35,13 +35,12 @@ func Test_enableFeaturesFromFlags(t *testing.T) { } for _, test := range tests { - Init(supportedFeatures) os.Unsetenv("PORTAINER_FEATURE_FLAGS") os.Setenv("PORTAINER_FEATURE_FLAGS", strings.Join(test.envFeatureFlags, ",")) t.Run("testing", func(t *testing.T) { - Parse(test.cliFeatureFlags) + Parse(test.cliFeatureFlags, supportedFeatures) supported := toFeatureMap(test.cliFeatureFlags, test.envFeatureFlags) // add env flags to supported flags diff --git a/pkg/libhelm/release/release.go b/pkg/libhelm/release/release.go index 48ed23c88..06b4eb6ff 100644 --- a/pkg/libhelm/release/release.go +++ b/pkg/libhelm/release/release.go @@ -63,9 +63,6 @@ type Chart struct { // Files are miscellaneous files in a chart archive, // e.g. README, LICENSE, etc. Files []*File `json:"files"` - - parent *Chart - dependencies []*Chart } // File represents a file as a name/value pair. diff --git a/pkg/libstack/compose/compose_test.go b/pkg/libstack/compose/compose_test.go index 2a4830ea0..3678a5159 100644 --- a/pkg/libstack/compose/compose_test.go +++ b/pkg/libstack/compose/compose_test.go @@ -2,7 +2,6 @@ package compose_test import ( "context" - "errors" "fmt" "log" "os" @@ -13,12 +12,11 @@ import ( "github.com/portainer/portainer/pkg/libstack" "github.com/portainer/portainer/pkg/libstack/compose" + "github.com/portainer/portainer/pkg/testhelpers" ) func checkPrerequisites(t *testing.T) { - if _, err := os.Stat("docker-compose"); errors.Is(err, os.ErrNotExist) { - t.Fatal("docker-compose binary not found, please run download.sh and re-run this suite") - } + testhelpers.IntegrationTest(t) } func Test_UpAndDown(t *testing.T) { @@ -31,7 +29,7 @@ func Test_UpAndDown(t *testing.T) { services: busybox: image: "alpine:3.7" - container_name: "test_container_one" + container_name: "binarytest_container_one" ` const overrideComposeFileContent = ` @@ -39,10 +37,10 @@ func Test_UpAndDown(t *testing.T) { services: busybox: 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() @@ -57,8 +55,13 @@ func Test_UpAndDown(t *testing.T) { } 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 { t.Fatal(err) } @@ -67,7 +70,7 @@ func Test_UpAndDown(t *testing.T) { 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 { t.Fatal(err) } diff --git a/pkg/libstack/compose/download.sh b/pkg/libstack/compose/download.sh deleted file mode 100755 index 7fe19cb0b..000000000 --- a/pkg/libstack/compose/download.sh +++ /dev/null @@ -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 - diff --git a/pkg/libstack/compose/internal/composeplugin/composeplugin_test.go b/pkg/libstack/compose/internal/composeplugin/composeplugin_test.go index 450d1e81a..329a1ae97 100644 --- a/pkg/libstack/compose/internal/composeplugin/composeplugin_test.go +++ b/pkg/libstack/compose/internal/composeplugin/composeplugin_test.go @@ -66,15 +66,15 @@ func Test_UpAndDown(t *testing.T) { services: busybox: image: "alpine:3.7" - container_name: "test_container_one"` + container_name: "plugintest_container_one"` const overrideComposeFileContent = `version: "3.9" services: busybox: 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) @@ -90,8 +90,14 @@ services: t.Fatal(err) } + projectName := "plugintest" + 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 { t.Fatal(err) } @@ -100,7 +106,7 @@ services: 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 { t.Fatal(err) } diff --git a/pkg/libstack/compose/internal/composeplugin/status.go b/pkg/libstack/compose/internal/composeplugin/status.go index 07ae648d3..27cbd4fe9 100644 --- a/pkg/libstack/compose/internal/composeplugin/status.go +++ b/pkg/libstack/compose/internal/composeplugin/status.go @@ -3,6 +3,7 @@ package composeplugin import ( "bytes" "context" + "errors" "fmt" "io" "time" @@ -143,7 +144,7 @@ func (wrapper *PluginWrapper) WaitForStatus(ctx context.Context, name string, st var svc service err := dec.Decode(&svc) - if err == io.EOF { + if errors.Is(err, io.EOF) { break } if err != nil { diff --git a/api/internal/testhelpers/integration.go b/pkg/testhelpers/integration.go similarity index 100% rename from api/internal/testhelpers/integration.go rename to pkg/testhelpers/integration.go