-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support relative paths in artifact files source section and always up…
…load all artifact files (#1247) Support relative paths in artifact files source section and always upload all artifact files Fixes #1156 ## Tests Added unit tests
- Loading branch information
1 parent
09d1846
commit ecf9c52
Showing
4 changed files
with
138 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package artifacts | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/databricks/cli/bundle" | ||
"github.com/databricks/cli/bundle/config" | ||
"github.com/databricks/cli/bundle/internal/bundletest" | ||
"github.com/databricks/cli/libs/testfile" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type noop struct{} | ||
|
||
func (n *noop) Apply(context.Context, *bundle.Bundle) error { | ||
return nil | ||
} | ||
|
||
func (n *noop) Name() string { | ||
return "noop" | ||
} | ||
|
||
func TestExpandGlobFilesSource(t *testing.T) { | ||
rootPath := t.TempDir() | ||
err := os.Mkdir(filepath.Join(rootPath, "test"), 0755) | ||
require.NoError(t, err) | ||
|
||
t1 := testfile.CreateFile(t, filepath.Join(rootPath, "test", "myjar1.jar")) | ||
t1.Close(t) | ||
|
||
t2 := testfile.CreateFile(t, filepath.Join(rootPath, "test", "myjar2.jar")) | ||
t2.Close(t) | ||
|
||
b := &bundle.Bundle{ | ||
Config: config.Root{ | ||
Path: rootPath, | ||
Artifacts: map[string]*config.Artifact{ | ||
"test": { | ||
Type: "custom", | ||
Files: []config.ArtifactFile{ | ||
{ | ||
Source: filepath.Join("..", "test", "*.jar"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
bundletest.SetLocation(b, ".", filepath.Join(rootPath, "resources", "artifacts.yml")) | ||
|
||
u := &upload{"test"} | ||
uploadMutators[config.ArtifactType("custom")] = func(name string) bundle.Mutator { | ||
return &noop{} | ||
} | ||
|
||
err = bundle.Apply(context.Background(), b, u) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, 2, len(b.Config.Artifacts["test"].Files)) | ||
require.Equal(t, filepath.Join(rootPath, "test", "myjar1.jar"), b.Config.Artifacts["test"].Files[0].Source) | ||
require.Equal(t, filepath.Join(rootPath, "test", "myjar2.jar"), b.Config.Artifacts["test"].Files[1].Source) | ||
} | ||
|
||
func TestExpandGlobFilesSourceWithNoMatches(t *testing.T) { | ||
rootPath := t.TempDir() | ||
err := os.Mkdir(filepath.Join(rootPath, "test"), 0755) | ||
require.NoError(t, err) | ||
|
||
b := &bundle.Bundle{ | ||
Config: config.Root{ | ||
Path: rootPath, | ||
Artifacts: map[string]*config.Artifact{ | ||
"test": { | ||
Type: "custom", | ||
Files: []config.ArtifactFile{ | ||
{ | ||
Source: filepath.Join("..", "test", "myjar.jar"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
bundletest.SetLocation(b, ".", filepath.Join(rootPath, "resources", "artifacts.yml")) | ||
|
||
u := &upload{"test"} | ||
uploadMutators[config.ArtifactType("custom")] = func(name string) bundle.Mutator { | ||
return &noop{} | ||
} | ||
|
||
err = bundle.Apply(context.Background(), b, u) | ||
require.ErrorContains(t, err, "no files found for") | ||
} |