Skip to content

Commit

Permalink
feat: Initial workflow target testing configuration (#69)
Browse files Browse the repository at this point in the history
Reference: https://linear.app/speakeasy/issue/GEN-590/feature-workflow-configuration-updates-for-target-testing

This change enables the following opt-in workflow configuration so customers can enable target testing via `speakeasy run` and direct/test mode in GitHub Actions:

```yaml
sources:
  SOURCE_NAME:
    inputs:
      - # ...
targets:
  TARGET_NAME:
    source: SOURCE_NAME
    target: TARGET
    testing:
      enabled: true
```
  • Loading branch information
bflad authored Nov 26, 2024
1 parent 938a4a1 commit fce5153
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 1 deletion.
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

0 comments on commit fce5153

Please sign in to comment.