Skip to content

Commit

Permalink
feat(lint): enabe goconst linter
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed May 13, 2024
1 parent 0e97aee commit dab74ed
Show file tree
Hide file tree
Showing 46 changed files with 172 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ linters:
# TODO: too much work at this stage as many files are impacted by the lint suggestions, however the reported
# lint violation make a lot of sense so we should re-enable the lints below and work to fix the findings
- perfsprint
- goconst
#- goconst
8 changes: 5 additions & 3 deletions addons/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package telemetry
import (
"fmt"

"github.com/apache/camel-k/v2/pkg/util/boolean"

"k8s.io/utils/pointer"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -161,9 +163,9 @@ func (t *telemetryTrait) setCatalogConfiguration(e *trait.Environment) {
e.ApplicationProperties["camel.k.telemetry.samplerRatio"] = t.SamplerRatio
}
if pointer.BoolDeref(t.SamplerParentBased, true) {
e.ApplicationProperties["camel.k.telemetry.samplerParentBased"] = "true"
e.ApplicationProperties["camel.k.telemetry.samplerParentBased"] = boolean.TrueString
} else {
e.ApplicationProperties["camel.k.telemetry.samplerParentBased"] = "false"
e.ApplicationProperties["camel.k.telemetry.samplerParentBased"] = boolean.FalseString
}

for _, cp := range e.CamelCatalog.Runtime.Capabilities["telemetry"].RuntimeProperties {
Expand Down Expand Up @@ -195,7 +197,7 @@ func (t *telemetryTrait) setProperties(e *trait.Environment) {
if pointer.BoolDeref(t.SamplerParentBased, true) {
e.ApplicationProperties[appPropSamplerParentBased] = "true"
} else {
e.ApplicationProperties[appPropSamplerParentBased] = "false"
e.ApplicationProperties[appPropSamplerParentBased] = boolean.FalseString
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion addons/telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package telemetry

import (
"github.com/apache/camel-k/v2/pkg/util/boolean"
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -81,7 +82,7 @@ func TestTelemetryTraitWithValues(t *testing.T) {
assert.Equal(t, "service.name=Test", e.ApplicationProperties["camel.k.telemetry.serviceName"])
assert.Equal(t, "ratio", e.ApplicationProperties["camel.k.telemetry.sampler"])
assert.Equal(t, "0.001", e.ApplicationProperties["camel.k.telemetry.samplerRatio"])
assert.Equal(t, "false", e.ApplicationProperties["camel.k.telemetry.samplerParentBased"])
assert.Equal(t, boolean.FalseString, e.ApplicationProperties["camel.k.telemetry.samplerParentBased"])
assert.Equal(t, "${camel.k.telemetry.endpoint}", e.ApplicationProperties["quarkus.opentelemetry.tracer.exporter.otlp.endpoint"])
assert.Equal(t, "${camel.k.telemetry.serviceName}", e.ApplicationProperties["quarkus.opentelemetry.tracer.resource-attributes"])
assert.Equal(t, "${camel.k.telemetry.sampler}", e.ApplicationProperties["quarkus.opentelemetry.tracer.sampler"])
Expand Down
9 changes: 5 additions & 4 deletions addons/vault/aws/aws_secrets_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package aws

import (
"github.com/apache/camel-k/v2/pkg/util/boolean"
"testing"

"github.com/apache/camel-k/v2/pkg/util/test"
Expand Down Expand Up @@ -56,7 +57,7 @@ func TestAwsSecretsManagerTraitApply(t *testing.T) {
assert.Equal(t, "eu-west-1", e.ApplicationProperties["camel.vault.aws.region"])
assert.Equal(t, "access-key", e.ApplicationProperties["camel.vault.aws.accessKey"])
assert.Equal(t, "secret-key", e.ApplicationProperties["camel.vault.aws.secretKey"])
assert.Equal(t, "false", e.ApplicationProperties["camel.vault.aws.defaultCredentialsProvider"])
assert.Equal(t, boolean.FalseString, e.ApplicationProperties["camel.vault.aws.defaultCredentialsProvider"])
}

func TestAwsSecretsManagerTraitNoDefaultCreds(t *testing.T) {
Expand All @@ -79,7 +80,7 @@ func TestAwsSecretsManagerTraitNoDefaultCreds(t *testing.T) {
assert.Equal(t, "eu-west-1", e.ApplicationProperties["camel.vault.aws.region"])
assert.Equal(t, "access-key", e.ApplicationProperties["camel.vault.aws.accessKey"])
assert.Equal(t, "secret-key", e.ApplicationProperties["camel.vault.aws.secretKey"])
assert.Equal(t, "false", e.ApplicationProperties["camel.vault.aws.defaultCredentialsProvider"])
assert.Equal(t, boolean.FalseString, e.ApplicationProperties["camel.vault.aws.defaultCredentialsProvider"])
}

func TestAwsSecretsManagerTraitWithSecrets(t *testing.T) {
Expand Down Expand Up @@ -119,7 +120,7 @@ func TestAwsSecretsManagerTraitWithSecrets(t *testing.T) {
assert.Equal(t, "eu-west-1", e.ApplicationProperties["camel.vault.aws.region"])
assert.Equal(t, "my-access-key", e.ApplicationProperties["camel.vault.aws.accessKey"])
assert.Equal(t, "my-secret-key", e.ApplicationProperties["camel.vault.aws.secretKey"])
assert.Equal(t, "false", e.ApplicationProperties["camel.vault.aws.defaultCredentialsProvider"])
assert.Equal(t, boolean.FalseString, e.ApplicationProperties["camel.vault.aws.defaultCredentialsProvider"])
}

func TestAwsSecretsManagerTraitWithConfigMap(t *testing.T) {
Expand Down Expand Up @@ -159,7 +160,7 @@ func TestAwsSecretsManagerTraitWithConfigMap(t *testing.T) {
assert.Equal(t, "eu-west-1", e.ApplicationProperties["camel.vault.aws.region"])
assert.Equal(t, "my-access-key", e.ApplicationProperties["camel.vault.aws.accessKey"])
assert.Equal(t, "my-secret-key", e.ApplicationProperties["camel.vault.aws.secretKey"])
assert.Equal(t, "false", e.ApplicationProperties["camel.vault.aws.defaultCredentialsProvider"])
assert.Equal(t, boolean.FalseString, e.ApplicationProperties["camel.vault.aws.defaultCredentialsProvider"])
}

func createEnvironment(t *testing.T, catalogGen func() (*camel.RuntimeCatalog, error), objects ...runtime.Object) *trait.Environment {
Expand Down
5 changes: 3 additions & 2 deletions addons/vault/gcp/gcp_secret_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package gcp

import (
"github.com/apache/camel-k/v2/pkg/util/boolean"
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -49,7 +50,7 @@ func TestGcpSecretManagerTraitApply(t *testing.T) {

assert.Equal(t, "project-gcp", e.ApplicationProperties["camel.vault.gcp.projectId"])
assert.Equal(t, "file:////usr/local/serviceaccount.json", e.ApplicationProperties["camel.vault.gcp.serviceAccountKey"])
assert.Equal(t, "false", e.ApplicationProperties["camel.vault.gcp.useDefaultInstance"])
assert.Equal(t, boolean.FalseString, e.ApplicationProperties["camel.vault.gcp.useDefaultInstance"])
}

func TestGcpSecretManagerTraitNoDefaultCreds(t *testing.T) {
Expand All @@ -70,7 +71,7 @@ func TestGcpSecretManagerTraitNoDefaultCreds(t *testing.T) {

assert.Equal(t, "project-gcp", e.ApplicationProperties["camel.vault.gcp.projectId"])
assert.Equal(t, "file:////usr/local/serviceaccount.json", e.ApplicationProperties["camel.vault.gcp.serviceAccountKey"])
assert.Equal(t, "false", e.ApplicationProperties["camel.vault.gcp.useDefaultInstance"])
assert.Equal(t, boolean.FalseString, e.ApplicationProperties["camel.vault.gcp.useDefaultInstance"])
}

func createEnvironment(t *testing.T, catalogGen func() (*camel.RuntimeCatalog, error)) *trait.Environment {
Expand Down
5 changes: 3 additions & 2 deletions e2e/advanced/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package advanced

import (
"fmt"
"github.com/apache/camel-k/v2/pkg/util/boolean"
"os"
"testing"

Expand All @@ -37,12 +38,12 @@ import (
)

func TestMain(m *testing.M) {
justCompile := GetEnvOrDefault("CAMEL_K_E2E_JUST_COMPILE", "false")
justCompile := GetEnvOrDefault("CAMEL_K_E2E_JUST_COMPILE", boolean.FalseString)
if justCompile == "true" {
os.Exit(m.Run())
}

fastSetup := GetEnvOrDefault("CAMEL_K_E2E_FAST_SETUP", "false")
fastSetup := GetEnvOrDefault("CAMEL_K_E2E_FAST_SETUP", boolean.FalseString)
if fastSetup == "true" {
operatorID := platform.DefaultPlatformName
ns := GetEnvOrDefault("CAMEL_K_GLOBAL_OPERATOR_NS", TestDefaultNamespace)
Expand Down
3 changes: 2 additions & 1 deletion e2e/common/cli/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package cli

import (
"fmt"
"github.com/apache/camel-k/v2/pkg/util/boolean"
"os"
"testing"

Expand All @@ -34,7 +35,7 @@ import (
)

func TestMain(m *testing.M) {
justCompile := GetEnvOrDefault("CAMEL_K_E2E_JUST_COMPILE", "false")
justCompile := GetEnvOrDefault("CAMEL_K_E2E_JUST_COMPILE", boolean.FalseString)
if justCompile == "true" {
os.Exit(m.Run())
}
Expand Down
7 changes: 4 additions & 3 deletions e2e/common/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ import (
. "github.com/apache/camel-k/v2/e2e/support"
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
"github.com/apache/camel-k/v2/pkg/platform"
"github.com/apache/camel-k/v2/pkg/util/boolean"
)

func TestMain(m *testing.M) {
justCompile := GetEnvOrDefault("CAMEL_K_E2E_JUST_COMPILE", "false")
if justCompile == "true" {
justCompile := GetEnvOrDefault("CAMEL_K_E2E_JUST_COMPILE", boolean.FalseString)
if justCompile == boolean.TrueString {
os.Exit(m.Run())
}

fastSetup := GetEnvOrDefault("CAMEL_K_E2E_FAST_SETUP", "false")
fastSetup := GetEnvOrDefault("CAMEL_K_E2E_FAST_SETUP", boolean.FalseString)
if fastSetup == "true" {
operatorID := platform.DefaultPlatformName
ns := GetEnvOrDefault("CAMEL_K_GLOBAL_OPERATOR_NS", TestDefaultNamespace)
Expand Down
2 changes: 1 addition & 1 deletion e2e/common/traits/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func TestHealthTrait(t *testing.T) {
// lastTransitionTime: "2021-12-08T20:12:14Z"
// message: 'containers with unready status: [integration]'
// reason: ContainersNotReady
// status: "False"
// status: False
// type: Ready
//
g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(And(
Expand Down
9 changes: 5 additions & 4 deletions e2e/support/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import (
"github.com/apache/camel-k/v2/pkg/platform"
pkgutil "github.com/apache/camel-k/v2/pkg/util"
v2util "github.com/apache/camel-k/v2/pkg/util"
"github.com/apache/camel-k/v2/pkg/util/boolean"
"github.com/apache/camel-k/v2/pkg/util/defaults"
"github.com/apache/camel-k/v2/pkg/util/kubernetes"
"github.com/apache/camel-k/v2/pkg/util/log"
Expand Down Expand Up @@ -285,10 +286,10 @@ func kamelInstallWithContext(t *testing.T, ctx context.Context, operatorID strin
installArgs = []string{"install", "-n", namespace, "--operator-id", operatorID, "--skip-cluster-setup"}

if !pkgutil.StringSliceExists(args, "--build-timeout") {
//if --build-timeout is not explicitly passed as an argument, try to configure it
// if --build-timeout is not explicitly passed as an argument, try to configure it
buildTimeout := os.Getenv("CAMEL_K_TEST_BUILD_TIMEOUT")
if buildTimeout == "" {
//default Build Timeout for tests
// default Build Timeout for tests
buildTimeout = "10m"
}
fmt.Printf("Setting build timeout to %s\n", buildTimeout)
Expand Down Expand Up @@ -2011,7 +2012,7 @@ func PlatformByName(t *testing.T, ctx context.Context, ns string, name string) f
}

func CopyIntegrationKits(t *testing.T, ctx context.Context, ns, operatorID string) error {
if value, ok := os.LookupEnv("CAMEL_K_TEST_COPY_INTEGRATION_KITS"); ok && value == "false" {
if value, ok := os.LookupEnv("CAMEL_K_TEST_COPY_INTEGRATION_KITS"); ok && value == boolean.FalseString {
fmt.Println("Copy integration kits optimization is disabled")
return nil
}
Expand Down Expand Up @@ -2046,7 +2047,7 @@ func CopyIntegrationKits(t *testing.T, ctx context.Context, ns, operatorID strin
}

func CopyCamelCatalog(t *testing.T, ctx context.Context, ns, operatorID string) error {
if value, ok := os.LookupEnv("CAMEL_K_TEST_COPY_CATALOG"); ok && value == "false" {
if value, ok := os.LookupEnv("CAMEL_K_TEST_COPY_CATALOG"); ok && value == boolean.FalseString {
fmt.Println("Copy catalog optimization is disabled")
return nil
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/builder/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"regexp"
"testing"

"github.com/apache/camel-k/v2/pkg/util/boolean"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -454,7 +456,7 @@ func TestInjectServersIntoDefaultMavenSettings(t *testing.T) {
Username: "jpoth",
Password: "changeit",
Configuration: v1.Properties{
"allowInsecureRegistries": "false",
"allowInsecureRegistries": boolean.FalseString,
},
},
}
Expand All @@ -480,7 +482,7 @@ func TestInjectServersIntoCustomMavenSettings(t *testing.T) {
Username: "jpoth",
Password: "changeit",
Configuration: v1.Properties{
"allowInsecureRegistries": "false",
"allowInsecureRegistries": boolean.FalseString,
},
},
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/builder/quarkus.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"path/filepath"
"strings"

"github.com/apache/camel-k/v2/pkg/util/boolean"

"github.com/apache/camel-k/v2/pkg/util/io"

v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
Expand Down Expand Up @@ -236,12 +238,12 @@ func computeApplicationProperties(appPropertiesPath string, applicationPropertie
applicationProperties = make(map[string]string)
}
// disable quarkus banner
applicationProperties["quarkus.banner.enabled"] = "false"
applicationProperties["quarkus.banner.enabled"] = boolean.FalseString
// camel-quarkus does route discovery at startup, but we don't want
// this to happen as routes are loaded at runtime and looking for
// routes at build time may try to load camel-k-runtime routes builder
// proxies which in some case may fail.
applicationProperties["quarkus.camel.routes-discovery.enabled"] = "false"
applicationProperties["quarkus.camel.routes-discovery.enabled"] = boolean.FalseString
// required for to resolve data type transformers at runtime with service discovery
// the different Camel runtimes use different resource paths for the service lookup
applicationProperties["quarkus.camel.service.discovery.include-patterns"] = "META-INF/services/org/apache/camel/datatype/converter/*,META-INF/services/org/apache/camel/datatype/transformer/*,META-INF/services/org/apache/camel/transformer/*"
Expand Down
8 changes: 5 additions & 3 deletions pkg/builder/quarkus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"strings"
"testing"

"github.com/apache/camel-k/v2/pkg/util/boolean"

v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
"github.com/apache/camel-k/v2/pkg/util/camel"
"github.com/apache/camel-k/v2/pkg/util/defaults"
Expand Down Expand Up @@ -146,7 +148,7 @@ func TestGenerateQuarkusProjectWithBuildTimeProperties(t *testing.T) {
err = generateQuarkusProject(&builderContext)
require.NoError(t, err)
// use local Maven executable in tests
t.Setenv("MAVEN_WRAPPER", "false")
t.Setenv("MAVEN_WRAPPER", boolean.FalseString)
_, ok := os.LookupEnv("MAVEN_CMD")
if !ok {
t.Setenv("MAVEN_CMD", "mvn")
Expand Down Expand Up @@ -205,7 +207,7 @@ func TestGenerateQuarkusProjectWithNativeSources(t *testing.T) {
err = generateQuarkusProject(&builderContext)
require.NoError(t, err)
// use local Maven executable in tests
t.Setenv("MAVEN_WRAPPER", "false")
t.Setenv("MAVEN_WRAPPER", boolean.FalseString)
_, ok := os.LookupEnv("MAVEN_CMD")
if !ok {
t.Setenv("MAVEN_CMD", "mvn")
Expand Down Expand Up @@ -281,7 +283,7 @@ func TestBuildQuarkusRunner(t *testing.T) {
err = sanitizeDependencies(&builderContext)
require.NoError(t, err)
// use local Maven executable in tests
t.Setenv("MAVEN_WRAPPER", "false")
t.Setenv("MAVEN_WRAPPER", boolean.FalseString)
_, ok := os.LookupEnv("MAVEN_CMD")
if !ok {
t.Setenv("MAVEN_CMD", "mvn")
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

//nolint:goconst
package cmd

import (
Expand Down
6 changes: 4 additions & 2 deletions pkg/controller/integrationplatform/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"strings"
"testing"

"github.com/apache/camel-k/v2/pkg/util/boolean"

v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
"github.com/apache/camel-k/v2/pkg/platform"
"github.com/apache/camel-k/v2/pkg/resources"
Expand Down Expand Up @@ -91,7 +93,7 @@ func TestCreateCatalog(t *testing.T) {
require.NoError(t, err)

// use local Maven executable in tests
t.Setenv("MAVEN_WRAPPER", "false")
t.Setenv("MAVEN_WRAPPER", boolean.FalseString)
_, ok := os.LookupEnv("MAVEN_CMD")
if !ok {
t.Setenv("MAVEN_CMD", "mvn")
Expand Down Expand Up @@ -194,7 +196,7 @@ func TestCreateCatalogError(t *testing.T) {
require.NoError(t, err)

// use local Maven executable in tests
t.Setenv("MAVEN_WRAPPER", "false")
t.Setenv("MAVEN_WRAPPER", boolean.FalseString)
_, ok := os.LookupEnv("MAVEN_CMD")
if !ok {
t.Setenv("MAVEN_CMD", "mvn")
Expand Down
1 change: 1 addition & 0 deletions pkg/install/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

//nolint:goconst
package install

import (
Expand Down
3 changes: 2 additions & 1 deletion pkg/install/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ type OperatorStorageConfiguration struct {
}

// OperatorOrCollect installs the operator resources or adds them to the collector if present.
// nolint: maintidx // TODO: refactor the code
//
//nolint:maintidx,goconst
func OperatorOrCollect(ctx context.Context, cmd *cobra.Command, c client.Client, cfg OperatorConfiguration, collection *kubernetes.Collection, force bool) error {
isOpenShift, err := isOpenShift(c, cfg.ClusterType)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion pkg/trait/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"strconv"
"strings"

"github.com/apache/camel-k/v2/pkg/util/boolean"

corev1 "k8s.io/api/core/v1"

v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
Expand Down Expand Up @@ -406,7 +408,7 @@ func (t *builderTrait) builderTask(e *Environment, taskConf *v1.BuildConfigurati

// Build time property required by master capability
if e.IntegrationKit.HasCapability("master") && e.CamelCatalog.Runtime.Capabilities["master"].BuildTimeProperties != nil {
task.Maven.Properties["camel.k.master.enabled"] = "true"
task.Maven.Properties["camel.k.master.enabled"] = boolean.TrueString
for _, cp := range e.CamelCatalog.Runtime.Capabilities["master"].BuildTimeProperties {
task.Maven.Properties[CapabilityPropertyKey(cp.Key, task.Maven.Properties)] = cp.Value
}
Expand Down
Loading

0 comments on commit dab74ed

Please sign in to comment.