github.com/cilium/ebpf@v0.16.0/cmd/bpf2go/makedep_test.go (about) 1 package main 2 3 import ( 4 "bytes" 5 "reflect" 6 "strings" 7 "testing" 8 ) 9 10 func TestParseDependencies(t *testing.T) { 11 const input = `main.go: /foo/bar baz 12 13 frob: /gobble \ 14 gubble 15 16 nothing: 17 ` 18 19 have, err := parseDependencies("/foo", strings.NewReader(input)) 20 if err != nil { 21 t.Fatal("Can't parse dependencies:", err) 22 } 23 24 want := []dependency{ 25 {"/foo/main.go", []string{"/foo/bar", "/foo/baz"}}, 26 {"/foo/frob", []string{"/gobble", "/foo/gubble"}}, 27 {"/foo/nothing", nil}, 28 } 29 30 if !reflect.DeepEqual(have, want) { 31 t.Logf("Have: %#v", have) 32 t.Logf("Want: %#v", want) 33 t.Error("Result doesn't match") 34 } 35 36 var output bytes.Buffer 37 err = adjustDependencies(&output, "/foo", want) 38 if err != nil { 39 t.Error("Can't adjust dependencies") 40 } 41 42 const wantOutput = `main.go: \ 43 bar \ 44 baz 45 46 frob: \ 47 ../gobble \ 48 gubble 49 50 nothing: 51 52 ` 53 54 if have := output.String(); have != wantOutput { 55 t.Logf("Have:\n%s", have) 56 t.Logf("Want:\n%s", wantOutput) 57 t.Error("Output doesn't match") 58 } 59 }