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

feat: Initial workflow target testing configuration #69

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
27 changes: 27 additions & 0 deletions schemas/workflow.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@
},
"codeSamples": {
"$ref": "#/$defs/codeSamples"
},
"testing": {
"$ref": "#/$defs/testing"
}
},
"required": ["target", "source"]
Expand Down Expand Up @@ -345,6 +348,30 @@
"required": ["apiKey"]
}
}
},
"testing": {
"type": "object",
"additionalProperties": false,
"description": "Target testing configuration. By default, targets are not tested as part of the workflow.",
"properties": {
"enabled": {
"type": "boolean",
"description": "Defaults to false. If true, the target will be tested as part of the workflow."
},
"mockServer": {
"type": "object",
"additionalProperties": false,
"description": "Mock API server configuration for testing. By default and if generated, the mock API server is started before testing and used.",
"properties": {
"enabled": {
"type": "boolean",
"description": "Defaults to true. If false, the mock API server will not be started."
}
},
"required": []
}
},
"required": []
}
}
}
19 changes: 19 additions & 0 deletions workflow/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@ type Target struct {
Output *string `yaml:"output,omitempty"`
Publishing *Publishing `yaml:"publish,omitempty"`
CodeSamples *CodeSamples `yaml:"codeSamples,omitempty"`

// Configuration for target testing. By default, target testing is disabled.
Testing *Testing `yaml:"testing,omitempty"`
}

// Configuration for target testing, such as `go test` for Go targets.
type Testing struct {
// When enabled, the target will be tested as part of the workflow.
Enabled *bool `yaml:"enabled,omitempty"`

// Configuration for mockserver handling during testing. By default, the
// mockserver is enabled.
MockServer *MockServer `yaml:"mockServer,omitempty"`
}

// Configuration for mockserver handling during testing.
type MockServer struct {
// When enabled, the mockserver will be started during testing.
Enabled *bool `yaml:"enabled,omitempty"`
}

type Publishing struct {
Expand Down
32 changes: 32 additions & 0 deletions workflow/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"
"testing"

"github.com/AlekSi/pointer"
"github.com/speakeasy-api/sdk-gen-config/workflow"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -70,6 +71,37 @@ func TestTarget_Validate(t *testing.T) {
},
wantErr: nil,
},
{
name: "target with testing successfully validates",
args: args{
supportedLangs: []string{"typescript"},
target: workflow.Target{
Target: "typescript",
Source: "openapi.yaml",
Testing: &workflow.Testing{
Enabled: pointer.ToBool(true),
},
},
},
wantErr: nil,
},
{
name: "target with testing.mockServer successfully validates",
args: args{
supportedLangs: []string{"typescript"},
target: workflow.Target{
Target: "typescript",
Source: "openapi.yaml",
Testing: &workflow.Testing{
Enabled: pointer.ToBool(true),
MockServer: &workflow.MockServer{
Enabled: pointer.ToBool(false),
},
},
},
},
wantErr: nil,
},
{
name: "missing target fails",
args: args{
Expand Down
44 changes: 43 additions & 1 deletion workflow/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package workflow_test

import (
"fmt"
"gopkg.in/yaml.v3"
"os"
"path/filepath"
"testing"

"gopkg.in/yaml.v3"

"github.com/AlekSi/pointer"
"github.com/speakeasy-api/sdk-gen-config/workflow"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -58,6 +60,46 @@ targets:
},
},
},
{
name: "loads workflow file with target testing",
args: args{
workflowLocation: "test/.speakeasy",
workflowContents: `workflowVersion: 1.0.0
sources:
testSource:
inputs:
- location: "./openapi.yaml"
targets:
typescript:
target: typescript
source: testSource
testing:
enabled: true
`,
workingDir: "test",
},
want: &workflow.Workflow{
Version: "1.0.0",
Sources: map[string]workflow.Source{
"testSource": {
Inputs: []workflow.Document{
{
Location: "./openapi.yaml",
},
},
},
},
Targets: map[string]workflow.Target{
"typescript": {
Target: "typescript",
Source: "testSource",
Testing: &workflow.Testing{
Enabled: pointer.ToBool(true),
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading