mirror of https://github.com/databricks/cli.git
separate GetFilerForLibraries tests
This commit is contained in:
parent
f919e94bce
commit
9921263928
|
@ -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.
|
// volume is in DAB.
|
||||||
path, locations, ok := findVolumeInBundle(b, "main", "my_schema", "my_volume")
|
path, locations, ok := findVolumeInBundle(b, "main", "my_schema", "my_volume")
|
||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
assert.Equal(t, []dyn.Location{{
|
assert.Equal(t, []dyn.Location{{
|
||||||
File: "volume.yml",
|
File: "volume.yml",
|
||||||
|
Line: 1,
|
||||||
|
Column: 2,
|
||||||
}}, locations)
|
}}, locations)
|
||||||
assert.Equal(t, dyn.MustPathFromString("resources.volumes.foo"), path)
|
assert.Equal(t, dyn.MustPathFromString("resources.volumes.foo"), path)
|
||||||
|
|
||||||
|
@ -388,139 +396,147 @@ func TestFindVolumeInBundle(t *testing.T) {
|
||||||
path, locations, ok = findVolumeInBundle(b, "main", "valuedoesnotmatter", "my_volume")
|
path, locations, ok = findVolumeInBundle(b, "main", "valuedoesnotmatter", "my_volume")
|
||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
assert.Equal(t, []dyn.Location{{
|
assert.Equal(t, []dyn.Location{{
|
||||||
File: "volume.yml",
|
File: "volume.yml",
|
||||||
|
Line: 1,
|
||||||
|
Column: 2,
|
||||||
}}, locations)
|
}}, locations)
|
||||||
assert.Equal(t, dyn.MustPathFromString("resources.volumes.foo"), path)
|
assert.Equal(t, dyn.MustPathFromString("resources.volumes.foo"), path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetFilerForLibraries(t *testing.T) {
|
func TestGetFilerForLibrariesValidWsfs(t *testing.T) {
|
||||||
t.Run("valid wsfs", func(t *testing.T) {
|
b := &bundle.Bundle{
|
||||||
b := &bundle.Bundle{
|
Config: config.Root{
|
||||||
Config: config.Root{
|
Workspace: config.Workspace{
|
||||||
Workspace: config.Workspace{
|
ArtifactPath: "/foo/bar/artifacts",
|
||||||
ArtifactPath: "/foo/bar/artifacts",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
|
}
|
||||||
|
|
||||||
client, uploadPath, diags := GetFilerForLibraries(context.Background(), b)
|
client, uploadPath, diags := GetFilerForLibraries(context.Background(), b)
|
||||||
require.NoError(t, diags.Error())
|
require.NoError(t, diags.Error())
|
||||||
assert.Equal(t, "/foo/bar/artifacts/.internal", uploadPath)
|
assert.Equal(t, "/foo/bar/artifacts/.internal", uploadPath)
|
||||||
|
|
||||||
assert.IsType(t, &filer.WorkspaceFilesClient{}, client)
|
assert.IsType(t, &filer.WorkspaceFilesClient{}, client)
|
||||||
})
|
}
|
||||||
|
|
||||||
t.Run("valid uc volume", func(t *testing.T) {
|
func TestGetFilerForLibrariesValidUcVolume(t *testing.T) {
|
||||||
b := &bundle.Bundle{
|
b := &bundle.Bundle{
|
||||||
Config: config.Root{
|
Config: config.Root{
|
||||||
Workspace: config.Workspace{
|
Workspace: config.Workspace{
|
||||||
ArtifactPath: "/Volumes/main/my_schema/my_volume",
|
ArtifactPath: "/Volumes/main/my_schema/my_volume",
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
|
}
|
||||||
|
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
m.WorkspaceClient.Config = &sdkconfig.Config{}
|
m.WorkspaceClient.Config = &sdkconfig.Config{}
|
||||||
m.GetMockFilesAPI().EXPECT().GetDirectoryMetadataByDirectoryPath(mock.Anything, "/Volumes/main/my_schema/my_volume").Return(nil)
|
m.GetMockFilesAPI().EXPECT().GetDirectoryMetadataByDirectoryPath(mock.Anything, "/Volumes/main/my_schema/my_volume").Return(nil)
|
||||||
b.SetWorkpaceClient(m.WorkspaceClient)
|
b.SetWorkpaceClient(m.WorkspaceClient)
|
||||||
|
|
||||||
client, uploadPath, diags := GetFilerForLibraries(context.Background(), b)
|
client, uploadPath, diags := GetFilerForLibraries(context.Background(), b)
|
||||||
require.NoError(t, diags.Error())
|
require.NoError(t, diags.Error())
|
||||||
assert.Equal(t, "/Volumes/main/my_schema/my_volume/.internal", uploadPath)
|
assert.Equal(t, "/Volumes/main/my_schema/my_volume/.internal", uploadPath)
|
||||||
|
|
||||||
assert.IsType(t, &filer.FilesClient{}, client)
|
assert.IsType(t, &filer.FilesClient{}, client)
|
||||||
})
|
}
|
||||||
|
|
||||||
t.Run("volume not in DAB", func(t *testing.T) {
|
func TestGetFilerForLibrariesVolumeNotInBundle(t *testing.T) {
|
||||||
b := &bundle.Bundle{
|
b := &bundle.Bundle{
|
||||||
Config: config.Root{
|
Config: config.Root{
|
||||||
Workspace: config.Workspace{
|
Workspace: config.Workspace{
|
||||||
ArtifactPath: "/Volumes/main/my_schema/doesnotexist",
|
ArtifactPath: "/Volumes/main/my_schema/doesnotexist",
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
|
}
|
||||||
|
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
m.WorkspaceClient.Config = &sdkconfig.Config{}
|
m.WorkspaceClient.Config = &sdkconfig.Config{}
|
||||||
m.GetMockFilesAPI().EXPECT().GetDirectoryMetadataByDirectoryPath(mock.Anything, "/Volumes/main/my_schema/doesnotexist").Return(fmt.Errorf("error from API"))
|
m.GetMockFilesAPI().EXPECT().GetDirectoryMetadataByDirectoryPath(mock.Anything, "/Volumes/main/my_schema/doesnotexist").Return(fmt.Errorf("error from API"))
|
||||||
b.SetWorkpaceClient(m.WorkspaceClient)
|
b.SetWorkpaceClient(m.WorkspaceClient)
|
||||||
|
|
||||||
_, _, diags := GetFilerForLibraries(context.Background(), b)
|
_, _, 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.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)
|
assert.Len(t, diags, 1)
|
||||||
})
|
}
|
||||||
|
|
||||||
t.Run("volume in DAB config", func(t *testing.T) {
|
func TestGetFilerForLibrariesVolumeInBundle(t *testing.T) {
|
||||||
b := &bundle.Bundle{
|
b := &bundle.Bundle{
|
||||||
Config: config.Root{
|
Config: config.Root{
|
||||||
Workspace: config.Workspace{
|
Workspace: config.Workspace{
|
||||||
ArtifactPath: "/Volumes/main/my_schema/my_volume",
|
ArtifactPath: "/Volumes/main/my_schema/my_volume",
|
||||||
},
|
},
|
||||||
Resources: config.Resources{
|
Resources: config.Resources{
|
||||||
Volumes: map[string]*resources.Volume{
|
Volumes: map[string]*resources.Volume{
|
||||||
"foo": {
|
"foo": {
|
||||||
CreateVolumeRequestContent: &catalog.CreateVolumeRequestContent{
|
CreateVolumeRequestContent: &catalog.CreateVolumeRequestContent{
|
||||||
CatalogName: "main",
|
CatalogName: "main",
|
||||||
Name: "my_volume",
|
Name: "my_volume",
|
||||||
VolumeType: "MANAGED",
|
VolumeType: "MANAGED",
|
||||||
SchemaName: "my_schema",
|
SchemaName: "my_schema",
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
|
}
|
||||||
|
|
||||||
bundletest.SetLocation(b, "resources.volumes.foo", "volume.yml")
|
bundletest.SetLocation(b, "resources.volumes.foo", []dyn.Location{
|
||||||
|
{
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
File: "volume.yml",
|
||||||
m.WorkspaceClient.Config = &sdkconfig.Config{}
|
Line: 1,
|
||||||
m.GetMockFilesAPI().EXPECT().GetDirectoryMetadataByDirectoryPath(mock.Anything, "/Volumes/main/my_schema/my_volume").Return(fmt.Errorf("error from API"))
|
Column: 2,
|
||||||
b.SetWorkpaceClient(m.WorkspaceClient)
|
},
|
||||||
|
|
||||||
_, _, diags := GetFilerForLibraries(context.Background(), b)
|
|
||||||
assert.EqualError(t, diags.Error(), "failed to fetch metadata for the UC volume /Volumes/main/my_schema/my_volume that is configured in the artifact_path: error from API")
|
|
||||||
assert.Contains(t, diags, diag.Diagnostic{
|
|
||||||
Severity: diag.Warning,
|
|
||||||
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",
|
|
||||||
}},
|
|
||||||
Paths: []dyn.Path{dyn.MustPathFromString("resources.volumes.foo")},
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("remote path is not set", func(t *testing.T) {
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
b := &bundle.Bundle{}
|
m.WorkspaceClient.Config = &sdkconfig.Config{}
|
||||||
|
m.GetMockFilesAPI().EXPECT().GetDirectoryMetadataByDirectoryPath(mock.Anything, "/Volumes/main/my_schema/my_volume").Return(fmt.Errorf("error from API"))
|
||||||
|
b.SetWorkpaceClient(m.WorkspaceClient)
|
||||||
|
|
||||||
_, _, diags := GetFilerForLibraries(context.Background(), b)
|
_, _, diags := GetFilerForLibraries(context.Background(), b)
|
||||||
require.EqualError(t, diags.Error(), "remote artifact path not configured")
|
assert.EqualError(t, diags.Error(), "failed to fetch metadata for the UC volume /Volumes/main/my_schema/my_volume that is configured in the artifact_path: error from API")
|
||||||
})
|
assert.Contains(t, diags, diag.Diagnostic{
|
||||||
|
Severity: diag.Warning,
|
||||||
t.Run("invalid volume paths", func(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.",
|
||||||
invalidPaths := []string{
|
Locations: []dyn.Location{{
|
||||||
"/Volumes/",
|
File: "volume.yml",
|
||||||
"/Volumes/main",
|
Line: 1,
|
||||||
"/Volumes/main/",
|
Column: 2,
|
||||||
"/Volumes/main//",
|
}},
|
||||||
"/Volumes/main//my_schema",
|
Paths: []dyn.Path{dyn.MustPathFromString("resources.volumes.foo")},
|
||||||
"/Volumes/main/my_schema",
|
|
||||||
"/Volumes/main/my_schema/",
|
|
||||||
"/Volumes/main/my_schema//",
|
|
||||||
"/Volumes//my_schema/my_volume",
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, p := range invalidPaths {
|
|
||||||
b := &bundle.Bundle{
|
|
||||||
Config: config.Root{
|
|
||||||
Workspace: config.Workspace{
|
|
||||||
ArtifactPath: p,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
_, _, 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")))
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetFilerForLibrariesVolumeInBundleWithArtifactPath(t *testing.T) {
|
||||||
|
b := &bundle.Bundle{}
|
||||||
|
|
||||||
|
_, _, diags := GetFilerForLibraries(context.Background(), b)
|
||||||
|
require.EqualError(t, diags.Error(), "remote artifact path not configured")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetFilerForLibrariesWithInvalidVolumePaths(t *testing.T) {
|
||||||
|
invalidPaths := []string{
|
||||||
|
"/Volumes/",
|
||||||
|
"/Volumes/main",
|
||||||
|
"/Volumes/main/",
|
||||||
|
"/Volumes/main//",
|
||||||
|
"/Volumes/main//my_schema",
|
||||||
|
"/Volumes/main/my_schema",
|
||||||
|
"/Volumes/main/my_schema/",
|
||||||
|
"/Volumes/main/my_schema//",
|
||||||
|
"/Volumes//my_schema/my_volume",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, p := range invalidPaths {
|
||||||
|
b := &bundle.Bundle{
|
||||||
|
Config: config.Root{
|
||||||
|
Workspace: config.Workspace{
|
||||||
|
ArtifactPath: p,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _, 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")))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue