-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers_test.go
More file actions
60 lines (48 loc) · 1.31 KB
/
helpers_test.go
File metadata and controls
60 lines (48 loc) · 1.31 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
package waitfor
import (
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
func TestUse(t *testing.T) {
// Create a mock module function
mockModule := func() ([]string, ResourceFactory) {
schemes := []string{"mock", "test"}
factory := func(_ *url.URL) (Resource, error) {
return &TestResource{}, nil
}
return schemes, factory
}
// Test Use function
config := Use(mockModule)
assert.Equal(t, []string{"mock", "test"}, config.Scheme)
assert.NotNil(t, config.Factory)
// Test that the factory works
testURL, _ := url.Parse("mock://example")
resource, err := config.Factory(testURL)
assert.NoError(t, err)
assert.NotNil(t, resource)
}
func TestUse_WithEmptySchemes(t *testing.T) {
// Create a module with empty schemes
mockModule := func() ([]string, ResourceFactory) {
schemes := []string{}
factory := func(_ *url.URL) (Resource, error) {
return &TestResource{}, nil
}
return schemes, factory
}
config := Use(mockModule)
assert.Empty(t, config.Scheme)
assert.NotNil(t, config.Factory)
}
func TestUse_WithNilFactory(t *testing.T) {
// Create a module with nil factory
mockModule := func() ([]string, ResourceFactory) {
schemes := []string{"nil"}
return schemes, nil
}
config := Use(mockModule)
assert.Equal(t, []string{"nil"}, config.Scheme)
assert.Nil(t, config.Factory)
}