-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy_test.go
More file actions
126 lines (113 loc) · 4.19 KB
/
Copy pathcopy_test.go
File metadata and controls
126 lines (113 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package barge_test
import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"testing"
"github.com/frantjc/barge"
_ "github.com/frantjc/barge/internal/archive"
_ "github.com/frantjc/barge/internal/directory"
_ "github.com/frantjc/barge/internal/file"
_ "github.com/frantjc/barge/internal/http"
_ "github.com/frantjc/barge/internal/oci"
_ "github.com/frantjc/barge/internal/repo"
"github.com/frantjc/barge/testdata"
"github.com/stretchr/testify/require"
"helm.sh/helm/v3/pkg/chart/loader"
)
func TestCopyArchive(t *testing.T) {
ctx := Context(t)
_, archive := Archive(t)
directory := fmt.Sprintf("directory://%s", t.TempDir())
require.NoError(t, barge.Copy(ctx, archive.String(), directory))
}
func TestCopyDirectory(t *testing.T) {
ctx := Context(t)
_, archive := Archive(t)
directory := fmt.Sprintf("directory://%s", t.TempDir())
require.NoError(t, barge.Copy(ctx, archive.String(), directory))
require.NoError(t, barge.Copy(ctx, directory, t.TempDir()))
}
func TestCopyFile(t *testing.T) {
ctx := Context(t)
archiveChart, archive := Archive(t)
file := fmt.Sprintf("file://%s/%s-%s.tgz", t.TempDir(), archiveChart.Name(), archiveChart.Metadata.Version)
require.NoError(t, barge.Copy(ctx, archive.String(), file))
require.NoError(t, barge.Copy(ctx, file, t.TempDir()))
fileDir := fmt.Sprintf("file://%s", t.TempDir())
require.NoError(t, barge.Copy(ctx, archive.String(), fileDir))
require.NoError(t, barge.Copy(ctx, fileDir, t.TempDir()))
}
func TestCopyDefault(t *testing.T) {
ctx := Context(t)
archiveChart, archive := Archive(t)
file := fmt.Sprintf("%s/%s-%s.tgz", t.TempDir(), archiveChart.Name(), archiveChart.Metadata.Version)
require.NoError(t, barge.Copy(ctx, archive.String(), file))
require.NoError(t, barge.Copy(ctx, file, t.TempDir()))
fileDir := t.TempDir()
require.NoError(t, barge.Copy(ctx, archive.String(), fileDir))
require.NoError(t, barge.Copy(ctx, fileDir, t.TempDir()))
}
func TestCopyHTTP(t *testing.T) {
ctx := Context(t)
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write(testdata.ChartArchive)
}))
t.Cleanup(srv.Close)
archiveChart, _ := Archive(t)
chartURL := fmt.Sprintf("%s/%s-%s.tgz", srv.URL, archiveChart.Name(), archiveChart.Metadata.Version)
require.NoError(t, barge.Copy(ctx, chartURL, t.TempDir()))
}
func TestCopyRepo(t *testing.T) {
ctx := Context(t)
archiveChart, _ := Archive(t)
repoName, _ := Repo(t, archiveChart)
require.NoError(t, barge.Copy(ctx, fmt.Sprintf("repo://%s/%s?version=%s", repoName, archiveChart.Name(), archiveChart.Metadata.Version), t.TempDir()))
}
func TestCopyOCI(t *testing.T) {
ctx := Context(t)
_, archive := Archive(t)
oci := OCI(t).JoinPath("test")
require.NoError(t, barge.Copy(ctx, archive.String(), oci.String()))
require.NoError(t, barge.Copy(ctx, oci.String(), t.TempDir()))
}
func TestCopyErrorUnknownScheme(t *testing.T) {
ctx := Context(t)
require.Error(t, barge.Copy(ctx, "foo://", t.TempDir()))
require.Error(t, barge.Copy(ctx, fmt.Sprintf("file://%s", t.TempDir()), "bar://"))
}
func TestCopyErrorInvalid(t *testing.T) {
ctx := Context(t)
_, archive := Archive(t)
ociURL := &url.URL{Scheme: "oci", Host: "does-not-exist"}
require.Error(t, barge.Copy(ctx, archive.String(), ociURL.String()))
}
func TestCopyBeforeEqualToAfter(t *testing.T) {
ctx := Context(t)
expected, archive := Archive(t)
tmp := t.TempDir()
directory := fmt.Sprintf("directory://%s", tmp)
require.NoError(t, barge.Copy(ctx, archive.String(), directory))
actual, err := loader.LoadDir(tmp)
require.NoError(t, err)
ChartsEqual(t, expected, actual)
}
func TestCopyPreservesSchema(t *testing.T) {
ctx := Context(t)
chart, archive := Archive(t)
expected := map[string]any{}
require.NoError(t, json.Unmarshal(chart.Schema, &expected))
tmp := t.TempDir()
directory := fmt.Sprintf("directory://%s", tmp)
require.NoError(t, barge.Copy(ctx, archive.String(), directory))
rawValuesSchemaJSON, err := os.ReadFile(filepath.Join(tmp, "values.schema.json"))
require.NoError(t, err)
actual := map[string]any{}
require.NoError(t, json.Unmarshal(rawValuesSchemaJSON, &actual))
require.Equal(t, expected, actual)
require.Equal(t, chart.Schema, rawValuesSchemaJSON)
}