Skip to content

Commit

Permalink
Added ability to support different genesis command syntax based upon …
Browse files Browse the repository at this point in the history
…the genesis command version (#20)

* update results and ginkgo v2 support
* allow for versioned genesis commands (v2 and v3)
  • Loading branch information
norman-abramovitz authored May 23, 2024
1 parent 337fb44 commit 6556ecc
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 9 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/genesis-community/testkit/v2
go 1.22

require (
github.com/blang/semver/v4 v4.0.0
github.com/egymgmbh/go-prefix-writer v0.0.0-20180609083313-7326ea162eca
github.com/gonvenience/ytbx v1.4.4
github.com/homeport/dyff v1.7.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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=
Expand Down
3 changes: 3 additions & 0 deletions internal/spec/results/baseline.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
exodus:
bosh: baseline
features: ""
is_director: false
use_create_env: false
instance_groups:
- azs:
- z1
Expand Down
3 changes: 3 additions & 0 deletions internal/spec/results/bosh-variables.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
exodus:
bosh: bosh-variables
features: bosh-variables
is_director: false
use_create_env: false
instance_groups:
- azs:
- z1
Expand Down
3 changes: 3 additions & 0 deletions internal/spec/results/credhub-vars.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
exodus:
bosh: credhub-vars
features: credhub-vars
is_director: false
use_create_env: false
instance_groups:
- azs:
- z1
Expand Down
3 changes: 3 additions & 0 deletions internal/spec/results/credhub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
exodus:
bosh: credhub
features: credhub
is_director: false
use_create_env: false
instance_groups:
- azs:
- z1
Expand Down
3 changes: 3 additions & 0 deletions internal/spec/results/detect-cpi.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
exodus:
bosh: detect-cpi
features: detect-cpi
is_director: false
use_create_env: false
instance_groups:
- azs:
- z1
Expand Down
3 changes: 3 additions & 0 deletions internal/spec/results/openvpn.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
exodus:
bosh: openvpn
features: openvpn
is_director: false
use_create_env: false
instance_groups:
- azs:
- z1
Expand Down
3 changes: 3 additions & 0 deletions internal/spec/results/ops-override.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
exodus:
bosh: ops-override
features: test-ops-override
is_director: false
use_create_env: false
instance_groups:
- azs:
- z1
Expand Down
3 changes: 3 additions & 0 deletions internal/spec/results/provided-user.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
exodus:
bosh: provided-user
features: provided-user
is_director: false
use_create_env: false
instance_groups:
- azs:
- z1
Expand Down
5 changes: 3 additions & 2 deletions internal/spec/results/test-exodus.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
exodus:
bosh:
ca: cert
bosh: test-exodus
features: exodus
is_director: false
not_filtered: this property should end up in result
use_create_env: false
instance_groups:
- azs:
- z1
Expand Down
11 changes: 6 additions & 5 deletions internal/spec/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import (
"runtime"

. "github.com/genesis-community/testkit/v2/testing"
. "github.com/onsi/ginkgo/v2
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = BeforeSuite(func() {
_, filename, _, _ := runtime.Caller(0)
KitDir, _ = filepath.Abs(filepath.Join(filepath.Dir(filename), "../"))
})

var _ = Describe("Interal Kit", func() {
BeforeSuite(func() {
_, filename, _, _ := runtime.Caller(0)
KitDir, _ = filepath.Abs(filepath.Join(filepath.Dir(filename), "../"))
})

Test(Environment{
Name: "baseline",
Expand Down
31 changes: 29 additions & 2 deletions testing/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
"path/filepath"
"strings"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

// gojq only works with v3
"github.com/blang/semver/v4"
"gopkg.in/yaml.v3"
)

Expand All @@ -27,6 +29,7 @@ type genesis struct {
environment Environment
workDir string
logger *log.Logger
version semver.Version
}

type manifestResult struct {
Expand Down Expand Up @@ -57,9 +60,28 @@ func newGenesis(environment Environment, workDir string, logger *log.Logger) *ge
logger: logger,
}

g.genesisVersion()
g.init()
return &g
}
func (g *genesis) genesisVersion() {
buf, code := g.genesis("version").RunWithoutMatcher()
if code == 0 {
words := strings.Fields(string(buf))
if len(words) > 1 && words[0] == "Genesis" {
if gsemver, err := semver.ParseTolerant(words[1]); err == nil {
g.version = gsemver
} else {
AbortSuite(fmt.Sprintf("Genesis version did not return its version. exitcode: %v returned %v\n", code, string(buf)), 1)
}

} else {
AbortSuite(fmt.Sprintf("Genesis version returned unexpected output. exitcode: %v returned %v\n", code, string(buf)), 1)
}
} else {
AbortSuite(fmt.Sprintf("Genesis version failed to run cleanly. exitcode: %v returned %v\n", code, string(buf)), 1)
}
}

func (g *genesis) init() {
g.logger.Println(fmt.Sprintf("initializing genesis workdir: %s", g.workDir))
Expand Down Expand Up @@ -178,10 +200,15 @@ func extractBoshVariables(raw []byte) ([]byte, bool) {
}

func (g *genesis) rawManifest() []byte {
g.logger.Println(fmt.Sprintf("running genesis version %v syntax", g.version.Major))
args := []string{
g.deploymentsDir() + "/" + g.environment.Name,
"manifest",
"--type=unredacted",
}
if g.version.Major >= 3 {
args = append(args, "--type=unredacted")
} else {
args = append(args, "--no-redact", "--no-prune")
}
args = append(args, g.configsArgs()...)
return g.genesis(args...).Run(g.environment.OutputMatchers.GenesisManifest)
Expand Down Expand Up @@ -273,7 +300,7 @@ func (g *genesis) exodusBase() string {

func (g *genesis) git(arg ...string) *Cmd {
return NewCmd("git", arg, []string{
fmt.Sprintf("XDG_CONFIG_HOME=%s/.config", g.workDir),
fmt.Sprintf("XDG_CONFIG_HOME=%s/.config", g.workDir),
fmt.Sprintf("HOME=%s", g.workDir),
}, g.logger)
}
Expand Down

0 comments on commit 6556ecc

Please sign in to comment.