Skip to content

Commit

Permalink
Move test data into testdata folder
Browse files Browse the repository at this point in the history
  • Loading branch information
simitt committed Jun 25, 2018
1 parent 4a17222 commit 8a7016a
Show file tree
Hide file tree
Showing 47 changed files with 55 additions and 64 deletions.
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ create-docs:
@mkdir -p docs/data/intake-api/generated/error
@mkdir -p docs/data/intake-api/generated/transaction
@mkdir -p docs/data/intake-api/generated/sourcemap
@cp tests/data/error/payload.json docs/data/intake-api/generated/error/
@cp tests/data/error/frontend.json docs/data/intake-api/generated/error/
@cp tests/data/error/minimal_payload_exception.json docs/data/intake-api/generated/error/
@cp tests/data/error/minimal_payload_log.json docs/data/intake-api/generated/error/
@cp tests/data/transaction/payload.json docs/data/intake-api/generated/transaction/
@cp tests/data/transaction/minimal_payload.json docs/data/intake-api/generated/transaction/
@cp tests/data/transaction/minimal_span.json docs/data/intake-api/generated/transaction/
@cp tests/data/sourcemap/bundle.js.map docs/data/intake-api/generated/sourcemap/
@cp testdata/error/payload.json docs/data/intake-api/generated/error/
@cp testdata/error/frontend.json docs/data/intake-api/generated/error/
@cp testdata/error/minimal_payload_exception.json docs/data/intake-api/generated/error/
@cp testdata/error/minimal_payload_log.json docs/data/intake-api/generated/error/
@cp testdata/transaction/payload.json docs/data/intake-api/generated/transaction/
@cp testdata/transaction/minimal_payload.json docs/data/intake-api/generated/transaction/
@cp testdata/transaction/minimal_span.json docs/data/intake-api/generated/transaction/
@cp testdata/sourcemap/bundle.js.map docs/data/intake-api/generated/sourcemap/

# Start manual testing environment with agents
start-env:
Expand Down
2 changes: 1 addition & 1 deletion decoder/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestDecodeSourcemapFormData(t *testing.T) {
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)

fileBytes, err := loader.LoadDataAsBytes("data/sourcemap/bundle.js.map")
fileBytes, err := loader.LoadDataAsBytes("../testdata/sourcemap/bundle.js.map")
assert.NoError(t, err)
part, err := writer.CreateFormFile("sourcemap", "bundle_no_mapping.js.map")
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion processor/error/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ type fakeAcc struct{}
func (ac *fakeAcc) Fetch(smapId sourcemap.Id) (*s.Consumer, error) {
file := "bundle.js.map"
current, _ := os.Getwd()
path := filepath.Join(current, "../../tests/data/sourcemap/", file)
path := filepath.Join(current, "../../testdata/sourcemap/", file)
fileBytes, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion processor/error/package_tests/json_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var (
procSetup = tests.ProcessorSetup{
Proc: er.NewProcessor(),
FullPayloadPath: "data/error/payload.json",
FullPayloadPath: "../testdata/error/payload.json",
TemplatePaths: []string{"../_meta/fields.yml",
"../../../_meta/fields.common.yml"},
}
Expand Down
24 changes: 12 additions & 12 deletions processor/error/package_tests/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ import (

var (
backendRequestInfo = []tests.RequestInfo{
{Name: "TestProcessErrorMinimalService", Path: "data/error/minimal_service.json"},
{Name: "TestProcessErrorMinimalProcess", Path: "data/error/minimal_process.json"},
{Name: "TestProcessErrorFull", Path: "data/error/payload.json"},
{Name: "TestProcessErrorNullValues", Path: "data/error/null_values.json"},
{Name: "TestProcessErrorAugmentedIP", Path: "data/error/augmented_payload_backend.json"},
{Name: "TestProcessErrorMinimalService", Path: "../testdata/error/minimal_service.json"},
{Name: "TestProcessErrorMinimalProcess", Path: "../testdata/error/minimal_process.json"},
{Name: "TestProcessErrorFull", Path: "../testdata/error/payload.json"},
{Name: "TestProcessErrorNullValues", Path: "../testdata/error/null_values.json"},
{Name: "TestProcessErrorAugmentedIP", Path: "../testdata/error/augmented_payload_backend.json"},
}

backendRequestInfoIgnoreTimestamp = []tests.RequestInfo{
{Name: "TestProcessErrorMinimalPayloadException", Path: "data/error/minimal_payload_exception.json"},
{Name: "TestProcessErrorMinimalPayloadLog", Path: "data/error/minimal_payload_log.json"},
{Name: "TestProcessErrorMinimalPayloadException", Path: "../testdata/error/minimal_payload_exception.json"},
{Name: "TestProcessErrorMinimalPayloadLog", Path: "../testdata/error/minimal_payload_log.json"},
}

frontendRequestInfo = []tests.RequestInfo{
{Name: "TestProcessErrorFrontend", Path: "data/error/frontend.json"},
{Name: "TestProcessErrorFrontendNoSmap", Path: "data/error/frontend_app.e2e-bundle.json"},
{Name: "TestProcessErrorFrontendMinifiedSmap", Path: "data/error/frontend_app.e2e-bundle.min.json"},
{Name: "TestProcessErrorAugmentedUserAgentAndIP", Path: "data/error/augmented_payload_frontend.json"},
{Name: "TestProcessErrorFrontend", Path: "../testdata/error/frontend.json"},
{Name: "TestProcessErrorFrontendNoSmap", Path: "../testdata/error/frontend_app.e2e-bundle.json"},
{Name: "TestProcessErrorFrontendMinifiedSmap", Path: "../testdata/error/frontend_app.e2e-bundle.min.json"},
{Name: "TestProcessErrorAugmentedUserAgentAndIP", Path: "../testdata/error/augmented_payload_frontend.json"},
}
)

Expand Down Expand Up @@ -87,7 +87,7 @@ func (ac *fakeAcc) Fetch(smapId sourcemap.Id) (*s.Consumer, error) {
file = testSourcemapInfo.file
}
current, _ := os.Getwd()
path := filepath.Join(current, "../../../tests/data/sourcemap/", file)
path := filepath.Join(current, "../../../testdata/sourcemap/", file)
fileBytes, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion processor/sourcemap/package_tests/json_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestPayloadAttributesInSchema(t *testing.T) {
var (
procSetup = tests.ProcessorSetup{
Proc: sm.NewProcessor(),
FullPayloadPath: "data/sourcemap/payload.json",
FullPayloadPath: "../testdata/sourcemap/payload.json",
TemplatePaths: []string{"../_meta/fields.yml"},
}
)
Expand Down
4 changes: 2 additions & 2 deletions processor/sourcemap/package_tests/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
// ensure all valid documents pass through the whole validation and transformation process
func TestSourcemapProcessorOK(t *testing.T) {
requestInfo := []tests.RequestInfo{
{Name: "TestProcessSourcemapFull", Path: "data/sourcemap/payload.json"},
{Name: "TestProcessSourcemapMinimalPayload", Path: "data/sourcemap/minimal_payload.json"},
{Name: "TestProcessSourcemapFull", Path: "../testdata/sourcemap/payload.json"},
{Name: "TestProcessSourcemapMinimalPayload", Path: "../testdata/sourcemap/minimal_payload.json"},
}
tests.TestProcessRequests(t, sourcemap.NewProcessor(), config.Config{}, requestInfo, map[string]string{"@timestamp": "***IGNORED***"})
}
2 changes: 1 addition & 1 deletion processor/sourcemap/payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestPayloadTransform(t *testing.T) {
}

func TestParseSourcemaps(t *testing.T) {
fileBytes, err := loader.LoadDataAsBytes("data/sourcemap/bundle.js.map")
fileBytes, err := loader.LoadDataAsBytes("../testdata/sourcemap/bundle.js.map")
assert.NoError(t, err)
parser, err := s.Parse("", fileBytes)
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion processor/transaction/package_tests/json_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var (
procSetup = tests.ProcessorSetup{
Proc: tr.NewProcessor(),
FullPayloadPath: "data/transaction/payload.json",
FullPayloadPath: "../testdata/transaction/payload.json",
TemplatePaths: []string{"../_meta/fields.yml",
"../../../_meta/fields.common.yml"},
}
Expand Down
26 changes: 13 additions & 13 deletions processor/transaction/package_tests/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ import (

var (
backendRequestInfo = []tests.RequestInfo{
{Name: "TestProcessTransactionFull", Path: "data/transaction/payload.json"},
{Name: "TestProcessTransactionNullValues", Path: "data/transaction/null_values.json"},
{Name: "TestProcessSystemNull", Path: "data/transaction/system_null.json"},
{Name: "TestProcessProcessNull", Path: "data/transaction/process_null.json"},
{Name: "TestProcessTransactionMinimalSpan", Path: "data/transaction/minimal_span.json"},
{Name: "TestProcessTransactionMinimalService", Path: "data/transaction/minimal_service.json"},
{Name: "TestProcessTransactionMinimalProcess", Path: "data/transaction/minimal_process.json"},
{Name: "TestProcessTransactionEmpty", Path: "data/transaction/transaction_empty_values.json"},
{Name: "TestProcessTransactionAugmentedIP", Path: "data/transaction/augmented_payload_backend.json"},
{Name: "TestProcessTransactionFull", Path: "../testdata/transaction/payload.json"},
{Name: "TestProcessTransactionNullValues", Path: "../testdata/transaction/null_values.json"},
{Name: "TestProcessSystemNull", Path: "../testdata/transaction/system_null.json"},
{Name: "TestProcessProcessNull", Path: "../testdata/transaction/process_null.json"},
{Name: "TestProcessTransactionMinimalSpan", Path: "../testdata/transaction/minimal_span.json"},
{Name: "TestProcessTransactionMinimalService", Path: "../testdata/transaction/minimal_service.json"},
{Name: "TestProcessTransactionMinimalProcess", Path: "../testdata/transaction/minimal_process.json"},
{Name: "TestProcessTransactionEmpty", Path: "../testdata/transaction/transaction_empty_values.json"},
{Name: "TestProcessTransactionAugmentedIP", Path: "../testdata/transaction/augmented_payload_backend.json"},
}

backendRequestInfoIgnoreTimestamp = []tests.RequestInfo{
{Name: "TestProcessTransactionMinimalPayload", Path: "data/transaction/minimal_payload.json"},
{Name: "TestProcessTransactionMinimalPayload", Path: "../testdata/transaction/minimal_payload.json"},
}

frontendRequestInfo = []tests.RequestInfo{
{Name: "TestProcessTransactionFrontend", Path: "data/transaction/frontend.json"},
{Name: "TestProcessTransactionAugmentedMerge", Path: "data/transaction/augmented_payload_frontend.json"},
{Name: "TestProcessTransactionAugmented", Path: "data/transaction/augmented_payload_frontend_no_context.json"},
{Name: "TestProcessTransactionFrontend", Path: "../testdata/transaction/frontend.json"},
{Name: "TestProcessTransactionAugmentedMerge", Path: "../testdata/transaction/augmented_payload_frontend.json"},
{Name: "TestProcessTransactionAugmented", Path: "../testdata/transaction/augmented_payload_frontend_no_context.json"},
}
)

Expand Down
8 changes: 2 additions & 6 deletions script/output_data/output_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ func main() {
}

func generate() error {
filename := "payload.json"
basePath := "data"
outputPath := "docs/data/elasticsearch/"

var checked = map[string]struct{}{}

for path, mapping := range beater.Routes {
Expand All @@ -36,7 +32,7 @@ func generate() error {

p := mapping.ProcessorFactory()

data, err := loader.LoadData(filepath.Join(basePath, p.Name(), filename))
data, err := loader.LoadData(filepath.Join("..", "testdata", p.Name(), "payload.json"))
if err != nil {
return err
}
Expand Down Expand Up @@ -67,7 +63,7 @@ func generate() error {

if _, ok := checked[key]; !ok {
checked[key] = struct{}{}
file := filepath.Join(outputPath, event.(string)+".json")
file := filepath.Join("docs/data/elasticsearch", event.(string)+".json")

output, err := json.MarshalIndent(d.Fields, "", " ")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion sourcemap/accessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func getFakeId() Id {

func getFakeSmap() *sourcemap.Consumer {
cwd, _ := os.Getwd()
data, err := ioutil.ReadFile(filepath.Join(cwd, "..", "tests/data/sourcemap/bundle.js.map"))
data, err := ioutil.ReadFile(filepath.Join(cwd, "..", "testdata/sourcemap/bundle.js.map"))
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion sourcemap/mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type fakeAccessor struct{}

func (ac *fakeAccessor) Fetch(smapId Id) (*sourcemap.Consumer, error) {
current, _ := os.Getwd()
path := filepath.Join(current, "../tests/data/sourcemap/", smapId.Path)
path := filepath.Join(current, "../testdata/sourcemap/", smapId.Path)
fileBytes, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions tests/approvals.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/yudai/gojsondiff"

"github.com/elastic/apm-server/config"
Expand Down Expand Up @@ -98,16 +99,15 @@ type RequestInfo struct {
}

func TestProcessRequests(t *testing.T, p processor.Processor, config config.Config, requestInfo []RequestInfo, ignored map[string]string) {
assert := assert.New(t)
for _, info := range requestInfo {
data, err := loader.LoadData(info.Path)
assert.Nil(err)
require.NoError(t, err)

err = p.Validate(data)
assert.NoError(err)
require.NoError(t, err)

payload, err := p.Decode(data)
assert.NoError(err)
require.NoError(t, err)

events := payload.Transform(config)

Expand All @@ -121,7 +121,7 @@ func TestProcessRequests(t *testing.T, p processor.Processor, config config.Conf
receivedJson := map[string]interface{}{"events": eventFields}
verifyErr := ApproveJson(receivedJson, info.Name, ignored)
if verifyErr != nil {
assert.Fail(fmt.Sprintf("Test %s failed with error: %s", info.Name, verifyErr.Error()))
assert.Fail(t, fmt.Sprintf("Test %s failed with error: %s", info.Name, verifyErr.Error()))
}
}
}
2 changes: 1 addition & 1 deletion tests/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func LoadValidData(processorName string) (map[string]interface{}, error) {
func buildPath(processorName string) (string, error) {
switch processorName {
case "error", "transaction", "sourcemap":
return findFile(filepath.Join("data", processorName, "payload.json"))
return findFile(filepath.Join("..", "testdata", processorName, "payload.json"))
default:
return "", errors.New("unknown data type")
}
Expand Down
9 changes: 3 additions & 6 deletions tests/system/apmserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def _beat_path_join(cls, *paths):

def get_transaction_payload_path(self, name="payload.json"):
return self._beat_path_join(
'tests',
'data',
'testdata',
'transaction',
name)

Expand All @@ -41,8 +40,7 @@ def get_transaction_payload(self):

def get_error_payload_path(self, name="payload.json"):
return self._beat_path_join(
'tests',
'data',
'testdata',
'error',
name)

Expand Down Expand Up @@ -268,8 +266,7 @@ def upload_sourcemap(self, file_name='bundle_no_mapping.js.map',
bundle_filepath='bundle_no_mapping.js.map',
expected_ct=1):
path = self._beat_path_join(
'tests',
'data',
'testdata',
'sourcemap',
file_name)
f = open(path)
Expand Down
4 changes: 1 addition & 3 deletions tests/system/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ def test_sourcemap_upload(self):

def test_sourcemap_upload_fail(self):
path = self._beat_path_join(
'tests',
'data',
'valid',
'testdata',
'sourcemap',
'bundle.js.map')
file = open(path)
Expand Down

0 comments on commit 8a7016a

Please sign in to comment.