separate GetFilerForLibraries tests

This commit is contained in:
Shreyas Goenka 2024-10-14 15:18:58 +02:00
parent f919e94bce
commit 9921263928
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
1 changed files with 127 additions and 111 deletions

View File

@ -361,13 +361,21 @@ func TestFindVolumeInBundle(t *testing.T) {
},
}
bundletest.SetLocation(b, "resources.volumes.foo", "volume.yml")
bundletest.SetLocation(b, "resources.volumes.foo", []dyn.Location{
{
File: "volume.yml",
Line: 1,
Column: 2,
},
})
// volume is in DAB.
path, locations, ok := findVolumeInBundle(b, "main", "my_schema", "my_volume")
assert.True(t, ok)
assert.Equal(t, []dyn.Location{{
File: "volume.yml",
Line: 1,
Column: 2,
}}, locations)
assert.Equal(t, dyn.MustPathFromString("resources.volumes.foo"), path)
@ -389,12 +397,13 @@ func TestFindVolumeInBundle(t *testing.T) {
assert.True(t, ok)
assert.Equal(t, []dyn.Location{{
File: "volume.yml",
Line: 1,
Column: 2,
}}, locations)
assert.Equal(t, dyn.MustPathFromString("resources.volumes.foo"), path)
}
func TestGetFilerForLibraries(t *testing.T) {
t.Run("valid wsfs", func(t *testing.T) {
func TestGetFilerForLibrariesValidWsfs(t *testing.T) {
b := &bundle.Bundle{
Config: config.Root{
Workspace: config.Workspace{
@ -408,9 +417,9 @@ func TestGetFilerForLibraries(t *testing.T) {
assert.Equal(t, "/foo/bar/artifacts/.internal", uploadPath)
assert.IsType(t, &filer.WorkspaceFilesClient{}, client)
})
}
t.Run("valid uc volume", func(t *testing.T) {
func TestGetFilerForLibrariesValidUcVolume(t *testing.T) {
b := &bundle.Bundle{
Config: config.Root{
Workspace: config.Workspace{
@ -429,9 +438,9 @@ func TestGetFilerForLibraries(t *testing.T) {
assert.Equal(t, "/Volumes/main/my_schema/my_volume/.internal", uploadPath)
assert.IsType(t, &filer.FilesClient{}, client)
})
}
t.Run("volume not in DAB", func(t *testing.T) {
func TestGetFilerForLibrariesVolumeNotInBundle(t *testing.T) {
b := &bundle.Bundle{
Config: config.Root{
Workspace: config.Workspace{
@ -448,9 +457,9 @@ func TestGetFilerForLibraries(t *testing.T) {
_, _, diags := GetFilerForLibraries(context.Background(), b)
assert.EqualError(t, diags.Error(), "failed to fetch metadata for the UC volume /Volumes/main/my_schema/doesnotexist that is configured in the artifact_path: error from API")
assert.Len(t, diags, 1)
})
}
t.Run("volume in DAB config", func(t *testing.T) {
func TestGetFilerForLibrariesVolumeInBundle(t *testing.T) {
b := &bundle.Bundle{
Config: config.Root{
Workspace: config.Workspace{
@ -471,7 +480,13 @@ func TestGetFilerForLibraries(t *testing.T) {
},
}
bundletest.SetLocation(b, "resources.volumes.foo", "volume.yml")
bundletest.SetLocation(b, "resources.volumes.foo", []dyn.Location{
{
File: "volume.yml",
Line: 1,
Column: 2,
},
})
m := mocks.NewMockWorkspaceClient(t)
m.WorkspaceClient.Config = &sdkconfig.Config{}
@ -485,19 +500,21 @@ func TestGetFilerForLibraries(t *testing.T) {
Summary: "You might be using a UC volume in your artifact_path that is managed by this bundle but which has not been deployed yet. Please deploy the UC volume in a separate bundle deploy before using it in the artifact_path.",
Locations: []dyn.Location{{
File: "volume.yml",
Line: 1,
Column: 2,
}},
Paths: []dyn.Path{dyn.MustPathFromString("resources.volumes.foo")},
})
})
}
t.Run("remote path is not set", func(t *testing.T) {
func TestGetFilerForLibrariesVolumeInBundleWithArtifactPath(t *testing.T) {
b := &bundle.Bundle{}
_, _, diags := GetFilerForLibraries(context.Background(), b)
require.EqualError(t, diags.Error(), "remote artifact path not configured")
})
}
t.Run("invalid volume paths", func(t *testing.T) {
func TestGetFilerForLibrariesWithInvalidVolumePaths(t *testing.T) {
invalidPaths := []string{
"/Volumes/",
"/Volumes/main",
@ -522,5 +539,4 @@ func TestGetFilerForLibraries(t *testing.T) {
_, _, diags := GetFilerForLibraries(context.Background(), b)
require.EqualError(t, diags.Error(), fmt.Sprintf("expected UC volume path to be in the format /Volumes/<catalog>/<schema>/<volume>/..., got %s", path.Join(p, ".internal")))
}
})
}