diff --git a/go.mod b/go.mod index b32419e..2d2a961 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module git.optclblast.xyz/optclblast/gustav go 1.23.0 require ( - golang.org/x/sync v0.8.0 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect + github.com/davecgh/go-spew v1.1.1 + golang.org/x/sync v0.8.0 + gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index f0318be..bddc0c0 100644 --- a/go.sum +++ b/go.sum @@ -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/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/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/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/config/config.go b/internal/config/config.go index 809bc99..777d53b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -2,3 +2,4 @@ package config type Config struct { } + diff --git a/internal/pipeline/executor.go b/internal/pipeline/executor.go index 7af79fc..6ed19fd 100644 --- a/internal/pipeline/executor.go +++ b/internal/pipeline/executor.go @@ -93,7 +93,7 @@ func prepareShelling[OutT any](ctx context.Context, cc HttpClient, pre Prepare) respBody, err := io.ReadAll(req.Body) 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) diff --git a/internal/pipeline/loader_test.go b/internal/pipeline/loader_test.go new file mode 100644 index 0000000..092d176 --- /dev/null +++ b/internal/pipeline/loader_test.go @@ -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)) + }) + } +} diff --git a/internal/pipeline/reader.go b/internal/pipeline/reader.go index 0ed7eca..904e4de 100644 --- a/internal/pipeline/reader.go +++ b/internal/pipeline/reader.go @@ -37,7 +37,7 @@ func FindPipelines(path string) []string { func LoadPipelines(ctx context.Context, paths []string) ([]*Pipeline, error) { pipelines := make([]*Pipeline, len(paths)) - eg, ctx := errgroup.WithContext(ctx) + eg, _ := errgroup.WithContext(ctx) for i, p := range paths { i := i