Skip to content

Commit

Permalink
Added tests for remote and local
Browse files Browse the repository at this point in the history
  • Loading branch information
davesavic committed Jan 2, 2024
1 parent 6e4c681 commit 06b460c
Show file tree
Hide file tree
Showing 10 changed files with 436 additions and 21 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ release:
trap - ERR;

.PHONY: release

test:
go test ./... -cover -coverprofile=coverage.out

.PHONY: test
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package cmd

import (
"encoding/json"
"github.com/davesavic/ploy/ploy"
"github.com/davesavic/ploy/pkg/ploy"
"github.com/spf13/cobra"
"log"
"os"
Expand Down
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package cmd
import (
"encoding/json"
"fmt"
"github.com/davesavic/ploy/ploy"
"github.com/davesavic/ploy/pkg/ploy"
"github.com/spf13/cobra"
"log"
"os"
Expand Down
38 changes: 38 additions & 0 deletions coverage.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
mode: set
github.com/davesavic/ploy/pkg/ploy/ploy.go:49.75,51.13 2 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:51.13,53.3 1 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:55.2,57.26 2 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:57.26,59.3 1 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:61.2,61.31 1 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:61.31,65.14 3 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:65.14,67.4 1 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:69.3,70.17 2 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:70.17,72.4 1 0
github.com/davesavic/ploy/pkg/ploy/ploy.go:74.3,75.17 2 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:75.17,77.4 1 0
github.com/davesavic/ploy/pkg/ploy/ploy.go:79.3,88.17 3 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:88.17,90.4 1 0
github.com/davesavic/ploy/pkg/ploy/ploy.go:92.3,92.30 1 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:92.30,94.15 2 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:94.15,96.5 1 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:98.4,98.31 1 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:98.31,101.19 3 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:101.19,103.6 1 0
github.com/davesavic/ploy/pkg/ploy/ploy.go:105.5,106.19 2 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:106.19,108.6 1 0
github.com/davesavic/ploy/pkg/ploy/ploy.go:110.5,112.60 2 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:112.60,114.6 1 0
github.com/davesavic/ploy/pkg/ploy/ploy.go:118.3,118.40 1 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:118.40,120.4 1 0
github.com/davesavic/ploy/pkg/ploy/ploy.go:123.2,123.26 1 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:126.53,130.27 3 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:130.27,132.3 1 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:139.74,143.13 3 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:143.13,145.3 1 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:147.2,147.29 1 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:147.29,149.14 2 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:149.14,151.4 1 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:153.3,153.26 1 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:153.26,160.18 6 1
github.com/davesavic/ploy/pkg/ploy/ploy.go:160.18,162.5 1 0
github.com/davesavic/ploy/pkg/ploy/ploy.go:166.2,166.26 1 1
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ module github.com/davesavic/ploy
go 1.21.4

require (
github.com/gliderlabs/ssh v0.3.6
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
golang.org/x/crypto v0.16.0
golang.org/x/crypto v0.17.0
)

require (
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -7,6 +9,8 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/gliderlabs/ssh v0.3.6 h1:ZzjlDa05TcFRICb3anf/dSPN3ewz1Zx6CMLPWgkm3b8=
github.com/gliderlabs/ssh v0.3.6/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
Expand Down Expand Up @@ -59,8 +63,8 @@ go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
Expand Down
31 changes: 15 additions & 16 deletions ploy/ploy.go → pkg/ploy/ploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ type RemotePipelineExecutor struct {
}

func (r *RemotePipelineExecutor) Execute(pipeline string) (string, error) {
pl := r.Config.Pipelines[pipeline]
pl, exists := r.Config.Pipelines[pipeline]
if !exists {
return "", fmt.Errorf("pipeline %s is not defined", pipeline)
}

var out bytes.Buffer

Expand Down Expand Up @@ -89,7 +92,7 @@ func (r *RemotePipelineExecutor) Execute(pipeline string) (string, error) {
for _, t := range pl.Tasks {
commands, exists := r.Config.Tasks[t]
if !exists {
return "", fmt.Errorf("task %s does not exist", t)
return "", fmt.Errorf("task %s is not defined", t)
}

for _, c := range commands {
Expand Down Expand Up @@ -136,10 +139,18 @@ type LocalPipelineExecutor struct {
func (l *LocalPipelineExecutor) Execute(pipeline string) (string, error) {
var out bytes.Buffer

pl := l.Config.Pipelines[pipeline]
pl, exists := l.Config.Pipelines[pipeline]
if !exists {
return "", fmt.Errorf("pipeline %s is not defined", pipeline)
}

for _, t := range pl.Tasks {
for _, c := range l.Config.Tasks[t] {
task, exists := l.Config.Tasks[t]
if !exists {
return "", fmt.Errorf("task %s is not defined", t)
}

for _, c := range task {
populatePlaceholders(&c, l.Config.Params)
cmd := exec.Command("sh", "-c", c)
cmd.Stdout = &out
Expand All @@ -158,15 +169,3 @@ func (l *LocalPipelineExecutor) Execute(pipeline string) (string, error) {
type Ploy struct {
Config Config
}

func NewPloy(cfg Config) *Ploy {
return &Ploy{Config: cfg}
}

func (p *Ploy) RunRollbackTask(task string) error {
for _, c := range p.Config.Tasks[fmt.Sprintf("rollback-%s", task)] {
fmt.Println("ROLLBACK TASK: ", c)
}

return nil
}
Loading

0 comments on commit 06b460c

Please sign in to comment.