github.com/mattevans/edward@v1.9.2/edward/telemetry_test.go (about) 1 package edward_test 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "path" 7 "testing" 8 9 "github.com/theothertomelliott/must" 10 ) 11 12 func TestTelemetryStart(t *testing.T) { 13 // if testing.Short() { 14 // t.Skip("skipping test in short mode.") 15 // } 16 17 var tests = []struct { 18 name string 19 path string 20 config string 21 services []string 22 expectedFile string 23 expectedContent string 24 expectedServices int 25 err error 26 }{ 27 { 28 name: "start telemetry", 29 path: "testdata/telemetry", 30 config: "edward.json", 31 services: []string{"service"}, 32 expectedFile: "events.txt", 33 expectedContent: "start service\n", 34 expectedServices: 1, 35 }, 36 } 37 for _, test := range tests { 38 t.Run(test.name, func(t *testing.T) { 39 var err error 40 41 // Copy test content into a temp dir on the GOPATH & defer deletion 42 client, wd, cleanup, err := createClient(test.config, test.name, test.path) 43 defer cleanup() 44 45 tf := newTestFollower() 46 client.Follower = tf 47 48 defer showLogsIfFailed(t, test.name, wd, client) 49 50 err = client.Start(test.services, false, false, nil) 51 must.BeEqualErrors(t, test.err, err) 52 53 // Check file content is as expected 54 expectedFilePath := path.Join(wd, test.expectedFile) 55 content, err := ioutil.ReadFile(expectedFilePath) 56 if err != nil { 57 t.Errorf("could not read %q: %v", expectedFilePath, err) 58 } 59 must.BeEqual(t, test.expectedContent, string(content), fmt.Sprintf("content of file %q", expectedFilePath)) 60 61 // Verify that the process actually started 62 verifyAndStopRunners(t, client, test.expectedServices) 63 }) 64 } 65 }