From 8c1242e1c563104031a8086fe0f7df8ed3ef0131 Mon Sep 17 00:00:00 2001 From: Pier-Hugues Pellerin Date: Tue, 18 Feb 2020 12:52:25 -0500 Subject: [PATCH] Make spec_test idempotent The previous implementation was actually saving the content over existing spec files. So everytime that you ran the test the files would have be modified and you had to ignore them on commit. This commit move the generated file into a temporary directory. --- x-pack/agent/pkg/agent/program/spec_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/x-pack/agent/pkg/agent/program/spec_test.go b/x-pack/agent/pkg/agent/program/spec_test.go index 021bbff6792..966eca15416 100644 --- a/x-pack/agent/pkg/agent/program/spec_test.go +++ b/x-pack/agent/pkg/agent/program/spec_test.go @@ -6,6 +6,8 @@ package program import ( "io/ioutil" + "os" + "path/filepath" "regexp" "strings" "testing" @@ -100,9 +102,14 @@ when: 1 == 1 } func TestExport(t *testing.T) { + dir, err := ioutil.TempDir("", "test_export") + require.NoError(t, err) + defer os.RemoveAll(dir) + for _, spec := range Supported { b, err := yaml.Marshal(spec) require.NoError(t, err) - ioutil.WriteFile("../../../spec/"+strings.ToLower(spec.Name)+".yml", b, 0666) + err = ioutil.WriteFile(filepath.Join(dir, strings.ToLower(spec.Name)+".yml"), b, 0666) + require.NoError(t, err) } }