Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update templates tests #2243

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions internal/pkg/service/cli/dialog/use_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (d *useTmplInputsDialog) ask(ctx context.Context, isForTest bool, inputsFil
err := d.groups.VisitInputs(func(group *input.StepsGroupExt, step *input.StepExt, inputDef *input.Input) error {
// Print info about group and select steps
if !group.Announced {
if err := d.announceGroup(group); err != nil {
if err := d.announceGroup(group, isForTest); err != nil {
return err
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@ func (d *useTmplInputsDialog) ask(ctx context.Context, isForTest bool, inputsFil
return d.out, warnings, err
}

func (d *useTmplInputsDialog) announceGroup(group *input.StepsGroupExt) error {
func (d *useTmplInputsDialog) announceGroup(group *input.StepsGroupExt, isForTest bool) error {
// Only once
if group.Announced {
return nil
Expand Down Expand Up @@ -147,8 +147,9 @@ func (d *useTmplInputsDialog) announceGroup(group *input.StepsGroupExt) error {
}
}
}
case !group.AreStepsSelectable():
case !group.AreStepsSelectable() || isForTest:
// Are all steps required? -> skip select box
// Want to test all cases for template test
for stepIndex := range group.Steps {
selectedSteps = append(selectedSteps, stepIndex)
}
Expand All @@ -173,7 +174,7 @@ func (d *useTmplInputsDialog) announceGroup(group *input.StepsGroupExt) error {
}

// Validate steps count
if err := group.ValidateStepsCount(len(group.Steps), len(selectedSteps)); err != nil {
if err := group.ValidateStepsCount(len(group.Steps), len(selectedSteps)); err != nil && !isForTest {
hosekpeter marked this conversation as resolved.
Show resolved Hide resolved
details := errors.NewMultiError()
details.Append(err)
details.Append(errors.Errorf("number of selected steps (%d) is incorrect", len(selectedSteps)))
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/template/test/inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func ReadInputValues(ctx context.Context, tmpl *template.Template, test *templat
inputValues := make(template.InputsValues, 0)
err = tmpl.Inputs().ToExtended().VisitInputs(func(group *input.StepsGroupExt, step *input.StepExt, inputDef *input.Input) error {
var inputValue template.InputValue
if v, found := inputsFile[inputDef.ID]; found {
inputValue, err = template.ParseInputValue(ctx, v, inputDef, true)
if value, found := inputsFile[inputDef.ID]; found {
inputValue, err = template.ParseInputValue(ctx, value, inputDef, true)
if err != nil {
return errors.NewNestedError(err, errors.New("please fix the value in the inputs JSON file"))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
template test create my-template 0.0.1 --test-name one --inputs-file ./inputs.json --test-projects-file ./projects.json
2 changes: 2 additions & 0 deletions test/cli/template-test-create/create-test-exactlyOne/env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TEST_KBC_PROJECTS_LOCK_DIR_NAME=.kac-cli-e2e-test-template-test

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Objects from "keboola/my-template/0.0.1" template:
+ C main/extractor/ex-generic-v2/empty-instance
+ C main/extractor/keboola.ex-db-mysql/with-rows
+ R main/extractor/keboola.ex-db-mysql/with-rows/rows/users
Template "keboola/my-template/0.0.1" has been applied, instance ID: %s
The test was created in folder tests/one.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"version": 2,
"author": {
"name": "Example Author",
"url": "https://example.com"
},
"templates": [
{
"id": "my-template",
"name": "My Template",
"description": "Full workflow to ...",
"path": "my-template",
"versions": [
{
"version": "0.0.1",
"description": "notes",
"stable": false,
"components": [
"keboola.ex-facebook"
],
"path": "v0"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ex-db-mysql-db-host": "host",
"ex-db-mysql-db-password": "##KBC_SECRET_PASSWORD##",
"ex-db-mysql-incremental": false,
"ex-generic-v2-api-base-url": "https://jsonplaceholder.typicode.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### My Template

Full workflow to ...

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# My Template

## Extended description
- of a template for demo purposes
- from the examples in the API documentation

## Some Example
```
with.a.code()
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
parameters: {
api: {
baseUrl: Input("ex-generic-v2-api-base-url"),
},
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
name: "empty " + InstanceIdShort(),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
parameters: {
db: {
host: Input("ex-db-mysql-db-host"),
"#password": Input("ex-db-mysql-db-password"),
},
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
name: "with-rows",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
parameters: {
incremental: Input("ex-db-mysql-incremental"),
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
name: "users",
isDisabled: false,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
stepsGroups: [
{
description: "Default Group",
required: "exactlyOne",
steps: [
{
icon: "common:settings",
name: "Default Step 1",
description: "Default Step 1",
inputs: [
{
id: "ex-generic-v2-api-base-url",
name: "Api BaseUrl",
description: "a",
type: "string",
kind: "input",
default: "https://jsonplaceholder.typicode.com",
},
],
},
{
icon: "common:settings",
name: "Default Step 2",
description: "Default Step 2",
inputs: [
{
id: "ex-db-mysql-db-host",
name: "Db Host",
description: "b",
type: "string",
kind: "input",
default: "mysql.example.com",
},
],
},
{
icon: "common:settings",
name: "Default Step 3",
description: "Default Step 3",
inputs: [
{
id: "ex-db-mysql-incremental",
name: "Incremental",
description: "c",
type: "bool",
kind: "confirm",
default: false,
},
],
},
{
icon: "common:settings",
name: "Default Step 4",
description: "Default Step 4",
inputs: [
{
id: "ex-db-mysql-db-password",
name: "Db Pass",
description: "b",
type: "string",
kind: "hidden",
},
],
},
],
},
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
configurations: [
{
componentId: "ex-generic-v2",
id: ConfigId("empty"),
path: "extractor/ex-generic-v2/empty",
rows: [],
},
{
componentId: "keboola.ex-db-mysql",
id: ConfigId("with-rows"),
path: "extractor/keboola.ex-db-mysql/with-rows",
rows: [
{
id: ConfigRowId("users"),
path: "rows/users",
},
],
},
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"host": "%%TEST_KBC_STORAGE_API_HOST%%",
"project":%%TEST_KBC_PROJECT_ID%%,
"stagingStorage": "%%TEST_KBC_PROJECT_STAGING_STORAGE%%",
"backend": "%%TEST_KBC_PROJECT_BACKEND%%",
"token": "%%TEST_KBC_STORAGE_API_TOKEN%%"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"allBranchesConfigs": [],
"branches": [
{
"branch": {
"name": "Main",
"isDefault": true
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"version": 2,
"author": {
"name": "Example Author",
"url": "https://example.com"
},
"templates": [
{
"id": "my-template",
"name": "My Template",
"description": "Full workflow to ...",
"path": "my-template",
"versions": [
{
"version": "0.0.1",
"description": "notes",
"stable": false,
"components": [
"keboola.ex-facebook"
],
"path": "v0"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ex-db-mysql-db-host": "host",
"ex-db-mysql-db-password": "##KBC_SECRET_PASSWORD##",
"ex-db-mysql-incremental": false,
"ex-generic-v2-api-base-url": "https://jsonplaceholder.typicode.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### My Template

Full workflow to ...

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# My Template

## Extended description
- of a template for demo purposes
- from the examples in the API documentation

## Some Example
```
with.a.code()
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
parameters: {
api: {
baseUrl: Input("ex-generic-v2-api-base-url"),
},
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
name: "empty " + InstanceIdShort(),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
parameters: {
db: {
host: Input("ex-db-mysql-db-host"),
"#password": Input("ex-db-mysql-db-password"),
},
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
name: "with-rows",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
parameters: {
incremental: Input("ex-db-mysql-incremental"),
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
name: "users",
isDisabled: false,
}
Loading
Loading