Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hosekpeter committed Jan 23, 2025
1 parent 91d61b3 commit 2d059bc
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/pkg/service/templates/api/service/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ func ComponentsResponse(d dependencies.ProjectRequestScope, in []string) (out []
componentId = function.SnowflakeWriterIDAws.String()
} else if _, found := d.Components().Get(function.SnowflakeWriterIDAzure); found {
componentId = function.SnowflakeWriterIDAzure.String()
} else if _, found := d.Components().Get(function.SnowflakeWriterIDGCPS3); found && slices.Contains(d.ProjectBackends(), project.BackendSnowflake) {
componentId = function.SnowflakeWriterIDGCPS3.String()
} else if _, found := d.Components().Get(function.SnowflakeWriterIDGCP); found && slices.Contains(d.ProjectBackends(), project.BackendBigQuery) {
componentId = function.SnowflakeWriterIDGCP.String()
} else {
continue
}
Expand Down
84 changes: 84 additions & 0 deletions internal/pkg/service/templates/api/service/mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/keboola/keboola-as-code/internal/pkg/service/templates/api/config"
"github.com/keboola/keboola-as-code/internal/pkg/service/templates/api/gen/templates"
"github.com/keboola/keboola-as-code/internal/pkg/service/templates/dependencies"
"github.com/keboola/keboola-as-code/internal/pkg/template/jsonnet/function"
"github.com/keboola/keboola-as-code/internal/pkg/template/repository/manifest"
)

func TestTemplatesResponse(t *testing.T) {
Expand Down Expand Up @@ -92,3 +94,85 @@ func TestTemplatesResponse(t *testing.T) {
})
}
}

func TestComponentsResponse(t *testing.T) {
t.Parallel()

type testCase struct {
name string
inputComponents []string
projectBackends commonDeps.MockedOption
mockComponents keboola.Components
expectedOutput []string
}

cases := []testCase{
//{
// name: "no components",
// inputComponents: []string{},
// projectBackends: nil,
// mockComponents: nil,
// expectedOutput: []string{},
// },
//{
// name: "single component",
// inputComponents: []string{"component1"},
// projectBackends: nil,
// mockComponents: keboola.Components{{ComponentKey: keboola.ComponentKey{ID: "component1"}}},
// expectedOutput: []string{"component1"},
// },
{
name: "placeholder component",
inputComponents: []string{manifest.SnowflakeWriterComponentIDPlaceholder},
projectBackends: commonDeps.WithSnowflakeBackend(),
mockComponents: keboola.Components{{ComponentKey: keboola.ComponentKey{ID: function.SnowflakeWriterIDAws}}},
expectedOutput: []string{function.SnowflakeWriterIDAws.String()},
},
{
name: "placeholder component not found",
inputComponents: []string{manifest.SnowflakeWriterComponentIDPlaceholder},
projectBackends: commonDeps.WithSnowflakeBackend(),
mockComponents: keboola.Components{},
expectedOutput: []string{},
},
{
name: "multiple components with placeholders",
inputComponents: []string{"component1", manifest.SnowflakeWriterComponentIDPlaceholder, "component2"},
projectBackends: commonDeps.WithSnowflakeBackend(),
mockComponents: keboola.Components{
{ComponentKey: keboola.ComponentKey{ID: "component1"}},
{ComponentKey: keboola.ComponentKey{ID: function.SnowflakeWriterIDAws}},
{ComponentKey: keboola.ComponentKey{ID: "component2"}},
},
expectedOutput: []string{"component1", function.SnowflakeWriterIDAws.String(), "component2"},
},
{
name: "bigquery component",
inputComponents: []string{manifest.SnowflakeWriterComponentIDPlaceholder},
projectBackends: commonDeps.WithBigQueryBackend(),
mockComponents: keboola.Components{{ComponentKey: keboola.ComponentKey{ID: function.SnowflakeWriterIDGCP}}},
expectedOutput: []string{function.SnowflakeWriterIDGCP.String()},
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

d, _ := dependencies.NewMockedProjectRequestScope(
t,
ctx,
config.New(),
commonDeps.WithMockedComponents(tc.mockComponents),
tc.projectBackends,
)

actualOutput := ComponentsResponse(d, tc.inputComponents)

assert.Equal(t, tc.expectedOutput, actualOutput)
})
}
}

0 comments on commit 2d059bc

Please sign in to comment.