go-hep.org/x/hep@v0.38.1/fwk/dflow_test.go (about)

     1  // Copyright ©2018 The go-hep Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package fwk_test
     6  
     7  import (
     8  	"bytes"
     9  	"os"
    10  	"testing"
    11  
    12  	"go-hep.org/x/hep/fwk/job"
    13  	"go-hep.org/x/hep/internal/diff"
    14  )
    15  
    16  func TestDFlowSvcGraph(t *testing.T) {
    17  	app := job.NewJob(nil, job.P{
    18  		"EvtMax":   int64(1),
    19  		"NProcs":   1,
    20  		"MsgLevel": job.MsgLevel("ERROR"),
    21  	})
    22  
    23  	app.Create(job.C{
    24  		Type: "go-hep.org/x/hep/fwk/internal/fwktest.task1",
    25  		Name: "t0",
    26  		Props: job.P{
    27  			"Ints1": "t0-ints1",
    28  			"Ints2": "t0-ints2",
    29  		},
    30  	})
    31  
    32  	app.Create(job.C{
    33  		Type: "go-hep.org/x/hep/fwk/internal/fwktest.task1",
    34  		Name: "t1",
    35  		Props: job.P{
    36  			"Ints1": "t1-ints1",
    37  			"Ints2": "t2-ints2",
    38  		},
    39  	})
    40  
    41  	app.Create(job.C{
    42  		Type: "go-hep.org/x/hep/fwk/internal/fwktest.task2",
    43  		Name: "t2",
    44  		Props: job.P{
    45  			"Input":  "t1-ints1",
    46  			"Output": "t1-ints1-massaged",
    47  		},
    48  	})
    49  
    50  	app.Create(job.C{
    51  		Type: "go-hep.org/x/hep/fwk/internal/fwktest.svc1",
    52  		Name: "svc1",
    53  	})
    54  
    55  	dflow := app.App().GetSvc("dataflow")
    56  	if dflow == nil {
    57  		t.Fatalf("could not retrieve dataflow svc")
    58  	}
    59  
    60  	const (
    61  		dotfile  = "testdata/simple_dflow.dot"
    62  		wantfile = "testdata/simple_dflow.dot.golden"
    63  	)
    64  
    65  	app.SetProp(dflow, "DotFile", dotfile)
    66  
    67  	app.Run()
    68  
    69  	got, err := os.ReadFile(dotfile)
    70  	if err != nil {
    71  		t.Fatalf("could not read %q: %v", dotfile, err)
    72  	}
    73  
    74  	want, err := os.ReadFile(wantfile)
    75  	if err != nil {
    76  		t.Fatalf("could not read reference file %q: %v", wantfile, err)
    77  	}
    78  
    79  	if !bytes.Equal(got, want) {
    80  		t.Fatalf("dot files differ:\n%s", diff.Format(string(got), string(want)))
    81  	}
    82  
    83  	os.Remove(dotfile)
    84  }