Skip to content

Commit

Permalink
adding more tests to activities
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzelei committed Nov 2, 2023
1 parent b4932e5 commit 9db8edc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
12 changes: 5 additions & 7 deletions worker/pkg/workflows/datasync/activities/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,12 +707,10 @@ func areAllColsNull(mappings []*mgmtv1alpha1.JobMapping) bool {
}

func buildPlainColumns(mappings []*mgmtv1alpha1.JobMapping) []string {
columns := []string{}

for _, col := range mappings {
columns = append(columns, col.Column)
columns := make([]string, len(mappings))
for idx := range mappings {
columns[idx] = mappings[idx].Column
}

return columns
}

Expand Down Expand Up @@ -960,8 +958,8 @@ func buildPlainInsertArgs(cols []string) string {
return ""
}
pieces := make([]string, len(cols))
for idx, col := range cols {
pieces[idx] = fmt.Sprintf("this.%s", col)
for idx := range cols {
pieces[idx] = fmt.Sprintf("this.%s", cols[idx])
}
return fmt.Sprintf("root = [%s]", strings.Join(pieces, ", "))
}
Expand Down
30 changes: 30 additions & 0 deletions worker/pkg/workflows/datasync/activities/activities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,33 @@ output:
err = val.Get(res)
require.NoError(t, err)
}

func Test_buildPlainInsertArgs(t *testing.T) {
assert.Empty(t, buildPlainInsertArgs(nil))
assert.Empty(t, buildPlainInsertArgs([]string{}))
assert.Equal(t, buildPlainInsertArgs([]string{"foo", "bar", "baz"}), "root = [this.foo, this.bar, this.baz]")
}

func Test_buildPlainColumns(t *testing.T) {
assert.Empty(t, buildPlainColumns(nil))
assert.Empty(t, buildPlainColumns([]*mgmtv1alpha1.JobMapping{}))
assert.Equal(
t,
buildPlainColumns([]*mgmtv1alpha1.JobMapping{
{Column: "foo"},
{Column: "bar"},
{Column: "baz"},
}),
[]string{"foo", "bar", "baz"},
)
}

func Test_splitTableKey(t *testing.T) {
schema, table := splitTableKey("foo")
assert.Equal(t, schema, "public")
assert.Equal(t, table, "foo")

schema, table = splitTableKey("neosync.foo")
assert.Equal(t, schema, "neosync")
assert.Equal(t, table, "foo")
}

0 comments on commit 9db8edc

Please sign in to comment.