MCPcopy
hub / github.com/dapr/dapr / TestLocalLoader_Load

Function TestLocalLoader_Load

pkg/components/loader/localloader_test.go:25–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestLocalLoader_Load(t *testing.T) {
26 t.Run("Test Load 1 Component", func(t *testing.T) {
27 tmp := t.TempDir()
28 require.NoError(t, os.WriteFile(filepath.Join(tmp, "test-component.yaml"), []byte(`
29apiVersion: dapr.io/v1alpha1
30kind: Component
31metadata:
32 name: statestore
33spec:
34 type: state.couchbase
35`), fs.FileMode(0o600)))
36
37 loader := NewLocalLoader("", []string{tmp})
38 components, err := loader.Load(t.Context())
39 require.NoError(t, err)
40 require.Len(t, components, 1)
41 require.Equal(t, "statestore", components[0].Name)
42 })
43
44 t.Run("Test Load Invalid Component YAML no error no components", func(t *testing.T) {
45 tmp := t.TempDir()
46 require.NoError(t, os.WriteFile(filepath.Join(tmp, "test-component.yaml"), []byte(`
47INVALID YAML
48apiVersion: dapr.io/v1alpha1
49kind: Component
50metadata:
51 name: statestore
52spec:
53 type: state.couchbase
54`), fs.FileMode(0o600)))
55
56 loader := NewLocalLoader("", []string{tmp})
57 components, err := loader.Load(t.Context())
58 require.NoError(t, err)
59 require.Empty(t, components)
60 })
61
62 t.Run("Test Non Existent Directory", func(t *testing.T) {
63 loader := NewLocalLoader("", []string{"/non-existent-directory"})
64 _, err := loader.Load(t.Context())
65 require.Error(t, err)
66 })
67}
68
69func TestLocalLoader_Validate(t *testing.T) {
70 t.Run("Test Validate", func(t *testing.T) {

Callers

nothing calls this directly

Calls 7

LoadMethod · 0.95
NewLocalLoaderFunction · 0.85
RunMethod · 0.65
LenMethod · 0.65
ContextMethod · 0.45
EqualMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected