handle os.ErrNotExist; update tests

This commit is contained in:
Denis Bilenko 2024-12-10 16:20:28 +01:00
parent 1789cca2cb
commit 1e7d06cc3e
2 changed files with 7 additions and 3 deletions

View File

@ -2,6 +2,8 @@ package mutator
import ( import (
"context" "context"
"errors"
"os"
"path/filepath" "path/filepath"
"github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle"
@ -24,7 +26,9 @@ func (m *loadGitDetails) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagn
var diags diag.Diagnostics var diags diag.Diagnostics
info, err := git.FetchRepositoryInfo(ctx, b.BundleRoot.Native(), b.WorkspaceClient()) info, err := git.FetchRepositoryInfo(ctx, b.BundleRoot.Native(), b.WorkspaceClient())
if err != nil { if err != nil {
diags = append(diags, diag.WarningFromErr(err)...) if !errors.Is(err, os.ErrNotExist) {
diags = append(diags, diag.WarningFromErr(err)...)
}
} }
if info.WorktreeRoot == "" { if info.WorktreeRoot == "" {

View File

@ -101,7 +101,7 @@ func TestAccFetchRepositoryInfoAPI_FromNonRepo(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
} else { } else {
assert.Error(t, err) assert.Error(t, err)
assert.Contains(t, err.Error(), test.msg) assert.ErrorContains(t, err, test.msg)
} }
assertEmptyGitInfo(t, info) assertEmptyGitInfo(t, info)
}) })
@ -151,7 +151,7 @@ func TestAccFetchRepositoryInfoDotGit_FromNonGitRepo(t *testing.T) {
for _, input := range tests { for _, input := range tests {
t.Run(input, func(t *testing.T) { t.Run(input, func(t *testing.T) {
info, err := git.FetchRepositoryInfo(ctx, input, wt.W) info, err := git.FetchRepositoryInfo(ctx, input, wt.W)
assert.NoError(t, err) assert.ErrorIs(t, err, os.ErrNotExist)
assertEmptyGitInfo(t, info) assertEmptyGitInfo(t, info)
}) })
} }