This repository has been archived by the owner on Aug 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_test.go
73 lines (61 loc) · 1.64 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"io/ioutil"
"os"
"testing"
)
const expectedBaseInstFile = `package testdata
import (
_ "go.undefinedlabs.com/scopeagent/autoinstrument"
)
`
const expectedSampleInstFile = `package samplePackage
import (
_ "go.undefinedlabs.com/scopeagent/autoinstrument"
)
`
func TestInstallerProcessor(t *testing.T) {
baseInstFilePath := "./testdata/scope_pkg_testdata_test.go"
sampleInstFilePath := "./testdata/samplePackage/scope_pkg_samplePackage_test.go"
defer func() {
// Remove test files
_ = os.Remove(baseInstFilePath)
_ = os.Remove(sampleInstFilePath)
}()
// Remove previous files if any
_ = os.Remove(baseInstFilePath)
_ = os.Remove(sampleInstFilePath)
// Process test data
processFolder("./testdata/")
// Base instrumentation file
baseInstFile, err := os.Open(baseInstFilePath)
if err != nil {
t.Fatal(err)
}
defer baseInstFile.Close()
data, err := ioutil.ReadAll(baseInstFile)
if err != nil {
t.Fatal(err)
}
if string(data) != expectedBaseInstFile {
t.Fatal("the base package instrumentation file is different than expected")
}
// Sample instrumentation file
sampleInstFile, err := os.Open(sampleInstFilePath)
if err != nil {
t.Fatal(err)
}
defer sampleInstFile.Close()
data, err = ioutil.ReadAll(sampleInstFile)
if err != nil {
t.Fatal(err)
}
if string(data) != expectedSampleInstFile {
t.Fatal("the sample package instrumentation file is different than expected")
}
// Instrumented test package shouldn't exist
_, err = os.Stat("./testdata/instrumentedPackage/scope_pkg_instrumentedPackage_test.go")
if err == nil {
t.Fatal("the instrumented package instrumentation file shouldn't exist")
}
}