Skip to content

Commit

Permalink
Make spec_test idempotent (elastic#16392)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ph authored Feb 24, 2020
1 parent 83df5d6 commit c5b9496
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion x-pack/agent/pkg/agent/program/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package program

import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strings"
"testing"
Expand Down Expand Up @@ -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)
}
}

0 comments on commit c5b9496

Please sign in to comment.