Skip to content

Integration test fixes#4

Merged
laverya merged 1 commit intomasterfrom
integration-test-fixes
Oct 25, 2017
Merged

Integration test fixes#4
laverya merged 1 commit intomasterfrom
integration-test-fixes

Conversation

@laverya
Copy link
Copy Markdown
Contributor

@laverya laverya commented Oct 24, 2017

The timeout-dependent tests don't work (since there aren't errors generated, and we can't set per-task timeouts) but the rest does.

@laverya laverya requested a review from areed October 24, 2017 21:26
Comment thread tests/integration_test.go Outdated
require.NoError(t, err)

// test to ensure all three components - core.loadavg, docker.logs, and docker.daemon - became specs
loadSpec, logsSpec, daemonSpec := false, false, false
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think require.Contains would be tidier

Comment thread tests/integration_test.go Outdated
)

// Test that yml files are parsed into spec lists properly
func TestParse(t *testing.T) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be unit test for Parse in the spec package, just remove the planner test at the end.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good idea

Comment thread tests/integration_test.go

// TestGenerate runs all the local data collection tools (read file, run command, hostname, loadavg, uptime)
// some tasks are not fully tested on windows (run command, loadavg, uptime)
func TestGenerate(t *testing.T) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit weary of maintaining this test because it's written like a unit test but the scope is of an integration test.
I think it would be better to break this down into several smaller tests. You could have one unit test for the Generate function with a set of fake Tasks with prepared results, and one integration test for each planner.
For the planner tests, I'd wait until we have the CLI working and write them as blackbox tests with Ginkgo. Each test would be a yaml spec and assert that the returned archive contains the expected files.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree - it really does have the scope of an integration test. I'll write a test for the Generate function within the relevant package, but leave this here for the moment to reuse when we make ginkgo integration tests, if that makes sense.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good

Copy link
Copy Markdown

@areed areed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple small style items. The generate test turned out nice.

Comment thread bundle/generate_test.go Outdated
"github.com/replicatedcom/support-bundle/types"
)

// TestGenerate runs all the local data collection tools (read file, run command, hostname, loadavg, uptime)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment is outdated

Comment thread bundle/generate_test.go Outdated
tasks := []types.Task{singleResults, mixedResults}

got, _ := ioutil.TempFile("", "generate-test-bundle")
// fmt.Println(got.Name())
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out code

Comment thread bundle/generate_test.go Outdated
err := Generate(tasks, time.Duration(time.Second*2), got.Name())
require.NoError(t, err)

testDir, _ := ioutil.TempDir("", "generate-test")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to require.NoError(t, err) here?

Comment thread spec/parse_test.go Outdated

// Test that yml files are parsed into spec lists properly
func TestParse(t *testing.T) {
yml, err := ioutil.ReadFile("./spec.yml")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you inline this file since this is a unit test? It makes the test easier to read and doesn't pollute the package directory.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good point

Comment thread spec/parse_test.go Outdated
logsSpec = true
require.Equal(t, "/raw/containers/testExample/logs.txt", spec.Raw)
require.NotNil(t, spec.Config)
// configMap, ok := spec.Config.(map[string]string)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out code

Comment thread spec/parse_test.go Outdated
Human: "/human/metrics/loadavg",
})

// require.Contains(t, specs, types.Spec{
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out code

Comment thread spec/parse_test.go Outdated
specs, err := Parse(yml)
require.NoError(t, err)

// test to ensure basics of docker.logs, since
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to use the require.Contains format for this test too. Did you try something like

var config = map[interface{}]interface{}
config["key"] = "val"
types.Spec{
    Builtin: "docker.logs",
    Config: config,
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had tried with map[string]string, which didn't work - I'll try with map[interface{}]interface{}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/replicatedcom/support-bundle/blob/master/plugins/docker/planners/logs.go#L10
Here's the code that parses that config. Maybe you learned a cleaner way to do this when working on Replicated yaml?

Comment thread tests/integration.go
// these commands aren't tested on windows platforms
lsCommandPath := ""
sleepCommandPath := ""
// sleepCommandPath := ""
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out code

Comment thread tests/integration.go
require.NotEqual(t, "", resultInfo.Path)
lsCommandPath = resultInfo.Path
}
// if resultInfo.Task == "runCommand" && resultInfo.Args[0] == "sleep" && resultInfo.Args[1] == "1m" {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out code through line 193

@laverya laverya force-pushed the integration-test-fixes branch from 156d52e to f6bcc5e Compare October 25, 2017 00:46
Reformatted integration test to use new task format
read-command.go modified to use an ellipsis operator
cmd.generate.go updated to use new function signatures
Added small test of docker planner to the integration test

Fix uptime and loadavg tests

Created parser test

Created much more limited test for bundle.Generate
@laverya laverya force-pushed the integration-test-fixes branch from f6bcc5e to c824b76 Compare October 25, 2017 00:57
@laverya laverya merged commit 9c6becf into master Oct 25, 2017
@laverya laverya deleted the integration-test-fixes branch October 25, 2017 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants