Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create helpers for using goss as a package #548

Merged
merged 2 commits into from Mar 23, 2020

Conversation

@ripienaar
Copy link
Contributor

ripienaar commented Feb 18, 2020

Checklist
  • make test-all (UNIX) passes. CI will also test this
  • unit and/or integration tests are included (if applicable)
  • documentation is changed or added (if applicable)

Description of change

This creates a way to make a goss Config programatically with defaults
suitable to use as a package.

This also merges the RuntimeConfig with Config as these had overlapping
uses, simplify some timeout handling and optionally surpress output when
adding resources to a goss file

This stops short of overhauling all std output and instead just focus
on the things package users are likely to want to do - programatically
add resources and validate them.

Additionally a new output format 'structured' is added that has a
matching data type that defines it's output which makes it easier
to use the result sets from goss programatically, this is handy when
one wants to write tooling to process CI output from goss in go

@ripienaar

This comment has been minimized.

Copy link
Contributor Author

ripienaar commented Feb 18, 2020

This is a draft PR - d739600 builds on #546 and finally makes resources add and validation usable as a package

Once #546 is merged I'll polish this up and make it into a full PR.

@ripienaar

This comment has been minimized.

Copy link
Contributor Author

ripienaar commented Feb 18, 2020

goss/goss_test.go

Lines 24 to 84 in d739600

func TestUseAsPackage(t *testing.T) {
output := &bytes.Buffer{}
// temp spec file
fh, err := ioutil.TempFile("", "*.yaml")
checkErr(t, err, "temp file failed")
fh.Close()
// new config that doesnt spam output etc
cfg, err := util.NewConfig(util.WithFormatOptions("pretty"), util.WithResultWriter(output), util.WithSpecFile(fh.Name()))
checkErr(t, err, "new config failed")
// adds the os tmp dir to the goss spec file
err = AddResources(fh.Name(), "File", []string{os.TempDir()}, cfg)
checkErr(t, err, "could not add resource %q", os.TempDir())
// validate and sanity check, compare structured vs direct results etc
results, err := ValidateResults(cfg)
checkErr(t, err, "check failed")
found := 0
passed := 0
for rg := range results {
for _, r := range rg {
found++
if r.Successful {
passed++
}
}
}
code, err := Validate(cfg, time.Now())
checkErr(t, err, "check failed")
if code != 0 {
t.Fatalf("check failed, expected 0 got %d", code)
}
res := &outputs.StructuredOutput{}
err = json.Unmarshal(output.Bytes(), res)
checkErr(t, err, "unmarshal failed")
if res.Summary.Failed != 0 {
t.Fatalf("expected 0 failed, got %d", res.Summary.Failed)
}
if len(res.Results) != found {
t.Fatalf("expected %d results for %d", found, len(res.Results))
}
okcount := 0
for _, r := range res.Results {
if r.Successful {
okcount++
}
}
if okcount != passed {
t.Fatalf("expected %d passed but got %d", passed, okcount)
}
}
demonstrates using add/validate

@ripienaar ripienaar force-pushed the ripienaar:544.package branch from d739600 to dded0dc Feb 18, 2020
@ripienaar ripienaar mentioned this pull request Feb 18, 2020
This also merges the RuntimeConfig with Config as these had overlapping
uses, simplify some timeout handling and surpress output when adding
resources to a goss file

This stops short of overhauling all std output and instead just focus
on the things package users are likely to want to do - programatically
add resources and validate them.

Additionally a new output format 'structured' is added that has a
matching data type that defines it's output which makes it easier
to use the result sets from goss programatically
@ripienaar ripienaar force-pushed the ripienaar:544.package branch from 906313f to aa3edfe Feb 26, 2020
@ripienaar ripienaar marked this pull request as ready for review Feb 26, 2020
@ripienaar

This comment has been minimized.

Copy link
Contributor Author

ripienaar commented Feb 26, 2020

@aelsabbahy good to go on this

@ripienaar

This comment has been minimized.

Copy link
Contributor Author

ripienaar commented Mar 3, 2020

I've been traveling for a week so been off the radar, back now, is there anything else left for me to do here?

@ripienaar

This comment has been minimized.

Copy link
Contributor Author

ripienaar commented Mar 12, 2020

Appears this PR is now gone out of date due to non attention, am I just expected to keep rebasing and rebasing while you keep merging other PRs and not this one?

With such a large piece of the code base being touched it's worth getting this one in to limit the knock on effect of continuously having to keep updating/rebasing/fixing this one

Copy link
Contributor

pedroMMM left a comment

@ripienaar I am very sorry that no one has taken a look at your PR yet! It's shameful that we dropped the ball there.

But I have taken a look a now and everything seems to be perfectly fine it's impressive work. 👍

@aelsabbahy

This comment has been minimized.

Copy link
Owner

aelsabbahy commented Mar 16, 2020

Hello, no rebase is necessary. I've been making sure I don't merge anything that conflicts with this PR as there's a lot of changes here.

Smaller changes I've merged in to cut a release. This will be the first PR merged if there's any conflicting PRs

@ripienaar

This comment has been minimized.

Copy link
Contributor Author

ripienaar commented Mar 17, 2020

thanks, would be good to get this merged for me as I can then continue to work on the what I need this for based on your master.

@aelsabbahy aelsabbahy merged commit a17ce0f into aelsabbahy:master Mar 23, 2020
1 of 2 checks passed
1 of 2 checks passed
codeclimate 3 issues to fix
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@aelsabbahy

This comment has been minimized.

Copy link
Owner

aelsabbahy commented Mar 23, 2020

Thanks for this. Awesome set of changes so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.