fix unit tests

This commit is contained in:
Shreyas Goenka 2024-09-16 03:00:22 +02:00
parent aa2e16d757
commit a90eb57a5b
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
2 changed files with 14 additions and 6 deletions

View File

@ -131,13 +131,15 @@ func collectLocalLibraries(b *bundle.Bundle) (map[string][]configLocation, error
func (u *upload) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
// If the client is not initialized, initialize it
// We use client field in mutator to allow for mocking client in testing
var uploadPath string
var diags diag.Diagnostics
client, uploadPath, diags := GetFilerForLibraries(ctx, b)
if diags.HasError() {
return diags
}
// Only set the filer client if it's not already set. This allows for using
// a mock client in tests.
if u.client == nil {
u.client, uploadPath, diags = GetFilerForLibraries(ctx, b)
if diags.HasError() {
return diags
}
u.client = client
}
libs, err := collectLocalLibraries(b)
@ -189,6 +191,7 @@ func (u *upload) Name() string {
return "libraries.Upload"
}
// TODO: As a followup add testing for interactive flows.
// This function returns the right filer to use, to upload artifacts to the configured locations.
// Supported locations:
// 1. WSFS

View File

@ -189,6 +189,11 @@ func TestArtifactUploadForVolumes(t *testing.T) {
filer.CreateParentDirectories,
).Return(nil)
m := mocks.NewMockWorkspaceClient(t)
m.WorkspaceClient.Config = &sdkconfig.Config{}
m.GetMockFilesAPI().EXPECT().GetDirectoryMetadataByDirectoryPath(mock.Anything, "/Volumes/foo/bar/artifacts").Return(nil)
b.SetWorkpaceClient(m.WorkspaceClient)
diags := bundle.Apply(context.Background(), b, bundle.Seq(ExpandGlobReferences(), UploadWithClient(mockFiler)))
require.NoError(t, diags.Error())