Compare commits

...

1 Commits

Author SHA1 Message Date
4ba6b8be86 yaml parsing tests (still failing) 2024-10-03 00:20:06 +03:00
6 changed files with 103 additions and 6 deletions

5
go.mod
View File

@ -3,6 +3,7 @@ module git.optclblast.xyz/optclblast/gustav
go 1.23.0 go 1.23.0
require ( require (
golang.org/x/sync v0.8.0 // indirect github.com/davecgh/go-spew v1.1.1
gopkg.in/yaml.v2 v2.4.0 // indirect golang.org/x/sync v0.8.0
gopkg.in/yaml.v3 v3.0.1
) )

5
go.sum
View File

@ -1,7 +1,8 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -2,3 +2,4 @@ package config
type Config struct { type Config struct {
} }

View File

@ -93,7 +93,7 @@ func prepareShelling[OutT any](ctx context.Context, cc HttpClient, pre Prepare)
respBody, err := io.ReadAll(req.Body) respBody, err := io.ReadAll(req.Body)
if err != nil { if err != nil {
return nil, fmt.Errorf("[%s] failed to read response body: %w", err) return nil, fmt.Errorf("[%s] failed to read response body: %w", op, err)
} }
out := new(OutT) out := new(OutT)

View File

@ -0,0 +1,94 @@
package pipeline
import (
"fmt"
"testing"
"github.com/davecgh/go-spew/spew"
"gopkg.in/yaml.v3"
)
func TestLoader(t *testing.T) {
type args struct {
yaml string
}
tests := []struct {
name string
args args
want *Pipeline
wantErr bool
}{
{
name: "example pipeline",
args: args{
yaml: `
name: "My pipeline" # The name of pipeline
description: "Test pipeline"
steps: # Steps
step1:
# The preparatory phase of our pipeline. Here we can perform authorizations and other actions that must
# be performed BEFORE the main part.
prepare:
type: "http_call" # Call type.
expected_codes: [200] # Expected return codes
# The name of the variable in which the result of this call will be stored.
# This value will be accessible only in scope of current stop.
save_into: "prepare_step1_result"
# The name of the variable in which the result of this call will be stored.
# This value will be accessible globally.
global_save_into: "global_variable"
call: # Request configuration
target: "http://127.0.0.1:8080/login" # Endpoint
headers:
secret: "xxx"
logon-with: "password"
method: "POST"
body: |-
{
"login":"admin",
"password":"password"
}
repeat: 1000
# The main part of the step. The set of requests that will be executed.
# They will be looped until the repeat number reached`,
},
want: &Pipeline{
Name: "My pipeline",
Description: "Test pipeline",
Steps: []Step{{
Name: "",
Repeat: 1000,
Prepare: Prepare{
Type: "http_call",
ExpectedCodes: []int{200},
SaveInto: "prepare_step1_result",
GlobalSaveInto: "global_variable",
Call: Call{
Target: "http://127.0.0.1:8080/login",
Headers: map[string]string{
"secret": "xxx",
"logon-with": "password",
},
Method: "POST",
Body: []byte("{\"login\":\"admin\",\"password\":\"password\"}"),
},
},
}},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pipeline := new(Pipeline)
if err := yaml.Unmarshal([]byte(tt.args.yaml), pipeline); err != nil {
t.Fatal(fmt.Errorf("failed to unmarshall pipeline: %v", err))
}
t.Logf("pipeline: %v", spew.Sdump(pipeline))
})
}
}

View File

@ -37,7 +37,7 @@ func FindPipelines(path string) []string {
func LoadPipelines(ctx context.Context, paths []string) ([]*Pipeline, error) { func LoadPipelines(ctx context.Context, paths []string) ([]*Pipeline, error) {
pipelines := make([]*Pipeline, len(paths)) pipelines := make([]*Pipeline, len(paths))
eg, ctx := errgroup.WithContext(ctx) eg, _ := errgroup.WithContext(ctx)
for i, p := range paths { for i, p := range paths {
i := i i := i