-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lawrence Zawila <113581282+darkmatterpool@users.noreply.github.com>
- Loading branch information
1 parent
6a0f52f
commit c862071
Showing
14 changed files
with
338 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package dummypay | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestConfigString tests the string representation of the config. | ||
func TestConfigString(t *testing.T) { | ||
t.Parallel() | ||
|
||
config := Config{ | ||
Directory: "test", | ||
FilePollingPeriod: time.Second, | ||
FileGenerationPeriod: time.Minute, | ||
} | ||
|
||
assert.Equal(t, "directory: test, filePollingPeriod: 1s, fileGenerationPeriod: 1m0s", config.String()) | ||
} | ||
|
||
// TestConfigValidate tests the validation of the config. | ||
func TestConfigValidate(t *testing.T) { | ||
t.Parallel() | ||
|
||
var config Config | ||
|
||
// fail on missing directory | ||
assert.EqualError(t, config.Validate(), ErrMissingDirectory.Error()) | ||
|
||
// fail on missing RW access to directory | ||
config.Directory = "/non-existing" | ||
assert.Error(t, config.Validate()) | ||
|
||
// set directory with RW access | ||
userHomeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
config.Directory = userHomeDir | ||
|
||
// fail on invalid file polling period | ||
config.FilePollingPeriod = -1 | ||
assert.ErrorIs(t, config.Validate(), ErrFilePollingPeriodInvalid) | ||
|
||
// fail on invalid file generation period | ||
config.FilePollingPeriod = 1 | ||
config.FileGenerationPeriod = -1 | ||
assert.ErrorIs(t, config.Validate(), ErrFileGenerationPeriodInvalid) | ||
|
||
// success | ||
config.FileGenerationPeriod = 1 | ||
assert.NoError(t, config.Validate()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package dummypay | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/numary/go-libs/sharedlogging" | ||
payments "github.com/numary/payments/pkg" | ||
"github.com/numary/payments/pkg/bridge/task" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// Create a minimal mock for connector installation | ||
type ( | ||
mockConnectorContext[TaskDescriptor payments.TaskDescriptor] struct { | ||
ctx context.Context | ||
} | ||
mockScheduler[TaskDescriptor payments.TaskDescriptor] struct{} | ||
) | ||
|
||
func (mcc *mockConnectorContext[TaskDescriptor]) Context() context.Context { | ||
return mcc.ctx | ||
} | ||
|
||
func (s mockScheduler[TaskDescriptor]) Schedule(p TaskDescriptor, restart bool) error { | ||
return nil | ||
} | ||
|
||
func (mcc *mockConnectorContext[TaskDescriptor]) Scheduler() task.Scheduler[TaskDescriptor] { | ||
return mockScheduler[TaskDescriptor]{} | ||
} | ||
|
||
func TestConnector(t *testing.T) { | ||
t.Parallel() | ||
|
||
config := Config{} | ||
logger := sharedlogging.GetLogger(context.Background()) | ||
|
||
fs := newTestFS() | ||
|
||
connector := NewConnector(logger, config, fs) | ||
|
||
err := connector.Install(new(mockConnectorContext[TaskDescriptor])) | ||
assert.NoErrorf(t, err, "Install() failed: %v") | ||
|
||
testCases := []struct { | ||
key taskKey | ||
task task.Task | ||
}{ | ||
{taskKeyReadFiles, taskReadFiles(config, fs)}, | ||
{taskKeyGenerateFiles, taskGenerateFiles(config, fs)}, | ||
{taskKeyIngest, taskIngest(config, TaskDescriptor{}, fs)}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
assert.EqualValues(t, | ||
reflect.ValueOf(testCase.task).String(), | ||
reflect.ValueOf(connector.Resolve(TaskDescriptor{Key: testCase.key})).String(), | ||
) | ||
} | ||
|
||
assert.EqualValues(t, | ||
reflect.ValueOf(func() error { return nil }).String(), | ||
reflect.ValueOf(connector.Resolve(TaskDescriptor{Key: "test"})).String(), | ||
) | ||
|
||
assert.NoError(t, connector.Uninstall(context.Background())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package dummypay | ||
|
||
import ( | ||
"github.com/spf13/afero" | ||
) | ||
|
||
type fs afero.Fs | ||
|
||
// newFS creates a new file system access point. | ||
func newFS() fs { | ||
return afero.NewOsFs() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package dummypay | ||
|
||
import "github.com/spf13/afero" | ||
|
||
func newTestFS() fs { | ||
fs := newFS() | ||
fs = afero.NewMemMapFs() | ||
|
||
return fs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package dummypay | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/numary/go-libs/sharedlogging" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestLoader tests the loader. | ||
func TestLoader(t *testing.T) { | ||
t.Parallel() | ||
|
||
config := Config{} | ||
logger := sharedlogging.GetLogger(context.Background()) | ||
|
||
loader := NewLoader() | ||
|
||
assert.Equal(t, connectorName, loader.Name()) | ||
assert.Equal(t, 10, loader.AllowTasks()) | ||
assert.Equal(t, Config{ | ||
FilePollingPeriod: 10 * time.Second, | ||
FileGenerationPeriod: 5 * time.Second, | ||
}, loader.ApplyDefaults(config)) | ||
|
||
assert.EqualValues(t, NewConnector(logger, config, newFS()), loader.Load(logger, config)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.