forked from raystack/optimus
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test case for maxcompute identifier
- Loading branch information
1 parent
a76da38
commit 2107d4b
Showing
2 changed files
with
64 additions
and
2 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
60 changes: 59 additions & 1 deletion
60
plugin/upstream_identifier/maxcompute_upstream_identifier_test.go
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 |
---|---|---|
@@ -1,3 +1,61 @@ | ||
package upstreamidentifier_test | ||
|
||
// TODO: Implement test | ||
import ( | ||
"context" | ||
"testing" | ||
|
||
upstreamidentifier "github.com/goto/optimus/plugin/upstream_identifier" | ||
"github.com/goto/salt/log" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewMaxcomputeUpstreamIdentifier(t *testing.T) { | ||
logger := log.NewNoop() | ||
parserFunc := func(string) []string { return nil } | ||
evaluatorFunc := func(map[string]string) string { return "" } | ||
t.Run("return error when logger is nil", func(t *testing.T) { | ||
upstreamIdentifier, err := upstreamidentifier.NewMaxcomputeUpstreamIdentifier(nil, parserFunc, evaluatorFunc) | ||
assert.Error(t, err) | ||
assert.Nil(t, upstreamIdentifier) | ||
}) | ||
t.Run("return error when parserFunc is nil", func(t *testing.T) { | ||
upstreamIdentifier, err := upstreamidentifier.NewMaxcomputeUpstreamIdentifier(logger, nil, evaluatorFunc) | ||
assert.Error(t, err) | ||
assert.Nil(t, upstreamIdentifier) | ||
}) | ||
t.Run("return error when no evaluators", func(t *testing.T) { | ||
upstreamIdentifier, err := upstreamidentifier.NewMaxcomputeUpstreamIdentifier(logger, parserFunc) | ||
assert.Error(t, err) | ||
assert.Nil(t, upstreamIdentifier) | ||
}) | ||
t.Run("return error when evaluatorFuncs is nil", func(t *testing.T) { | ||
upstreamIdentifier, err := upstreamidentifier.NewMaxcomputeUpstreamIdentifier(logger, parserFunc, nil) | ||
assert.Error(t, err) | ||
assert.Nil(t, upstreamIdentifier) | ||
}) | ||
t.Run("return success", func(t *testing.T) { | ||
upstreamIdentifier, err := upstreamidentifier.NewMaxcomputeUpstreamIdentifier(logger, parserFunc, evaluatorFunc) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, upstreamIdentifier) | ||
}) | ||
} | ||
|
||
func TestMaxcomputeUpstreamIdentifier_IdentifyResources(t *testing.T) { | ||
ctx := context.Background() | ||
logger := log.NewNoop() | ||
assets := map[string]string{ | ||
"./query.sql": "select 1 from project1.schema1.name1", | ||
} | ||
// TODO: adding failure test cases | ||
t.Run("return success", func(t *testing.T) { | ||
parserFunc := func(string) []string { return []string{"project1.schema1.name1"} } | ||
evaluatorFunc := func(map[string]string) string { return "./query.sql" } | ||
upstreamIdentifier, err := upstreamidentifier.NewMaxcomputeUpstreamIdentifier(logger, parserFunc, evaluatorFunc) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, upstreamIdentifier) | ||
resourceURNs, err := upstreamIdentifier.IdentifyResources(ctx, assets) | ||
assert.NoError(t, err) | ||
assert.Len(t, resourceURNs, 1) | ||
assert.Equal(t, "maxcompute://project1.schema1.name1", resourceURNs[0].String()) | ||
}) | ||
} |