Skip to content

Commit

Permalink
fix tests and build
Browse files Browse the repository at this point in the history
  • Loading branch information
askolesov committed Sep 29, 2024
1 parent f842f1d commit cf9372e
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 38 deletions.
18 changes: 9 additions & 9 deletions pkg/command/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"time"

v2 "github.com/askolesov/image-vault/pkg/v2"
"github.com/askolesov/image-vault/pkg/util"
"github.com/barasher/go-exiftool"
"github.com/jedib0t/go-pretty/v6/progress"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -53,7 +53,7 @@ func importFiles(cmd *cobra.Command, importPath string, dryRun, errorOnAction bo
}

// Load config
cfg, err := v2.ReadConfigFromFile(DefaultConfigFile)
cfg, err := util.ReadConfigFromFile(DefaultConfigFile)
if err != nil {
return err
}
Expand All @@ -78,7 +78,7 @@ func importFiles(cmd *cobra.Command, importPath string, dryRun, errorOnAction bo

pw.AppendTracker(tracker)

inFilesRel, err := v2.ListFilesRel(pw.Log, importPath, tracker.Increment, cfg.SkipPermissionDenied)
inFilesRel, err := util.ListFilesRel(pw.Log, importPath, tracker.Increment, cfg.SkipPermissionDenied)
if err != nil {
return err
}
Expand All @@ -94,15 +94,15 @@ func importFiles(cmd *cobra.Command, importPath string, dryRun, errorOnAction bo

pw.AppendTracker(tracker)

inFilesRel = v2.FilterIgnore(inFilesRel, cfg.Ignore, tracker.Increment)
inFilesRel = util.FilterIgnore(inFilesRel, cfg.Ignore, tracker.Increment)

tracker.MarkAsDone()

// 3. Link sidecar files

pw.Log("Linking sidecar files")

inFilesRelLinked := v2.LinkSidecars(cfg.SidecarExtensions, inFilesRel)
inFilesRelLinked := util.LinkSidecars(cfg.SidecarExtensions, inFilesRel)

// 4. Shuffle files

Expand Down Expand Up @@ -130,17 +130,17 @@ func importFiles(cmd *cobra.Command, importPath string, dryRun, errorOnAction bo

for _, f := range inFilesRelLinked {
// Copy main file
info, err := v2.ExtractMetadata(et, importPath, f.Path)
info, err := util.ExtractMetadata(et, importPath, f.Path)
if err != nil {
return fmt.Errorf("failed to extract metadata for %s: %w", f.Path, err)
}

targetPath, err := v2.RenderTemplate(cfg.Template, info)
targetPath, err := util.RenderTemplate(cfg.Template, info)
if err != nil {
return fmt.Errorf("failed to render template for %s: %w", f.Path, err)
}

err = v2.SmartCopyFile(
err = util.SmartCopyFile(
pw.Log,
path.Join(importPath, f.Path),
path.Join(libPath, targetPath),
Expand All @@ -155,7 +155,7 @@ func importFiles(cmd *cobra.Command, importPath string, dryRun, errorOnAction bo
for _, sidecar := range f.Sidecars {
// Use the same name as the main file, but with the sidecar extension
sidecarPath := replaceExtension(targetPath, filepath.Ext(sidecar))
err = v2.SmartCopyFile(
err = util.SmartCopyFile(
pw.Log,
path.Join(importPath, sidecarPath),
path.Join(libPath, sidecarPath),
Expand Down
4 changes: 2 additions & 2 deletions pkg/command/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package command
import (
"os"

v2 "github.com/askolesov/image-vault/pkg/v2"
"github.com/askolesov/image-vault/pkg/util"
"github.com/barasher/go-exiftool"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -33,7 +33,7 @@ func showFileInfo(cmd *cobra.Command, target string) error {
return err
}

infos, err := v2.ExtractMetadata(et, dir, target)
infos, err := util.ExtractMetadata(et, dir, target)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"strings"

v2 "github.com/askolesov/image-vault/pkg/v2"
"github.com/askolesov/image-vault/pkg/util"
"github.com/spf13/cobra"
)

Expand All @@ -26,7 +26,7 @@ func GetInitCmd() *cobra.Command {
}

func ensureLibraryInitialized(cmd *cobra.Command) error {
cfgExists, err := v2.IsConfigExists(DefaultConfigFile)
cfgExists, err := util.IsConfigExists(DefaultConfigFile)
if err != nil {
return err
}
Expand Down Expand Up @@ -75,7 +75,7 @@ func initLibrary(cmd *cobra.Command) error {
}

// Write default config to file
err = v2.WriteDefaultConfigToFile(DefaultConfigFile)
err = util.WriteDefaultConfigToFile(DefaultConfigFile)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/compare.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2
package util

import (
"bytes"
Expand Down
6 changes: 4 additions & 2 deletions pkg/util/compare_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2
package util

import (
"os"
Expand All @@ -12,7 +12,9 @@ func TestCompareFiles(t *testing.T) {
if err != nil {
t.Fatalf("Failed to create temp directory: %v", err)
}
defer os.RemoveAll(tempDir)
defer func(path string) {
_ = os.RemoveAll(path)
}(tempDir)

// Helper function to create a file with content
createFile := func(name, content string) string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2
package util

import (
"encoding/json"
Expand Down
8 changes: 4 additions & 4 deletions pkg/util/config_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2
package util

import (
"testing"
Expand All @@ -13,8 +13,8 @@ func TestReadConfigFromString(t *testing.T) {
c = DefaultConfig()
})

require.Equal(t, `{{or .Exif.Make .Exif.DeviceManufacturer "NoMake"}} {{or .Exif.Model .Exif.DeviceModelName "NoModel"}} ({{.Exif.MIMEType | default "unknown/unknown" | splitList "/" | first }})/{{.Exif.DateTimeOriginal | date "2006"}}/{{.Exif.DateTimeOriginal | date "2006-01-02"}}/{{.Exif.DateTimeOriginal | date "2006-01-02_150405"}}_{{.Hash.Md5Short}}{{.Fs.Ext}}`, c.Template)
require.NotEmpty(t, c.Template)
require.Equal(t, true, c.SkipPermissionDenied)
require.Equal(t, []string{"image-vault.yaml"}, c.Ignore)
require.Equal(t, []string{"*.xmp", "*.yaml", "*.json"}, c.SidecarExtensions)
require.NotEmpty(t, c.Ignore)
require.NotEmpty(t, c.SidecarExtensions)
}
2 changes: 1 addition & 1 deletion pkg/util/copy.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2
package util

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/copy_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2
package util

import (
"os"
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/filter.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2
package util

import (
ignore "github.com/sabhiram/go-gitignore"
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/filter_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2
package util

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/list.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2
package util

import (
"os"
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/list_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2
package util

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/metadata.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2
package util

import (
"crypto/md5"
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/metadata_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2
package util

import (
"testing"
Expand Down
7 changes: 3 additions & 4 deletions pkg/util/sidecar.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package v2
package util

import (
"path/filepath"
"strings"

"github.com/askolesov/image-vault/pkg/v1/util"
"github.com/samber/lo"
)

Expand Down Expand Up @@ -49,7 +48,7 @@ func LinkSidecars(
Path: f,
}

pathWithoutExt := util.GetPathWithoutExtension(f)
pathWithoutExt := PathWithoutExtension(f)
if fSidecars, ok := sidecarsByPathWithoutExt[pathWithoutExt]; ok {
fs.Sidecars = fSidecars
}
Expand All @@ -62,7 +61,7 @@ func LinkSidecars(
primariesByPathWithoutExt := lo.GroupBy(primaries, PathWithoutExtension)

for _, f := range sidecars {
pathWithoutExt := util.GetPathWithoutExtension(f)
pathWithoutExt := PathWithoutExtension(f)
if _, ok := primariesByPathWithoutExt[pathWithoutExt]; !ok {
result = append(result, FileWithSidecars{
Path: f,
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/sidecar_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2
package util

import (
"github.com/stretchr/testify/require"
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/template.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2
package util

import (
"bytes"
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/template_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2
package util

import (
"testing"
Expand Down Expand Up @@ -54,7 +54,7 @@ func TestRenderTemplate(t *testing.T) {

t.Run("Test Sprig function index", func(t *testing.T) {
fields := map[string]string{
"type1": "application/json",
"type": "application/json",
}

templateStr := `{{ .type | default "unknown/unknown" | splitList "/" | first }}`
Expand Down

0 comments on commit cf9372e

Please sign in to comment.