Skip to content
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
6 changes: 1 addition & 5 deletions e2e/common/cli/promote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ package common

import (
"context"
"os"
"testing"

corev1 "k8s.io/api/core/v1"
Expand All @@ -47,10 +46,7 @@ func TestKamelPromoteGitOps(t *testing.T) {
})
WithNewTestNamespace(t, func(ctx context.Context, g *WithT, nsTarget string) {
// Export to GitOps directory structure
tmpDir, err := os.MkdirTemp("", "ck-promote-it-*")
if err != nil {
t.Error(err)
}
tmpDir := t.TempDir()
g.Expect(Kamel(t, ctx, "promote", "yaml", "-n", ns, "--to", nsTarget, "--export-gitops-dir", tmpDir).Execute()).To(Succeed())
// Run the exported Integration as it would be any CICD
ExpectExecSucceed(t, g, Kubectl("apply", "-k", tmpDir+"/yaml/overlays/"+nsTarget))
Expand Down
6 changes: 2 additions & 4 deletions pkg/builder/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import (
)

func TestProcessDependenciesSkipNested(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "ck-deps-dir")
require.NoError(t, err)
tmpDir := t.TempDir()
tmpDirNested, err := os.MkdirTemp(tmpDir, "nested")
require.NoError(t, err)
err = util.WriteFileWithContent(path.Join(tmpDir, "deps.jar"), []byte("bogus"))
Expand All @@ -48,8 +47,7 @@ func TestProcessDependenciesSkipNested(t *testing.T) {
}

func TestProcessDependenciesIncludeNested(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "ck-deps-dir")
require.NoError(t, err)
tmpDir := t.TempDir()
tmpDirNested, err := os.MkdirTemp(tmpDir, "nested")
require.NoError(t, err)
err = util.WriteFileWithContent(path.Join(tmpDir, "deps.jar"), []byte("bogus"))
Expand Down
10 changes: 4 additions & 6 deletions pkg/builder/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ import (
)

func TestGitPublicRepo(t *testing.T) {
tmpGitDir, err := os.MkdirTemp("", "ck-git-dir")
require.NoError(t, err)
tmpGitDir := t.TempDir()

ctx := &builderContext{
C: context.TODO(),
Expand All @@ -45,7 +44,7 @@ func TestGitPublicRepo(t *testing.T) {
},
}

err = cloneProject(ctx)
err := cloneProject(ctx)
require.NoError(t, err)
f, err := os.Stat(path.Join(tmpGitDir, "maven", "pom.xml"))
require.NoError(t, err)
Expand Down Expand Up @@ -75,8 +74,7 @@ func TestGitPublicRepo(t *testing.T) {
}

func TestGitPrivateRepoFail(t *testing.T) {
tmpGitDir, err := os.MkdirTemp("", "ck-git-dir")
require.NoError(t, err)
tmpGitDir := t.TempDir()

ctx := &builderContext{
Path: tmpGitDir,
Expand All @@ -87,7 +85,7 @@ func TestGitPrivateRepoFail(t *testing.T) {
},
}

err = cloneProject(ctx)
err := cloneProject(ctx)
require.Error(t, err)
assert.Contains(t, err.Error(), "authentication required")
_, err = os.Stat(path.Join(tmpGitDir, "maven", "pom.xml"))
Expand Down
17 changes: 6 additions & 11 deletions pkg/builder/jib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package builder
import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
"testing"
Expand All @@ -32,8 +31,7 @@ import (
)

func TestJibBuildMavenArgs(t *testing.T) {
tmpMvnCtxDir, err := os.MkdirTemp("", "my-build-test")
require.NoError(t, err)
tmpMvnCtxDir := t.TempDir()
args := buildJibMavenArgs(tmpMvnCtxDir, "my-image", "my-base-image", true, nil)
expectedParams := strings.Split(
fmt.Sprintf("jib:build -Djib.disableUpdateChecks=true -P jib -Djib.to.image=my-image "+
Expand All @@ -43,8 +41,7 @@ func TestJibBuildMavenArgs(t *testing.T) {
}

func TestJibBuildMavenArgsWithPlatforms(t *testing.T) {
tmpMvnCtxDir, err := os.MkdirTemp("", "my-build-test")
require.NoError(t, err)
tmpMvnCtxDir := t.TempDir()
args := buildJibMavenArgs(tmpMvnCtxDir, "my-image", "my-base-image", true, []string{"amd64", "arm64"})
expectedParams := strings.Split(
fmt.Sprintf("jib:build -Djib.disableUpdateChecks=true -P jib -Djib.to.image=my-image "+
Expand All @@ -55,13 +52,12 @@ func TestJibBuildMavenArgsWithPlatforms(t *testing.T) {
}

func TestInjectJibProfileMissingPom(t *testing.T) {
tmpMvnCtxDir, err := os.MkdirTemp("", "ck-jib-profile-test")
require.NoError(t, err)
tmpMvnCtxDir := t.TempDir()
builderContext := builderContext{
C: context.TODO(),
Path: tmpMvnCtxDir,
}
err = injectJibProfile(&builderContext)
err := injectJibProfile(&builderContext)
assert.Error(t, err)
assert.Contains(t, err.Error(), "no such file or directory")
}
Expand All @@ -73,16 +69,15 @@ var poms = []string{
}

func TestInjectJibProfiles(t *testing.T) {
tmpMvnCtxDir, err := os.MkdirTemp("", "ck-jib-profile-test")
require.NoError(t, err)
tmpMvnCtxDir := t.TempDir()
builderContext := builderContext{
C: context.TODO(),
Path: tmpMvnCtxDir,
}

for _, p := range poms {
pom := filepath.Join(tmpMvnCtxDir, "maven", "pom.xml")
err = util.WriteFileWithContent(pom, []byte(p))
err := util.WriteFileWithContent(pom, []byte(p))
require.NoError(t, err)
err = injectJibProfile(&builderContext)
require.NoError(t, err)
Expand Down
9 changes: 3 additions & 6 deletions pkg/builder/quarkus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ func TestLoadCamelQuarkusCatalogOk(t *testing.T) {
}

func TestGenerateQuarkusProjectWithBuildTimeProperties(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "go-test-camel-k-quarkus-with-props")
require.NoError(t, err)
tmpDir := t.TempDir()
defaultCatalog, err := camel.DefaultCatalog()
require.NoError(t, err)

Expand Down Expand Up @@ -167,8 +166,7 @@ func TestGenerateQuarkusProjectWithBuildTimeProperties(t *testing.T) {
}

func TestGenerateQuarkusProjectWithNativeSources(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "go-test-camel-k-quarkus-native")
require.NoError(t, err)
tmpDir := t.TempDir()
defaultCatalog, err := camel.DefaultCatalog()
require.NoError(t, err)

Expand Down Expand Up @@ -227,8 +225,7 @@ func TestGenerateQuarkusProjectWithNativeSources(t *testing.T) {
}

func TestBuildQuarkusRunner(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "go-test-camel-k-quarkus")
require.NoError(t, err)
tmpDir := t.TempDir()
defaultCatalog, err := camel.DefaultCatalog()
require.NoError(t, err)
c, err := internal.NewFakeClient(&v1.CamelCatalog{
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ func TestBindServiceAccountName(t *testing.T) {
}

func TestBindOutputWithoutKubernetesCluster(t *testing.T) {
tmpFile, err := os.CreateTemp("", "camel-k-kubeconfig-*")
tempDir := t.TempDir()
tmpFile, err := os.CreateTemp(tempDir, "camel-k-kubeconfig-*")
require.NoError(t, err)

bindCmdOptions, bindCmd, _ := initializeBindCmdOptions(t)
Expand Down
10 changes: 2 additions & 8 deletions pkg/cmd/promote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,7 @@ func TestIntegrationGitOps(t *testing.T) {
srcCatalog := createTestCamelCatalog(srcPlatform)
dstCatalog := createTestCamelCatalog(dstPlatform)

tmpDir, err := os.MkdirTemp("", "ck-promote-it-*")
if err != nil {
t.Error(err)
}
tmpDir := t.TempDir()

_, promoteCmd, _ := initializePromoteCmdOptions(t, &srcPlatform, &dstPlatform, &defaultIntegration, &defaultKit, &srcCatalog, &dstCatalog)
output, err := ExecuteCommand(promoteCmd, cmdPromote, "my-it-test", "--to", "prod-namespace", "--export-gitops-dir", tmpDir, "-n", "default")
Expand Down Expand Up @@ -702,10 +699,7 @@ func TestPipeGitOps(t *testing.T) {
srcCatalog := createTestCamelCatalog(srcPlatform)
dstCatalog := createTestCamelCatalog(dstPlatform)

tmpDir, err := os.MkdirTemp("", "ck-promote-pipe-*")
if err != nil {
t.Error(err)
}
tmpDir := t.TempDir()

_, promoteCmd, _ := initializePromoteCmdOptions(t, &srcPlatform, &dstPlatform, &defaultKB, &defaultIntegration, &defaultKit, &srcCatalog, &dstCatalog)
output, err := ExecuteCommand(promoteCmd, cmdPromote, "my-pipe-test", "--to", "prod-namespace", "--export-gitops-dir", tmpDir, "-n", "default")
Expand Down
52 changes: 27 additions & 25 deletions pkg/cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ func TestExtractProperties_SingleKeyValue(t *testing.T) {
func TestExtractProperties_FromFile(t *testing.T) {
var tmpFile1 *os.File
var err error
if tmpFile1, err = os.CreateTemp("", "camel-k-*.properties"); err != nil {
tempDir := t.TempDir()
if tmpFile1, err = os.CreateTemp(tempDir, "camel-k-*.properties"); err != nil {
t.Error(err)
}

Expand All @@ -324,7 +325,8 @@ func TestExtractProperties_FromFile(t *testing.T) {
func TestExtractPropertiesFromFileAndSingleValue(t *testing.T) {
var tmpFile1 *os.File
var err error
if tmpFile1, err = os.CreateTemp("", "camel-k-*.properties"); err != nil {
tempDir := t.TempDir()
if tmpFile1, err = os.CreateTemp(tempDir, "camel-k-*.properties"); err != nil {
t.Error(err)
}

Expand All @@ -351,7 +353,8 @@ func TestExtractPropertiesFromFileAndSingleValue(t *testing.T) {
func TestAddPropertyFile(t *testing.T) {
var tmpFile *os.File
var err error
if tmpFile, err = os.CreateTemp("", "camel-k-"); err != nil {
tempDir := t.TempDir()
if tmpFile, err = os.CreateTemp(tempDir, "camel-k-"); err != nil {
t.Error(err)
}

Expand Down Expand Up @@ -582,7 +585,8 @@ public class Sample extends RouteBuilder {
func TestOutputYaml(t *testing.T) {
var tmpFile *os.File
var err error
if tmpFile, err = os.CreateTemp("", "camel-k-"); err != nil {
tempDir := t.TempDir()
if tmpFile, err = os.CreateTemp(tempDir, "camel-k-"); err != nil {
t.Error(err)
}

Expand Down Expand Up @@ -616,7 +620,8 @@ status: {}
func TestTrait(t *testing.T) {
var tmpFile *os.File
var err error
if tmpFile, err = os.CreateTemp("", "camel-k-"); err != nil {
tempDir := t.TempDir()
if tmpFile, err = os.CreateTemp(tempDir, "camel-k-"); err != nil {
t.Error(err)
}

Expand Down Expand Up @@ -653,7 +658,8 @@ status: {}
func TestMissingTrait(t *testing.T) {
var tmpFile *os.File
var err error
if tmpFile, err = os.CreateTemp("", "camel-k-"); err != nil {
tempDir := t.TempDir()
if tmpFile, err = os.CreateTemp(tempDir, "camel-k-"); err != nil {
t.Error(err)
}

Expand Down Expand Up @@ -703,7 +709,8 @@ func TestResolveJsonPodTemplateWithSupplementalGroups(t *testing.T) {
func TestIntegrationServiceAccountName(t *testing.T) {
var tmpFile *os.File
var err error
if tmpFile, err = os.CreateTemp("", "camel-k-"); err != nil {
tempDir := t.TempDir()
if tmpFile, err = os.CreateTemp(tempDir, "camel-k-"); err != nil {
t.Error(err)
}

Expand All @@ -720,7 +727,8 @@ func TestIntegrationServiceAccountName(t *testing.T) {
func TestFileProperties(t *testing.T) {
var tmpFile1 *os.File
var err error
if tmpFile1, err = os.CreateTemp("", "camel-k-*.properties"); err != nil {
tempDir := t.TempDir()
if tmpFile1, err = os.CreateTemp(tempDir, "camel-k-*.properties"); err != nil {
t.Error(err)
}

Expand All @@ -732,7 +740,7 @@ func TestFileProperties(t *testing.T) {
`), 0o400))

var tmpFile *os.File
if tmpFile, err = os.CreateTemp("", "camel-k-"); err != nil {
if tmpFile, err = os.CreateTemp(tempDir, "camel-k-"); err != nil {
t.Error(err)
}

Expand All @@ -752,7 +760,8 @@ func TestFileProperties(t *testing.T) {
func TestPropertyShouldNotExpand(t *testing.T) {
var tmpFile1 *os.File
var err error
if tmpFile1, err = os.CreateTemp("", "camel-k-*.properties"); err != nil {
tempDir := t.TempDir()
if tmpFile1, err = os.CreateTemp(tempDir, "camel-k-*.properties"); err != nil {
t.Error(err)
}

Expand All @@ -762,7 +771,7 @@ func TestPropertyShouldNotExpand(t *testing.T) {
`), 0o400))

var tmpFile *os.File
if tmpFile, err = os.CreateTemp("", "camel-k-"); err != nil {
if tmpFile, err = os.CreateTemp(tempDir, "camel-k-"); err != nil {
t.Error(err)
}

Expand All @@ -784,7 +793,8 @@ func TestPropertyShouldNotExpand(t *testing.T) {
func TestRunOutput(t *testing.T) {
var tmpFile1 *os.File
var err error
if tmpFile1, err = os.CreateTemp("", "camel-k-*.yaml"); err != nil {
tempDir := t.TempDir()
if tmpFile1, err = os.CreateTemp(tempDir, "camel-k-*.yaml"); err != nil {
t.Error(err)
}
defer tmpFile1.Close()
Expand All @@ -811,10 +821,7 @@ func TestRunOutput(t *testing.T) {
}

func TestRunGlob(t *testing.T) {
dir, err := os.MkdirTemp("", "camel-k-TestRunGlob-*")
if err != nil {
t.Error(err)
}
dir := t.TempDir()

pattern := "camel-k-*.yaml"

Expand Down Expand Up @@ -846,10 +853,7 @@ func TestRunGlob(t *testing.T) {
}

func TestRunGlobAllFiles(t *testing.T) {
dir, err := os.MkdirTemp("", "camel-k-TestRunGlobAllFiles-*")
if err != nil {
t.Error(err)
}
dir := t.TempDir()

pattern := "camel-k-*.yaml"

Expand Down Expand Up @@ -881,10 +885,7 @@ func TestRunGlobAllFiles(t *testing.T) {
}

func TestRunGlobChange(t *testing.T) {
dir, err := os.MkdirTemp("", "camel-k-TestRunGlobChange-*")
if err != nil {
t.Error(err)
}
dir := t.TempDir()

pattern := "camel-k-*.yaml"

Expand Down Expand Up @@ -924,7 +925,8 @@ func TestRunGlobChange(t *testing.T) {
}

func TestRunOutputWithoutKubernetesCluster(t *testing.T) {
tmpFile, err := os.CreateTemp("", "camel-k-kubeconfig-*")
tempDir := t.TempDir()
tmpFile, err := os.CreateTemp(tempDir, "camel-k-kubeconfig-*")
require.NoError(t, err)

runCmdOptions, rootCmd, _ := initializeRunCmdOptions(t)
Expand Down
9 changes: 8 additions & 1 deletion pkg/cmd/source/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ func TestPermissionDenied(t *testing.T) {
t.Skip("Test not reliably producing a result on a windows OS")
}

dir, err := os.MkdirTemp("/tmp", "camel-k-")
dir := t.TempDir()

fileInfo, err := os.Stat(dir)
require.NoError(t, err)
originalDirMode := fileInfo.Mode()

filename := filepath.Join(dir, "file.txt")
f, err := os.Create(filename)
Expand All @@ -63,6 +66,10 @@ func TestPermissionDenied(t *testing.T) {
// must not panic because a permission error
require.Error(t, err)
assert.False(t, value)

// restore original directory permissions, so that the Golang test framework can delete it
err = os.Chmod(dir, originalDirMode)
require.NoError(t, err)
}

func TestSupportedScheme(t *testing.T) {
Expand Down
Loading
Loading