docstring_tokens
stringlengths
18
16.9k
code_tokens
stringlengths
75
1.81M
html_url
stringlengths
74
116
file_name
stringlengths
3
311
keep add keep keep keep
<mask> <mask> // Neighbors implements the ARPDB interface for *arpdbs. <mask> func (arp *arpdbs) Neighbors() (ns []Neighbor) { <mask> return arp.clone() <mask> } </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove if l := len(arp.arps); l > 0 && arp.last < l { return arp.arps[arp.last].Neighbors() } return nil </s> add return arp.clone() </s> remove l := len(arp.arps) // Start from the last succeeded implementation. for i := 0; i < l; i++ { cur := (arp.last + i) % l err = arp.arps[cur].Refresh() if err == nil { // The succeeded implementation found so update the last succeeded // index. arp.last = cur return nil </s> add for _, a := range arp.arps { err = a.Refresh() if err != nil { errs = append(errs, err) continue </s> remove // last is the last succeeded ARPDB index. last int </s> add neighs </s> remove var r io.Reader r, err = arp.runcmd() </s> add code, out, err := aghosRunCommand(arp.cmd, arp.args...) </s> remove last: 0, </s> add neighs: neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, </s> remove // runCmd runs the cmd with it's args and returns the result wrapped to be an // io.Reader. The error is returned either if the exit code retured by command // not equals 0 or the execution itself failed. func runCmd(cmd string, args ...string) (r io.Reader, err error) { var code int var out string code, out, err = aghos.RunCommand(cmd, args...) if err != nil { return nil, err } else if code != 0 { return nil, fmt.Errorf("unexpected exit code %d", code) } return strings.NewReader(out), nil } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb.go
keep keep keep keep replace replace replace replace replace keep
<mask> } <mask> <mask> // Neighbors implements the ARPDB interface for *arpdbs. <mask> func (arp *arpdbs) Neighbors() (ns []Neighbor) { <mask> if l := len(arp.arps); l > 0 && arp.last < l { <mask> return arp.arps[arp.last].Neighbors() <mask> } <mask> <mask> return nil <mask> } </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> add // // TODO(e.burkov): Think of a way to avoid cloning the slice twice. </s> remove l := len(arp.arps) // Start from the last succeeded implementation. for i := 0; i < l; i++ { cur := (arp.last + i) % l err = arp.arps[cur].Refresh() if err == nil { // The succeeded implementation found so update the last succeeded // index. arp.last = cur return nil </s> add for _, a := range arp.arps { err = a.Refresh() if err != nil { errs = append(errs, err) continue </s> remove var r io.Reader r, err = arp.runcmd() </s> add code, out, err := aghosRunCommand(arp.cmd, arp.args...) </s> remove // runCmd runs the cmd with it's args and returns the result wrapped to be an // io.Reader. The error is returned either if the exit code retured by command // not equals 0 or the execution itself failed. func runCmd(cmd string, args ...string) (r io.Reader, err error) { var code int var out string code, out, err = aghos.RunCommand(cmd, args...) if err != nil { return nil, err } else if code != 0 { return nil, fmt.Errorf("unexpected exit code %d", code) } return strings.NewReader(out), nil } </s> add </s> remove // last is the last succeeded ARPDB index. last int </s> add neighs </s> remove last: 0, </s> add neighs: neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), },
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> ) <mask> <mask> func newARPDB() *cmdARPDB { <mask> return &cmdARPDB{ <mask> parse: parseArpA, <mask> runcmd: rcArpA, <mask> ns: &neighs{ <mask> mu: &sync.RWMutex{}, <mask> ns: make([]Neighbor, 0), <mask> }, <mask> } </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove runcmd: rcArpA, parse: parseArpA, </s> add parse: parseArpA, </s> remove runcmd: rcArpA, </s> add parse: parseArpA, </s> add cmd: "cmd", </s> remove func TestCmdARPDB_ipneigh(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, runcmd: func() (r io.Reader, err error) { return strings.NewReader(ipNeighOutput), nil }, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> add assert.Equal(t, wantNeighs, a.Neighbors()) }) t.Run("ip_neigh", func(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, cmd: "ip", args: []string{"neigh"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> remove parse: parseArpA, </s> add cmd: "arp", args: []string{"/a"}, </s> remove err := a.Refresh() require.NoError(t, err) </s> add t.Run("wrt", func(t *testing.T) { a := &cmdARPDB{ parse: parseArpAWrt, cmd: "arp", args: []string{"-a"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, }
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_bsd.go
keep add keep keep keep keep
<mask> ns: make([]Neighbor, 0), <mask> }, <mask> } <mask> } <mask> <mask> // parseArpA parses the output of the "arp -a" command on macOS and FreeBSD. </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> add cmd: "arp", args: []string{"-a"}, </s> remove // rcArpA runs "arp /a". func rcArpA() (r io.Reader, err error) { return runCmd("arp", "/a") } </s> add </s> remove // rcIPNeigh runs "ip neigh". func rcIPNeigh() (r io.Reader, err error) { return runCmd("ip", "neigh") } </s> add </s> add // hardwareReportsReg is the regular expression matching the lines of // networksetup command output lines containing the interface information. var hardwareReportsReg = regexp.MustCompile("Hardware Port: (.*?)\nDevice: (.*?)\n") </s> remove parse: parseArpA, </s> add cmd: "arp", args: []string{"/a"}, </s> remove last: 0, </s> add neighs: neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), },
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_bsd.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> import ( <mask> "bufio" <mask> "fmt" <mask> "io" <mask> "io/fs" <mask> "net" <mask> "strings" <mask> "sync" <mask> </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove "io" </s> add </s> remove "io" </s> add </s> remove "strings" </s> add </s> add "bytes" </s> add "fmt" </s> remove "io" </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_linux.go
keep keep keep keep replace replace replace replace replace keep keep keep keep keep
<mask> } <mask> <mask> return newARPDBs( <mask> // Try /proc/net/arp first. <mask> &fsysARPDB{ns: ns, fsys: aghos.RootDirFS(), filename: "proc/net/arp"}, <mask> // Try "arp -a" then. <mask> &cmdARPDB{parse: parseF, runcmd: rcArpA, ns: ns}, <mask> // Try "ip neigh" finally. <mask> &cmdARPDB{parse: parseIPNeigh, runcmd: rcIPNeigh, ns: ns}, <mask> ) <mask> } <mask> <mask> // fsysARPDB accesses the ARP cache file to update the database. <mask> type fsysARPDB struct { </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove parse: parseArpA, runcmd: rcArpA, </s> add parse: parseArpA, </s> remove runcmd: rcArpA, parse: parseArpA, </s> add parse: parseArpA, </s> add cmd: "arp", args: []string{"-a"}, </s> add cmd: "arp", args: []string{"-a"}, </s> remove runcmd: rcArpA, </s> add parse: parseArpA, </s> remove func TestCmdARPDB_ipneigh(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, runcmd: func() (r io.Reader, err error) { return strings.NewReader(ipNeighOutput), nil }, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> add assert.Equal(t, wantNeighs, a.Neighbors()) }) t.Run("ip_neigh", func(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, cmd: "ip", args: []string{"neigh"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err)
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_linux.go
keep keep keep keep replace replace replace replace replace keep keep keep keep keep
<mask> <mask> return ns <mask> } <mask> <mask> // rcIPNeigh runs "ip neigh". <mask> func rcIPNeigh() (r io.Reader, err error) { <mask> return runCmd("ip", "neigh") <mask> } <mask> <mask> // parseIPNeigh parses the output of the "ip neigh" command on Linux. The <mask> // expected input format: <mask> // <mask> // 192.168.1.1 dev enp0s3 lladdr ab:cd:ef:ab:cd:ef REACHABLE <mask> // </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> add cmd: "arp", args: []string{"-a"}, </s> remove // rcArpA runs "arp /a". func rcArpA() (r io.Reader, err error) { return runCmd("arp", "/a") } </s> add </s> add cmd: "arp", args: []string{"-a"}, </s> remove // runCmdFunc is the function that runs some command and returns its output // wrapped to be a io.Reader. type runCmdFunc func() (r io.Reader, err error) </s> add </s> remove if len(fields) < 3 || fields[0] != "default" { </s> add if len(fields) < 3 || string(fields[0]) != "default" { </s> remove fields := strings.Fields(string(d)) </s> add fields := bytes.Fields(out)
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_linux.go
keep keep replace keep keep keep keep keep keep keep keep replace keep
<mask> <mask> import ( <mask> "io" <mask> "net" <mask> "strings" <mask> "sync" <mask> "testing" <mask> <mask> import ( <mask> "io" <mask> "net" <mask> "strings" <mask> "sync" </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove "strings" </s> add </s> remove "io" </s> add </s> remove "io" </s> add </s> remove "io" </s> add </s> remove "io" </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_linux_test.go
keep keep add keep keep keep keep keep keep
<mask> "net" <mask> "sync" <mask> "testing" <mask> <mask> "github.com/stretchr/testify/assert" <mask> "github.com/stretchr/testify/require" <mask> ) <mask> <mask> const arpAOutputWrt = ` </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove "github.com/stretchr/testify/require" </s> add </s> remove "strings" </s> add </s> remove "testing/iotest" </s> add </s> add "testing/fstest" </s> remove "bytes" </s> add "io/fs" </s> add "testing/fstest"
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_linux_test.go
keep keep add keep keep keep keep keep
<mask> }} <mask> <mask> func TestFSysARPDB(t *testing.T) { <mask> a := &fsysARPDB{ <mask> ns: &neighs{ <mask> mu: &sync.RWMutex{}, <mask> ns: make([]Neighbor, 0), <mask> }, </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> add cmd: "cmd", </s> remove err := a.Refresh() require.NoError(t, err) </s> add t.Run("wrt", func(t *testing.T) { a := &cmdARPDB{ parse: parseArpAWrt, cmd: "arp", args: []string{"-a"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } </s> remove func TestCmdARPDB_ipneigh(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, runcmd: func() (r io.Reader, err error) { return strings.NewReader(ipNeighOutput), nil }, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> add assert.Equal(t, wantNeighs, a.Neighbors()) }) t.Run("ip_neigh", func(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, cmd: "ip", args: []string{"neigh"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> remove runcmd: rcArpA, </s> add parse: parseArpA, </s> remove parse: parseArpA, runcmd: rcArpA, </s> add parse: parseArpA, </s> remove runcmd: rcArpA, parse: parseArpA, </s> add parse: parseArpA,
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_linux_test.go
keep keep keep keep replace replace replace replace replace replace replace replace keep keep keep keep keep
<mask> ns := a.Neighbors() <mask> assert.Equal(t, wantNeighs, ns) <mask> } <mask> <mask> func TestCmdARPDB_arpawrt(t *testing.T) { <mask> a := &cmdARPDB{ <mask> parse: parseArpAWrt, <mask> runcmd: func() (r io.Reader, err error) { return strings.NewReader(arpAOutputWrt), nil }, <mask> ns: &neighs{ <mask> mu: &sync.RWMutex{}, <mask> ns: make([]Neighbor, 0), <mask> }, <mask> } <mask> <mask> err := a.Refresh() <mask> require.NoError(t, err) <mask> </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove func TestCmdARPDB_ipneigh(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, runcmd: func() (r io.Reader, err error) { return strings.NewReader(ipNeighOutput), nil }, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> add assert.Equal(t, wantNeighs, a.Neighbors()) }) t.Run("ip_neigh", func(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, cmd: "ip", args: []string{"neigh"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> remove err := a.Refresh() require.NoError(t, err) </s> add t.Run("wrt", func(t *testing.T) { a := &cmdARPDB{ parse: parseArpAWrt, cmd: "arp", args: []string{"-a"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } </s> remove assert.Equal(t, wantNeighs, a.Neighbors()) } </s> add err := a.Refresh() require.NoError(t, err) </s> remove a := &cmdARPDB{ runcmd: badReaderRunCmd, parse: parseArpA, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } const wantErrMsg string = "cmd arpdb: scanning the output: " + string(errRead) testutil.AssertErrorMsg(t, wantErrMsg, a.Refresh()) </s> add </s> remove parse: parseArpA, runcmd: rcArpA, </s> add parse: parseArpA, </s> remove runcmd: rcArpA, parse: parseArpA, </s> add parse: parseArpA,
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_linux_test.go
keep add keep keep keep keep
<mask> "ip neigh": {err: nil, out: ipNeighOutput, code: 0}, <mask> } <mask> <mask> t.Run("wrt", func(t *testing.T) { <mask> a := &cmdARPDB{ <mask> parse: parseArpAWrt, </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove func TestCmdARPDB_arpawrt(t *testing.T) { a := &cmdARPDB{ parse: parseArpAWrt, runcmd: func() (r io.Reader, err error) { return strings.NewReader(arpAOutputWrt), nil }, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, </s> add func TestCmdARPDB_linux(t *testing.T) { sh := mapShell{ "arp -a": {err: nil, out: arpAOutputWrt, code: 0}, "ip neigh": {err: nil, out: ipNeighOutput, code: 0}, </s> remove err := a.Refresh() require.NoError(t, err) </s> add t.Run("wrt", func(t *testing.T) { a := &cmdARPDB{ parse: parseArpAWrt, cmd: "arp", args: []string{"-a"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } </s> remove func TestCmdARPDB_ipneigh(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, runcmd: func() (r io.Reader, err error) { return strings.NewReader(ipNeighOutput), nil }, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> add assert.Equal(t, wantNeighs, a.Neighbors()) }) t.Run("ip_neigh", func(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, cmd: "ip", args: []string{"neigh"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> remove assert.Equal(t, wantNeighs, a.Neighbors()) } </s> add err := a.Refresh() require.NoError(t, err) </s> add cmd: "cmd", </s> remove a := &cmdARPDB{ runcmd: badReaderRunCmd, parse: parseArpA, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } const wantErrMsg string = "cmd arpdb: scanning the output: " + string(errRead) testutil.AssertErrorMsg(t, wantErrMsg, a.Refresh()) </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_linux_test.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> ns: make([]Neighbor, 0), <mask> }, <mask> } <mask> <mask> err := a.Refresh() <mask> require.NoError(t, err) <mask> <mask> assert.Equal(t, wantNeighs, a.Neighbors()) <mask> } <mask> <mask> func TestCmdARPDB_ipneigh(t *testing.T) { </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove func TestCmdARPDB_ipneigh(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, runcmd: func() (r io.Reader, err error) { return strings.NewReader(ipNeighOutput), nil }, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> add assert.Equal(t, wantNeighs, a.Neighbors()) }) t.Run("ip_neigh", func(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, cmd: "ip", args: []string{"neigh"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> remove assert.Equal(t, wantNeighs, a.Neighbors()) } </s> add err := a.Refresh() require.NoError(t, err) </s> remove assert.Equal(t, wantNeighs, a.Neighbors()) </s> add assert.Equal(t, wantNeighs, a.Neighbors()) }) </s> remove func TestCmdARPDB_arpawrt(t *testing.T) { a := &cmdARPDB{ parse: parseArpAWrt, runcmd: func() (r io.Reader, err error) { return strings.NewReader(arpAOutputWrt), nil }, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, </s> add func TestCmdARPDB_linux(t *testing.T) { sh := mapShell{ "arp -a": {err: nil, out: arpAOutputWrt, code: 0}, "ip neigh": {err: nil, out: ipNeighOutput, code: 0}, </s> remove a.runcmd = func() (r io.Reader, err error) { return strings.NewReader(arpAOutput), nil } </s> add sh := theOnlyCmd("cmd", 0, arpAOutput, nil) substShell(t, sh.RunCmd) </s> add require.NoError(t, fstest.TestFS(testdata, "proc_net_arp"))
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_linux_test.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> <mask> err := a.Refresh() <mask> require.NoError(t, err) <mask> <mask> assert.Equal(t, wantNeighs, a.Neighbors()) <mask> } <mask> <mask> func TestCmdARPDB_ipneigh(t *testing.T) { <mask> a := &cmdARPDB{ <mask> parse: parseIPNeigh, <mask> runcmd: func() (r io.Reader, err error) { return strings.NewReader(ipNeighOutput), nil }, </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove func TestCmdARPDB_ipneigh(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, runcmd: func() (r io.Reader, err error) { return strings.NewReader(ipNeighOutput), nil }, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> add assert.Equal(t, wantNeighs, a.Neighbors()) }) t.Run("ip_neigh", func(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, cmd: "ip", args: []string{"neigh"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> remove err := a.Refresh() require.NoError(t, err) </s> add t.Run("wrt", func(t *testing.T) { a := &cmdARPDB{ parse: parseArpAWrt, cmd: "arp", args: []string{"-a"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } </s> remove a.runcmd = func() (r io.Reader, err error) { return strings.NewReader(arpAOutput), nil } </s> add sh := theOnlyCmd("cmd", 0, arpAOutput, nil) substShell(t, sh.RunCmd) </s> remove func TestCmdARPDB_arpawrt(t *testing.T) { a := &cmdARPDB{ parse: parseArpAWrt, runcmd: func() (r io.Reader, err error) { return strings.NewReader(arpAOutputWrt), nil }, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, </s> add func TestCmdARPDB_linux(t *testing.T) { sh := mapShell{ "arp -a": {err: nil, out: arpAOutputWrt, code: 0}, "ip neigh": {err: nil, out: ipNeighOutput, code: 0}, </s> remove a.runcmd = func() (r io.Reader, err error) { return nil, errors.Error("can't run") } </s> add sh := theOnlyCmd("cmd", 0, "", errors.Error("can't run")) substShell(t, sh.RunCmd) </s> remove badReaderRunCmd := runCmdFunc(func() (r io.Reader, err error) { return iotest.ErrReader(errRead), nil </s> add err := a.Refresh() testutil.AssertErrorMsg(t, "cmd arpdb: running command: unexpected exit code 1", err)
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_linux_test.go
keep replace replace replace replace replace replace replace replace replace replace replace keep replace
<mask> <mask> func TestCmdARPDB_ipneigh(t *testing.T) { <mask> a := &cmdARPDB{ <mask> parse: parseIPNeigh, <mask> runcmd: func() (r io.Reader, err error) { return strings.NewReader(ipNeighOutput), nil }, <mask> ns: &neighs{ <mask> mu: &sync.RWMutex{}, <mask> ns: make([]Neighbor, 0), <mask> }, <mask> } <mask> err := a.Refresh() <mask> require.NoError(t, err) <mask> <mask> assert.Equal(t, wantNeighs, a.Neighbors()) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_linux_test.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> ) <mask> <mask> func newARPDB() *cmdARPDB { <mask> return &cmdARPDB{ <mask> runcmd: rcArpA, <mask> parse: parseArpA, <mask> ns: &neighs{ <mask> mu: &sync.RWMutex{}, <mask> ns: make([]Neighbor, 0), <mask> }, <mask> } </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove parse: parseArpA, runcmd: rcArpA, </s> add parse: parseArpA, </s> remove runcmd: rcArpA, </s> add parse: parseArpA, </s> add cmd: "cmd", </s> remove func TestCmdARPDB_ipneigh(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, runcmd: func() (r io.Reader, err error) { return strings.NewReader(ipNeighOutput), nil }, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> add assert.Equal(t, wantNeighs, a.Neighbors()) }) t.Run("ip_neigh", func(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, cmd: "ip", args: []string{"neigh"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> remove parse: parseArpA, </s> add cmd: "arp", args: []string{"/a"}, </s> remove err := a.Refresh() require.NoError(t, err) </s> add t.Run("wrt", func(t *testing.T) { a := &cmdARPDB{ parse: parseArpAWrt, cmd: "arp", args: []string{"-a"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, }
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_openbsd.go
keep add keep keep keep keep keep
<mask> ns: make([]Neighbor, 0), <mask> }, <mask> } <mask> } <mask> <mask> // parseArpA parses the output of the "arp -a" command on OpenBSD. The expected <mask> // input format: </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> add cmd: "arp", args: []string{"-a"}, </s> remove // rcArpA runs "arp /a". func rcArpA() (r io.Reader, err error) { return runCmd("arp", "/a") } </s> add </s> remove // rcIPNeigh runs "ip neigh". func rcIPNeigh() (r io.Reader, err error) { return runCmd("ip", "neigh") } </s> add </s> remove parse: parseArpA, </s> add cmd: "arp", args: []string{"/a"}, </s> add // hardwareReportsReg is the regular expression matching the lines of // networksetup command output lines containing the interface information. var hardwareReportsReg = regexp.MustCompile("Hardware Port: (.*?)\nDevice: (.*?)\n") </s> remove last: 0, </s> add neighs: neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), },
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_openbsd.go
keep keep replace keep replace keep keep keep keep
<mask> <mask> import ( <mask> "io" <mask> "net" <mask> "strings" <mask> "sync" <mask> "testing" <mask> "testing/iotest" <mask> </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove "io" </s> add </s> remove "strings" </s> add </s> remove "io" </s> add </s> remove "io" </s> add </s> remove "io" </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> "net" <mask> "strings" <mask> "sync" <mask> "testing" <mask> "testing/iotest" <mask> <mask> "github.com/AdguardTeam/golibs/errors" <mask> "github.com/AdguardTeam/golibs/testutil" <mask> "github.com/stretchr/testify/assert" <mask> "github.com/stretchr/testify/require" </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove "strings" </s> add </s> remove "strings" </s> add </s> remove "io" </s> add </s> add "testing/fstest" </s> add "github.com/AdguardTeam/golibs/testutil" </s> add "testing/fstest"
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_test.go
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> ) <mask> <mask> func TestNewARPDB(t *testing.T) { <mask> var a ARPDB <mask> require.NotPanics(t, func() { <mask> a = NewARPDB() <mask> }) <mask> <mask> assert.NotNil(t, a) <mask> } <mask> <mask> // TestARPDB is the mock implementation of ARPDB to use in tests. </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove parse parseNeighsFunc runcmd runCmdFunc ns *neighs </s> add parse parseNeighsFunc ns *neighs cmd string args []string </s> remove // runCmdFunc is the function that runs some command and returns its output // wrapped to be a io.Reader. type runCmdFunc func() (r io.Reader, err error) </s> add </s> add // aghosRunCommand is the function to run shell commands. It's an unexported // variable instead of a direct call to make it substitutable in tests. var aghosRunCommand = aghos.RunCommand // rootDirFS is the filesystem pointing to the root directory. It's an // unexported variable instead to make it substitutable in tests. var rootDirFS = aghos.RootDirFS() </s> remove // last is the last succeeded ARPDB index. last int </s> add neighs </s> add // // TODO(e.burkov): Think of a way to avoid cloning the slice twice. </s> add // etcResolvConfReg is the regular expression matching the lines of resolv.conf // file containing a name server information. var etcResolvConfReg = regexp.MustCompile("nameserver ([a-zA-Z0-9.:]+)")
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_test.go
keep replace keep keep keep replace keep
<mask> <mask> // Only the last succeeded ARPDB should be used. <mask> err = a.Refresh() <mask> require.NoError(t, err) <mask> <mask> assert.Equal(t, 2, succRefrCount) <mask> assert.NotEmpty(t, a.Neighbors()) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove assert.Equal(t, wantNeighs, a.Neighbors()) </s> add assert.Equal(t, wantNeighs, a.Neighbors()) }) </s> remove l := len(arp.arps) // Start from the last succeeded implementation. for i := 0; i < l; i++ { cur := (arp.last + i) % l err = arp.arps[cur].Refresh() if err == nil { // The succeeded implementation found so update the last succeeded // index. arp.last = cur return nil </s> add for _, a := range arp.arps { err = a.Refresh() if err != nil { errs = append(errs, err) continue </s> remove // last is the last succeeded ARPDB index. last int </s> add neighs </s> remove assert.Equal(t, wantNeighs, a.Neighbors()) } </s> add err := a.Refresh() require.NoError(t, err) </s> remove func TestCmdARPDB_ipneigh(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, runcmd: func() (r io.Reader, err error) { return strings.NewReader(ipNeighOutput), nil }, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> add assert.Equal(t, wantNeighs, a.Neighbors()) }) t.Run("ip_neigh", func(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, cmd: "ip", args: []string{"neigh"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err)
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_test.go
keep keep add keep keep keep keep
<mask> <mask> func TestCmdARPDB_arpa(t *testing.T) { <mask> a := &cmdARPDB{ <mask> parse: parseArpA, <mask> ns: &neighs{ <mask> mu: &sync.RWMutex{}, <mask> ns: make([]Neighbor, 0), </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove runcmd: rcArpA, </s> add parse: parseArpA, </s> remove runcmd: rcArpA, parse: parseArpA, </s> add parse: parseArpA, </s> remove parse: parseArpA, runcmd: rcArpA, </s> add parse: parseArpA, </s> remove err := a.Refresh() require.NoError(t, err) </s> add t.Run("wrt", func(t *testing.T) { a := &cmdARPDB{ parse: parseArpAWrt, cmd: "arp", args: []string{"-a"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } </s> remove func TestCmdARPDB_ipneigh(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, runcmd: func() (r io.Reader, err error) { return strings.NewReader(ipNeighOutput), nil }, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> add assert.Equal(t, wantNeighs, a.Neighbors()) }) t.Run("ip_neigh", func(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, cmd: "ip", args: []string{"neigh"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> remove a := &cmdARPDB{ runcmd: badReaderRunCmd, parse: parseArpA, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } const wantErrMsg string = "cmd arpdb: scanning the output: " + string(errRead) testutil.AssertErrorMsg(t, wantErrMsg, a.Refresh()) </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> }, <mask> } <mask> <mask> t.Run("arp_a", func(t *testing.T) { <mask> a.runcmd = func() (r io.Reader, err error) { return strings.NewReader(arpAOutput), nil } <mask> <mask> err := a.Refresh() <mask> require.NoError(t, err) <mask> <mask> assert.Equal(t, wantNeighs, a.Neighbors()) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove assert.Equal(t, wantNeighs, a.Neighbors()) } </s> add err := a.Refresh() require.NoError(t, err) </s> remove func TestCmdARPDB_ipneigh(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, runcmd: func() (r io.Reader, err error) { return strings.NewReader(ipNeighOutput), nil }, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> add assert.Equal(t, wantNeighs, a.Neighbors()) }) t.Run("ip_neigh", func(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, cmd: "ip", args: []string{"neigh"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> remove a.runcmd = func() (r io.Reader, err error) { return nil, errors.Error("can't run") } </s> add sh := theOnlyCmd("cmd", 0, "", errors.Error("can't run")) substShell(t, sh.RunCmd) </s> remove assert.Equal(t, wantNeighs, a.Neighbors()) </s> add assert.Equal(t, wantNeighs, a.Neighbors()) }) </s> remove err := a.Refresh() require.NoError(t, err) </s> add t.Run("wrt", func(t *testing.T) { a := &cmdARPDB{ parse: parseArpAWrt, cmd: "arp", args: []string{"-a"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } </s> remove func TestCmdARPDB_arpawrt(t *testing.T) { a := &cmdARPDB{ parse: parseArpAWrt, runcmd: func() (r io.Reader, err error) { return strings.NewReader(arpAOutputWrt), nil }, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, </s> add func TestCmdARPDB_linux(t *testing.T) { sh := mapShell{ "arp -a": {err: nil, out: arpAOutputWrt, code: 0}, "ip neigh": {err: nil, out: ipNeighOutput, code: 0},
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_test.go
keep keep replace keep keep keep keep replace
<mask> <mask> t.Run("runcmd_error", func(t *testing.T) { <mask> a.runcmd = func() (r io.Reader, err error) { return nil, errors.Error("can't run") } <mask> <mask> err := a.Refresh() <mask> testutil.AssertErrorMsg(t, "cmd arpdb: running command: can't run", err) <mask> }) <mask> } </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove func TestCmdARPDB_errors(t *testing.T) { const errRead errors.Error = "can't read" </s> add t.Run("bad_code", func(t *testing.T) { sh := theOnlyCmd("cmd", 1, "", nil) substShell(t, sh.RunCmd) </s> remove badReaderRunCmd := runCmdFunc(func() (r io.Reader, err error) { return iotest.ErrReader(errRead), nil </s> add err := a.Refresh() testutil.AssertErrorMsg(t, "cmd arpdb: running command: unexpected exit code 1", err) </s> remove a.runcmd = func() (r io.Reader, err error) { return strings.NewReader(arpAOutput), nil } </s> add sh := theOnlyCmd("cmd", 0, arpAOutput, nil) substShell(t, sh.RunCmd) </s> remove a := &cmdARPDB{ runcmd: badReaderRunCmd, parse: parseArpA, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } const wantErrMsg string = "cmd arpdb: scanning the output: " + string(errRead) testutil.AssertErrorMsg(t, wantErrMsg, a.Refresh()) </s> add </s> remove assert.Equal(t, wantNeighs, a.Neighbors()) } </s> add err := a.Refresh() require.NoError(t, err)
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_test.go
keep keep keep keep replace replace keep keep keep keep keep keep keep keep replace replace keep keep
<mask> testutil.AssertErrorMsg(t, "cmd arpdb: running command: can't run", err) <mask> }) <mask> } <mask> <mask> func TestCmdARPDB_errors(t *testing.T) { <mask> const errRead errors.Error = "can't read" <mask> <mask> badReaderRunCmd := runCmdFunc(func() (r io.Reader, err error) { <mask> return iotest.ErrReader(errRead), nil <mask> }) <mask> <mask> func TestCmdARPDB_errors(t *testing.T) { <mask> const errRead errors.Error = "can't read" <mask> <mask> badReaderRunCmd := runCmdFunc(func() (r io.Reader, err error) { <mask> return iotest.ErrReader(errRead), nil <mask> }) <mask> </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove } </s> add </s> remove a := &cmdARPDB{ runcmd: badReaderRunCmd, parse: parseArpA, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } const wantErrMsg string = "cmd arpdb: scanning the output: " + string(errRead) testutil.AssertErrorMsg(t, wantErrMsg, a.Refresh()) </s> add </s> remove a.runcmd = func() (r io.Reader, err error) { return nil, errors.Error("can't run") } </s> add sh := theOnlyCmd("cmd", 0, "", errors.Error("can't run")) substShell(t, sh.RunCmd) </s> remove assert.Equal(t, wantNeighs, a.Neighbors()) } </s> add err := a.Refresh() require.NoError(t, err) </s> remove a.runcmd = func() (r io.Reader, err error) { return strings.NewReader(arpAOutput), nil } </s> add sh := theOnlyCmd("cmd", 0, arpAOutput, nil) substShell(t, sh.RunCmd)
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_test.go
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
<mask> <mask> badReaderRunCmd := runCmdFunc(func() (r io.Reader, err error) { <mask> return iotest.ErrReader(errRead), nil <mask> }) <mask> <mask> a := &cmdARPDB{ <mask> runcmd: badReaderRunCmd, <mask> parse: parseArpA, <mask> ns: &neighs{ <mask> mu: &sync.RWMutex{}, <mask> ns: make([]Neighbor, 0), <mask> }, <mask> } <mask> <mask> const wantErrMsg string = "cmd arpdb: scanning the output: " + string(errRead) <mask> <mask> testutil.AssertErrorMsg(t, wantErrMsg, a.Refresh()) <mask> } <mask> <mask> func TestEmptyARPDB(t *testing.T) { <mask> a := EmptyARPDB{} <mask> </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove badReaderRunCmd := runCmdFunc(func() (r io.Reader, err error) { return iotest.ErrReader(errRead), nil </s> add err := a.Refresh() testutil.AssertErrorMsg(t, "cmd arpdb: running command: unexpected exit code 1", err) </s> remove func TestCmdARPDB_ipneigh(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, runcmd: func() (r io.Reader, err error) { return strings.NewReader(ipNeighOutput), nil }, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> add assert.Equal(t, wantNeighs, a.Neighbors()) }) t.Run("ip_neigh", func(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, cmd: "ip", args: []string{"neigh"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> add cmd: "cmd", </s> remove parse: parseArpA, runcmd: rcArpA, </s> add parse: parseArpA, </s> remove runcmd: rcArpA, parse: parseArpA, </s> add parse: parseArpA, </s> remove err := a.Refresh() require.NoError(t, err) </s> add t.Run("wrt", func(t *testing.T) { a := &cmdARPDB{ parse: parseArpAWrt, cmd: "arp", args: []string{"-a"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, }
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> package aghnet <mask> <mask> import ( <mask> "bufio" <mask> "io" <mask> "net" <mask> "strings" <mask> "sync" <mask> ) <mask> </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove "io" </s> add </s> remove "io" </s> add </s> remove "io" </s> add </s> remove "io" </s> add </s> add "bufio" "bytes" </s> remove "os" </s> add "io"
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_windows.go
keep replace keep keep keep keep replace
<mask> return &cmdARPDB{ <mask> runcmd: rcArpA, <mask> ns: &neighs{ <mask> mu: &sync.RWMutex{}, <mask> ns: make([]Neighbor, 0), <mask> }, <mask> parse: parseArpA, </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove runcmd: rcArpA, parse: parseArpA, </s> add parse: parseArpA, </s> remove parse: parseArpA, runcmd: rcArpA, </s> add parse: parseArpA, </s> add cmd: "cmd", </s> remove func TestCmdARPDB_ipneigh(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, runcmd: func() (r io.Reader, err error) { return strings.NewReader(ipNeighOutput), nil }, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> add assert.Equal(t, wantNeighs, a.Neighbors()) }) t.Run("ip_neigh", func(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, cmd: "ip", args: []string{"neigh"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> remove err := a.Refresh() require.NoError(t, err) </s> add t.Run("wrt", func(t *testing.T) { a := &cmdARPDB{ parse: parseArpAWrt, cmd: "arp", args: []string{"-a"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, }
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_windows.go
keep keep keep keep replace replace replace replace replace keep keep keep keep keep
<mask> parse: parseArpA, <mask> } <mask> } <mask> <mask> // rcArpA runs "arp /a". <mask> func rcArpA() (r io.Reader, err error) { <mask> return runCmd("arp", "/a") <mask> } <mask> <mask> // parseArpA parses the output of the "arp /a" command on Windows. The expected <mask> // input format (the first line is empty): <mask> // <mask> // <mask> // Interface: 192.168.56.16 --- 0x7 </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> add cmd: "arp", args: []string{"-a"}, </s> remove parse: parseArpA, </s> add cmd: "arp", args: []string{"/a"}, </s> remove // rcIPNeigh runs "ip neigh". func rcIPNeigh() (r io.Reader, err error) { return runCmd("ip", "neigh") } </s> add </s> add cmd: "arp", args: []string{"-a"}, </s> remove // runCmdFunc is the function that runs some command and returns its output // wrapped to be a io.Reader. type runCmdFunc func() (r io.Reader, err error) </s> add </s> add // hardwareReportsReg is the regular expression matching the lines of // networksetup command output lines containing the interface information. var hardwareReportsReg = regexp.MustCompile("Hardware Port: (.*?)\nDevice: (.*?)\n")
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/arpdb_windows.go
keep keep add keep keep keep keep
<mask> OnClose: func() (err error) { panic("not implemented") }, <mask> } <mask> <mask> hc, err := NewHostsContainer(0, testdata, &stubWatcher, "etc_hosts") <mask> require.NoError(t, err) <mask> testutil.CleanupAndRequireSuccess(t, hc.Close) <mask> </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove assert.Equal(t, wantNeighs, a.Neighbors()) } </s> add err := a.Refresh() require.NoError(t, err) </s> remove a.runcmd = func() (r io.Reader, err error) { return strings.NewReader(arpAOutput), nil } </s> add sh := theOnlyCmd("cmd", 0, arpAOutput, nil) substShell(t, sh.RunCmd) </s> remove func TestCmdARPDB_ipneigh(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, runcmd: func() (r io.Reader, err error) { return strings.NewReader(ipNeighOutput), nil }, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> add assert.Equal(t, wantNeighs, a.Neighbors()) }) t.Run("ip_neigh", func(t *testing.T) { a := &cmdARPDB{ parse: parseIPNeigh, cmd: "ip", args: []string{"neigh"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, } err := a.Refresh() require.NoError(t, err) </s> remove var r io.Reader r, err = arp.runcmd() </s> add code, out, err := aghosRunCommand(arp.cmd, arp.args...) </s> remove func TestCmdARPDB_arpawrt(t *testing.T) { a := &cmdARPDB{ parse: parseArpAWrt, runcmd: func() (r io.Reader, err error) { return strings.NewReader(arpAOutputWrt), nil }, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, </s> add func TestCmdARPDB_linux(t *testing.T) { sh := mapShell{ "arp -a": {err: nil, out: arpAOutputWrt, code: 0}, "ip neigh": {err: nil, out: ipNeighOutput, code: 0}, </s> remove err := a.Refresh() require.NoError(t, err) </s> add t.Run("wrt", func(t *testing.T) { a := &cmdARPDB{ parse: parseArpAWrt, cmd: "arp", args: []string{"-a"}, ns: &neighs{ mu: &sync.RWMutex{}, ns: make([]Neighbor, 0), }, }
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/hostscontainer_test.go
keep keep add keep keep keep keep keep keep
<mask> func TestHostsContainer(t *testing.T) { <mask> const listID = 1234 <mask> <mask> testCases := []struct { <mask> want []*rules.DNSRewrite <mask> name string <mask> req urlfilter.DNSRequest <mask> }{{ <mask> want: []*rules.DNSRewrite{{ </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove name string rcconfData string wantHas bool </s> add name string rootFsys fs.FS wantHas assert.BoolAssertionFunc </s> remove func TestSetStaticIPdhcpcdConf(t *testing.T) { </s> add func TestSetStaticIP_dhcpcdConfIface(t *testing.T) { </s> remove name string rcconfData string wantCont bool </s> add name string rootFsys fs.FS wantHas assert.BoolAssertionFunc </s> remove func TestHostnameIfStaticConfig(t *testing.T) { const nl = "\n" </s> add func TestIfaceHasStaticIP(t *testing.T) { const ifaceName = "em0" confFile := fmt.Sprintf("etc/hostname.%s", ifaceName) </s> remove func TestDHCPCDStaticConfig(t *testing.T) { const iface interfaceName = `wlan0` </s> add func TestHasStaticIP(t *testing.T) { const ifaceName = "wlan0" </s> remove const iface interfaceName = `em0` const nl = "\n" </s> add const ( ifaceName = `em0` rcConf = "etc/rc.conf" )
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/hostscontainer_test.go
keep keep add keep keep keep keep keep keep
<mask> package aghnet <mask> <mask> import ( <mask> "encoding/json" <mask> "fmt" <mask> "io" <mask> "net" <mask> "syscall" <mask> </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove "os/exec" "strings" </s> add </s> remove "os" </s> add "io" </s> add "bufio" "bytes" </s> remove "io" </s> add </s> add "fmt" </s> remove "io" </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> "encoding/json" <mask> "fmt" <mask> "io" <mask> "net" <mask> "os/exec" <mask> "strings" <mask> "syscall" <mask> <mask> "github.com/AdguardTeam/golibs/errors" <mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/AdguardTeam/golibs/netutil" </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> add "github.com/AdguardTeam/AdGuardHome/internal/aghos" </s> add "bytes" </s> remove "strings" </s> add </s> add "bytes" </s> add "strings" </s> remove "os" </s> add "io"
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net.go
keep keep keep add keep keep keep keep keep keep
<mask> "io" <mask> "net" <mask> "syscall" <mask> <mask> "github.com/AdguardTeam/golibs/errors" <mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/AdguardTeam/golibs/netutil" <mask> ) <mask> <mask> // aghosRunCommand is the function to run shell commands. It's an unexported </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> add // aghosRunCommand is the function to run shell commands. It's an unexported // variable instead of a direct call to make it substitutable in tests. var aghosRunCommand = aghos.RunCommand // rootDirFS is the filesystem pointing to the root directory. It's an // unexported variable instead to make it substitutable in tests. var rootDirFS = aghos.RootDirFS() </s> remove "os/exec" "strings" </s> add </s> remove "strings" </s> add </s> remove "github.com/AdguardTeam/AdGuardHome/internal/aghos" </s> add </s> add "bytes" </s> remove func TestMain(m *testing.M) { aghtest.DiscardLogOutput(m) </s> add // substRootDirFS replaces the aghos.RootDirFS function used throughout the // package with fsys for tests ran under t. func substRootDirFS(t testing.TB, fsys fs.FS) { t.Helper() prev := rootDirFS t.Cleanup(func() { rootDirFS = prev }) rootDirFS = fsys } // RunCmdFunc is the signature of aghos.RunCommand function. type RunCmdFunc func(cmd string, args ...string) (code int, out []byte, err error) // substShell replaces the the aghos.RunCommand function used throughout the // package with rc for tests ran under t. func substShell(t testing.TB, rc RunCmdFunc) { t.Helper() prev := aghosRunCommand t.Cleanup(func() { aghosRunCommand = prev }) aghosRunCommand = rc } // mapShell is a substitution of aghos.RunCommand that maps the command to it's // execution result. It's only needed to simplify testing. // // TODO(e.burkov): Perhaps put all the shell interactions behind an interface. type mapShell map[string]struct { err error out string code int } // theOnlyCmd returns s that only handles a single command and arguments // combination from cmd. func theOnlyCmd(cmd string, code int, out string, err error) (s mapShell) { return mapShell{cmd: {code: code, out: out, err: err}} } // RunCmd is a RunCmdFunc handled by s. func (s mapShell) RunCmd(cmd string, args ...string) (code int, out []byte, err error) { key := strings.Join(append([]string{cmd}, args...), " ") ret, ok := s[key] if !ok { return 0, nil, fmt.Errorf("unexpected shell command %q", key) } return ret.code, []byte(ret.out), ret.err } func TestGatewayIP(t *testing.T) { testCases := []struct { name string shell mapShell want net.IP }{{ name: "success_v4", shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via 1.2.3.4 onlink`, nil), want: net.IP{1, 2, 3, 4}.To16(), }, { name: "success_v6", shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via ::ffff onlink`, nil), want: net.IP{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xFF, 0xFF, }, }, { name: "bad_output", shell: theOnlyCmd("ip route show dev ifaceName", 0, `non-default via 1.2.3.4 onlink`, nil), want: nil, }, { name: "err_runcmd", shell: theOnlyCmd("ip route show dev ifaceName", 0, "", errors.Error("can't run command")), want: nil, }, { name: "bad_code", shell: theOnlyCmd("ip route show dev ifaceName", 1, "", nil), want: nil, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { substShell(t, tc.shell.RunCmd) assert.Equal(t, tc.want, GatewayIP("ifaceName")) }) }
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net.go
keep keep add keep keep keep keep keep keep
<mask> "github.com/AdguardTeam/golibs/netutil" <mask> ) <mask> <mask> // ErrNoStaticIPInfo is returned by IfaceHasStaticIP when no information about <mask> // the IP being static is available. <mask> const ErrNoStaticIPInfo errors.Error = "no information about static ip" <mask> <mask> // IfaceHasStaticIP checks if interface is configured to have static IP address. <mask> // If it can't give a definitive answer, it returns false and an error for which </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove // TODO(a.garipov): Currently, this function returns the first // definitive result. So if /etc/dhcpcd.conf has a static IP while // /etc/network/interfaces doesn't, it will return true. Perhaps this // is not the most desirable behavior. </s> add // TODO(a.garipov): Currently, this function returns the first definitive // result. So if /etc/dhcpcd.conf has and /etc/network/interfaces has no // static IP configuration, it will return true. Perhaps this is not the // most desirable behavior. </s> remove return walker.Walk(aghos.RootDirFS(), rcConfFilename) </s> add return walker.Walk(rootDirFS, rcConfFilename) </s> remove return aghos.FileWalker(hostnameIfStaticConfig).Walk(aghos.RootDirFS(), filename) </s> add return aghos.FileWalker(hostnameIfStaticConfig).Walk(rootDirFS, filename) </s> remove } if code != 0 { </s> add } else if code != 0 { </s> remove ifaceFound := findIfaceLine(s, string(n)) if !ifaceFound { </s> add if !findIfaceLine(s, string(n)) { </s> add // hardwareReportsReg is the regular expression matching the lines of // networksetup command output lines containing the interface information. var hardwareReportsReg = regexp.MustCompile("Hardware Port: (.*?)\nDevice: (.*?)\n")
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net.go
keep keep replace replace replace replace replace keep keep keep replace keep keep
<mask> <mask> // GatewayIP returns IP address of interface's gateway. <mask> func GatewayIP(ifaceName string) net.IP { <mask> cmd := exec.Command("ip", "route", "show", "dev", ifaceName) <mask> log.Tracef("executing %s %v", cmd.Path, cmd.Args) <mask> d, err := cmd.Output() <mask> if err != nil || cmd.ProcessState.ExitCode() != 0 { <mask> return nil <mask> } <mask> <mask> fields := strings.Fields(string(d)) <mask> // The meaningful "ip route" command output should contain the word <mask> // "default" at first field and default gateway IP address at third field. </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove if len(fields) < 3 || fields[0] != "default" { </s> add if len(fields) < 3 || string(fields[0]) != "default" { </s> remove // Man page interfaces(5) declares that interface definition // should consist of the key word "iface" followed by interface // name, and method at fourth field. </s> add // Man page interfaces(5) declares that interface definition should // consist of the key word "iface" followed by interface name, and // method at fourth field. </s> remove // TODO(a.garipov): Currently, this function returns the first // definitive result. So if /etc/dhcpcd.conf has a static IP while // /etc/network/interfaces doesn't, it will return true. Perhaps this // is not the most desirable behavior. </s> add // TODO(a.garipov): Currently, this function returns the first definitive // result. So if /etc/dhcpcd.conf has and /etc/network/interfaces has no // static IP configuration, it will return true. Perhaps this is not the // most desirable behavior. </s> remove } if code != 0 { </s> add } else if code != 0 { </s> remove func getHardwarePortInfo(hardwarePort string) (hardwarePortInfo, error) { h := hardwarePortInfo{} </s> add // hardwarePortReg is the regular expression matching the lines of networksetup // command output lines containing the port information. var hardwarePortReg = regexp.MustCompile("IP address: (.*?)\nSubnet mask: (.*?)\nRouter: (.*?)\n")
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net.go
keep replace keep keep keep replace keep keep keep keep
<mask> // "default" at first field and default gateway IP address at third field. <mask> if len(fields) < 3 || fields[0] != "default" { <mask> return nil <mask> } <mask> <mask> return net.ParseIP(fields[2]) <mask> } <mask> <mask> // CanBindPort checks if we can bind to the given port. <mask> func CanBindPort(port int) (can bool, err error) { </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove fields := strings.Fields(string(d)) </s> add fields := bytes.Fields(out) </s> remove // Man page interfaces(5) declares that interface definition // should consist of the key word "iface" followed by interface // name, and method at fourth field. </s> add // Man page interfaces(5) declares that interface definition should // consist of the key word "iface" followed by interface name, and // method at fourth field. </s> remove func ifaceHasStaticIP(ifaceName string) (bool, error) { </s> add func ifaceHasStaticIP(ifaceName string) (ok bool, err error) { </s> remove func GatewayIP(ifaceName string) net.IP { cmd := exec.Command("ip", "route", "show", "dev", ifaceName) log.Tracef("executing %s %v", cmd.Path, cmd.Args) d, err := cmd.Output() if err != nil || cmd.ProcessState.ExitCode() != 0 { </s> add // // TODO(e.burkov): Investigate if the gateway address may be fetched in another // way since not every machine has the software installed. func GatewayIP(ifaceName string) (ip net.IP) { code, out, err := aghosRunCommand("ip", "route", "show", "dev", ifaceName) if err != nil { log.Debug("%s", err) return nil } else if code != 0 { log.Debug("fetching gateway ip: unexpected exit code: %d", code) </s> remove return aghos.FileWalker(hostnameIfStaticConfig).Walk(aghos.RootDirFS(), filename) </s> add return aghos.FileWalker(hostnameIfStaticConfig).Walk(rootDirFS, filename)
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> <mask> // GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and WEB only <mask> // we do not return link-local addresses here <mask> func GetValidNetInterfacesForWeb() ([]*NetInterface, error) { <mask> ifaces, err := net.Interfaces() <mask> if err != nil { <mask> return nil, fmt.Errorf("couldn't get interfaces: %w", err) <mask> } else if len(ifaces) == 0 { <mask> return nil, errors.Error("couldn't find any legible interface") </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove var netInterfaces []*NetInterface </s> add </s> remove return nil, err } re := regexp.MustCompile("nameserver ([a-zA-Z0-9.:]+)") matches := re.FindAllStringSubmatch(string(body), -1) if len(matches) == 0 { return nil, errors.Error("found no DNS servers in /etc/resolv.conf") } addrs := make([]string, 0) for i := range matches { addrs = append(addrs, matches[i][1]) </s> add return nil, fmt.Errorf("parsing etc/resolv.conf file: %w", err) } else if len(addrs) == 0 { return nil, fmt.Errorf("found no dns servers in %s", filename) </s> remove func getEtcResolvConfServers() ([]string, error) { body, err := os.ReadFile("/etc/resolv.conf") </s> add func getEtcResolvConfServers() (addrs []string, err error) { const filename = "etc/resolv.conf" _, err = aghos.FileWalker(func(r io.Reader) (_ []string, _ bool, err error) { sc := bufio.NewScanner(r) for sc.Scan() { matches := etcResolvConfReg.FindAllStringSubmatch(sc.Text(), -1) if len(matches) == 0 { continue } for _, m := range matches { addrs = append(addrs, m[1]) } } return nil, false, sc.Err() }).Walk(rootDirFS, filename) </s> remove return nil, fmt.Errorf("got iface.Addrs() element %s that is not net.IPNet, it is %T", addr, addr) </s> add return nil, fmt.Errorf("got %s that is not net.IPNet, it is %T", addr, addr) </s> remove // runCmd runs the cmd with it's args and returns the result wrapped to be an // io.Reader. The error is returned either if the exit code retured by command // not equals 0 or the execution itself failed. func runCmd(cmd string, args ...string) (r io.Reader, err error) { var code int var out string code, out, err = aghos.RunCommand(cmd, args...) if err != nil { return nil, err } else if code != 0 { return nil, fmt.Errorf("unexpected exit code %d", code) } return strings.NewReader(out), nil } </s> add </s> remove // First of all we should find hardware port name </s> add // First of all we should find hardware port name.
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> } else if len(ifaces) == 0 { <mask> return nil, errors.Error("couldn't find any legible interface") <mask> } <mask> <mask> var netInterfaces []*NetInterface <mask> <mask> for _, iface := range ifaces { <mask> var addrs []net.Addr <mask> addrs, err = iface.Addrs() <mask> if err != nil { <mask> return nil, fmt.Errorf("failed to get addresses for interface %s: %w", iface.Name, err) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove func GetValidNetInterfacesForWeb() ([]*NetInterface, error) { </s> add func GetValidNetInterfacesForWeb() (netInterfaces []*NetInterface, err error) { </s> remove return nil, err } re := regexp.MustCompile("nameserver ([a-zA-Z0-9.:]+)") matches := re.FindAllStringSubmatch(string(body), -1) if len(matches) == 0 { return nil, errors.Error("found no DNS servers in /etc/resolv.conf") } addrs := make([]string, 0) for i := range matches { addrs = append(addrs, matches[i][1]) </s> add return nil, fmt.Errorf("parsing etc/resolv.conf file: %w", err) } else if len(addrs) == 0 { return nil, fmt.Errorf("found no dns servers in %s", filename) </s> remove func getEtcResolvConfServers() ([]string, error) { body, err := os.ReadFile("/etc/resolv.conf") </s> add func getEtcResolvConfServers() (addrs []string, err error) { const filename = "etc/resolv.conf" _, err = aghos.FileWalker(func(r io.Reader) (_ []string, _ bool, err error) { sc := bufio.NewScanner(r) for sc.Scan() { matches := etcResolvConfReg.FindAllStringSubmatch(sc.Text(), -1) if len(matches) == 0 { continue } for _, m := range matches { addrs = append(addrs, m[1]) } } return nil, false, sc.Err() }).Walk(rootDirFS, filename) </s> remove return nil, fmt.Errorf("got iface.Addrs() element %s that is not net.IPNet, it is %T", addr, addr) </s> add return nil, fmt.Errorf("got %s that is not net.IPNet, it is %T", addr, addr) </s> remove // runCmd runs the cmd with it's args and returns the result wrapped to be an // io.Reader. The error is returned either if the exit code retured by command // not equals 0 or the execution itself failed. func runCmd(cmd string, args ...string) (r io.Reader, err error) { var code int var out string code, out, err = aghos.RunCommand(cmd, args...) if err != nil { return nil, err } else if code != 0 { return nil, fmt.Errorf("unexpected exit code %d", code) } return strings.NewReader(out), nil } </s> add </s> remove } if code != 0 { </s> add } else if code != 0 {
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net.go
keep keep keep keep replace keep keep keep keep keep
<mask> for _, addr := range addrs { <mask> ipNet, ok := addr.(*net.IPNet) <mask> if !ok { <mask> // Should be net.IPNet, this is weird. <mask> return nil, fmt.Errorf("got iface.Addrs() element %s that is not net.IPNet, it is %T", addr, addr) <mask> } <mask> // Ignore link-local. <mask> if ipNet.IP.IsLinkLocalUnicast() { <mask> continue <mask> } </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove // TODO(a.garipov): Currently, this function returns the first // definitive result. So if /etc/dhcpcd.conf has a static IP while // /etc/network/interfaces doesn't, it will return true. Perhaps this // is not the most desirable behavior. </s> add // TODO(a.garipov): Currently, this function returns the first definitive // result. So if /etc/dhcpcd.conf has and /etc/network/interfaces has no // static IP configuration, it will return true. Perhaps this is not the // most desirable behavior. </s> remove var netInterfaces []*NetInterface </s> add </s> remove func getEtcResolvConfServers() ([]string, error) { body, err := os.ReadFile("/etc/resolv.conf") </s> add func getEtcResolvConfServers() (addrs []string, err error) { const filename = "etc/resolv.conf" _, err = aghos.FileWalker(func(r io.Reader) (_ []string, _ bool, err error) { sc := bufio.NewScanner(r) for sc.Scan() { matches := etcResolvConfReg.FindAllStringSubmatch(sc.Text(), -1) if len(matches) == 0 { continue } for _, m := range matches { addrs = append(addrs, m[1]) } } return nil, false, sc.Err() }).Walk(rootDirFS, filename) </s> remove return nil, err } re := regexp.MustCompile("nameserver ([a-zA-Z0-9.:]+)") matches := re.FindAllStringSubmatch(string(body), -1) if len(matches) == 0 { return nil, errors.Error("found no DNS servers in /etc/resolv.conf") } addrs := make([]string, 0) for i := range matches { addrs = append(addrs, matches[i][1]) </s> add return nil, fmt.Errorf("parsing etc/resolv.conf file: %w", err) } else if len(addrs) == 0 { return nil, fmt.Errorf("found no dns servers in %s", filename) </s> remove // First of all we should find hardware port name </s> add // First of all we should find hardware port name. </s> remove ifaceFound := findIfaceLine(s, string(n)) if !ifaceFound { </s> add if !findIfaceLine(s, string(n)) {
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net.go
keep keep add keep keep keep keep keep keep
<mask> package aghnet <mask> <mask> import ( <mask> "fmt" <mask> "io" <mask> "regexp" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghos" <mask> "github.com/AdguardTeam/golibs/errors" </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove "os" </s> add "io" </s> remove "strings" </s> add </s> add "bytes" </s> remove "io" </s> add </s> remove "io" </s> add </s> add "fmt"
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_darwin.go
keep keep replace keep replace keep keep keep keep
<mask> import ( <mask> "fmt" <mask> "os" <mask> "regexp" <mask> "strings" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghos" <mask> "github.com/AdguardTeam/golibs/errors" <mask> ) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> add "bufio" "bytes" </s> add "fmt" </s> remove "io" </s> add </s> remove "strings" </s> add </s> remove "strings" </s> add "fmt" "io/fs"
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_darwin.go
keep keep keep keep replace keep keep keep keep keep
<mask> func canBindPrivilegedPorts() (can bool, err error) { <mask> return aghos.HaveAdminRights() <mask> } <mask> <mask> func ifaceHasStaticIP(ifaceName string) (bool, error) { <mask> portInfo, err := getCurrentHardwarePortInfo(ifaceName) <mask> if err != nil { <mask> return false, err <mask> } <mask> </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove return aghos.FileWalker(hostnameIfStaticConfig).Walk(aghos.RootDirFS(), filename) </s> add return aghos.FileWalker(hostnameIfStaticConfig).Walk(rootDirFS, filename) </s> remove h.name = hardwarePort h.ip = match[1] h.subnet = match[2] h.gatewayIP = match[3] if strings.Index(out, "Manual Configuration") == 0 { h.static = true } return h, nil </s> add return hardwarePortInfo{ name: hardwarePort, ip: string(match[1]), subnet: string(match[2]), gatewayIP: string(match[3]), static: bytes.Index(out, []byte("Manual Configuration")) == 0, }, nil </s> remove return net.ParseIP(fields[2]) </s> add return net.ParseIP(string(fields[2])) </s> remove func getEtcResolvConfServers() ([]string, error) { body, err := os.ReadFile("/etc/resolv.conf") </s> add func getEtcResolvConfServers() (addrs []string, err error) { const filename = "etc/resolv.conf" _, err = aghos.FileWalker(func(r io.Reader) (_ []string, _ bool, err error) { sc := bufio.NewScanner(r) for sc.Scan() { matches := etcResolvConfReg.FindAllStringSubmatch(sc.Text(), -1) if len(matches) == 0 { continue } for _, m := range matches { addrs = append(addrs, m[1]) } } return nil, false, sc.Err() }).Walk(rootDirFS, filename) </s> remove _, out, err := aghos.RunCommand("networksetup", "-getinfo", hardwarePort) </s> add func getHardwarePortInfo(hardwarePort string) (h hardwarePortInfo, err error) { _, out, err := aghosRunCommand("networksetup", "-getinfo", hardwarePort) </s> remove } if has { </s> add } else if has {
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_darwin.go
keep replace keep replace
<mask> <mask> // getCurrentHardwarePortInfo gets information for the specified network interface. <mask> func getCurrentHardwarePortInfo(ifaceName string) (hardwarePortInfo, error) { <mask> // First of all we should find hardware port name </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove func getHardwarePortInfo(hardwarePort string) (hardwarePortInfo, error) { h := hardwarePortInfo{} </s> add // hardwarePortReg is the regular expression matching the lines of networksetup // command output lines containing the port information. var hardwarePortReg = regexp.MustCompile("IP address: (.*?)\nSubnet mask: (.*?)\nRouter: (.*?)\n") </s> remove return m </s> add return reports </s> remove h.name = hardwarePort h.ip = match[1] h.subnet = match[2] h.gatewayIP = match[3] if strings.Index(out, "Manual Configuration") == 0 { h.static = true } return h, nil </s> add return hardwarePortInfo{ name: hardwarePort, ip: string(match[1]), subnet: string(match[2]), gatewayIP: string(match[3]), static: bytes.Index(out, []byte("Manual Configuration")) == 0, }, nil </s> remove func GetValidNetInterfacesForWeb() ([]*NetInterface, error) { </s> add func GetValidNetInterfacesForWeb() (netInterfaces []*NetInterface, err error) { </s> remove _, out, err := aghos.RunCommand("networksetup", "-getinfo", hardwarePort) </s> add func getHardwarePortInfo(hardwarePort string) (h hardwarePortInfo, err error) { _, out, err := aghosRunCommand("networksetup", "-getinfo", hardwarePort)
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_darwin.go
keep add keep keep keep keep
<mask> } <mask> <mask> // getNetworkSetupHardwareReports parses the output of the `networksetup <mask> // -listallhardwareports` command it returns a map where the key is the <mask> // interface name, and the value is the "hardware port" returns nil if it fails <mask> // to parse the output </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove // runCmdFunc is the function that runs some command and returns its output // wrapped to be a io.Reader. type runCmdFunc func() (r io.Reader, err error) </s> add </s> add // aghosRunCommand is the function to run shell commands. It's an unexported // variable instead of a direct call to make it substitutable in tests. var aghosRunCommand = aghos.RunCommand // rootDirFS is the filesystem pointing to the root directory. It's an // unexported variable instead to make it substitutable in tests. var rootDirFS = aghos.RootDirFS() </s> add cmd: "arp", args: []string{"-a"}, </s> remove // TODO(a.garipov): Currently, this function returns the first // definitive result. So if /etc/dhcpcd.conf has a static IP while // /etc/network/interfaces doesn't, it will return true. Perhaps this // is not the most desirable behavior. </s> add // TODO(a.garipov): Currently, this function returns the first definitive // result. So if /etc/dhcpcd.conf has and /etc/network/interfaces has no // static IP configuration, it will return true. Perhaps this is not the // most desirable behavior. </s> add cmd: "arp", args: []string{"-a"}, </s> remove // Man page interfaces(5) declares that interface definition // should consist of the key word "iface" followed by interface // name, and method at fourth field. </s> add // Man page interfaces(5) declares that interface definition should // consist of the key word "iface" followed by interface name, and // method at fourth field.
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_darwin.go
keep keep keep replace replace replace replace replace replace replace keep keep keep keep replace keep keep
<mask> // TODO(e.burkov): There should be more proper approach than parsing the <mask> // command output. For example, see <mask> // https://developer.apple.com/documentation/systemconfiguration. <mask> func getNetworkSetupHardwareReports() map[string]string { <mask> _, out, err := aghos.RunCommand("networksetup", "-listallhardwareports") <mask> if err != nil { <mask> return nil <mask> } <mask> <mask> re, err := regexp.Compile("Hardware Port: (.*?)\nDevice: (.*?)\n") <mask> if err != nil { <mask> return nil <mask> } <mask> <mask> m := make(map[string]string) <mask> <mask> matches := re.FindAllStringSubmatch(out, -1) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove matches := re.FindAllStringSubmatch(out, -1) for i := range matches { port := matches[i][1] device := matches[i][2] m[device] = port </s> add matches := hardwareReportsReg.FindAllSubmatch(out, -1) for _, m := range matches { reports[string(m[2])] = string(m[1]) </s> remove func getHardwarePortInfo(hardwarePort string) (hardwarePortInfo, error) { h := hardwarePortInfo{} </s> add // hardwarePortReg is the regular expression matching the lines of networksetup // command output lines containing the port information. var hardwarePortReg = regexp.MustCompile("IP address: (.*?)\nSubnet mask: (.*?)\nRouter: (.*?)\n") </s> remove func GatewayIP(ifaceName string) net.IP { cmd := exec.Command("ip", "route", "show", "dev", ifaceName) log.Tracef("executing %s %v", cmd.Path, cmd.Args) d, err := cmd.Output() if err != nil || cmd.ProcessState.ExitCode() != 0 { </s> add // // TODO(e.burkov): Investigate if the gateway address may be fetched in another // way since not every machine has the software installed. func GatewayIP(ifaceName string) (ip net.IP) { code, out, err := aghosRunCommand("ip", "route", "show", "dev", ifaceName) if err != nil { log.Debug("%s", err) return nil } else if code != 0 { log.Debug("fetching gateway ip: unexpected exit code: %d", code) </s> remove _, out, err := aghos.RunCommand("networksetup", "-getinfo", hardwarePort) </s> add func getHardwarePortInfo(hardwarePort string) (h hardwarePortInfo, err error) { _, out, err := aghosRunCommand("networksetup", "-getinfo", hardwarePort) </s> remove func getEtcResolvConfServers() ([]string, error) { body, err := os.ReadFile("/etc/resolv.conf") </s> add func getEtcResolvConfServers() (addrs []string, err error) { const filename = "etc/resolv.conf" _, err = aghos.FileWalker(func(r io.Reader) (_ []string, _ bool, err error) { sc := bufio.NewScanner(r) for sc.Scan() { matches := etcResolvConfReg.FindAllStringSubmatch(sc.Text(), -1) if len(matches) == 0 { continue } for _, m := range matches { addrs = append(addrs, m[1]) } } return nil, false, sc.Err() }).Walk(rootDirFS, filename)
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_darwin.go
keep keep replace replace replace replace replace keep keep replace
<mask> m := make(map[string]string) <mask> <mask> matches := re.FindAllStringSubmatch(out, -1) <mask> for i := range matches { <mask> port := matches[i][1] <mask> device := matches[i][2] <mask> m[device] = port <mask> } <mask> <mask> return m </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove m := make(map[string]string) </s> add reports = make(map[string]string) </s> remove func getEtcResolvConfServers() ([]string, error) { body, err := os.ReadFile("/etc/resolv.conf") </s> add func getEtcResolvConfServers() (addrs []string, err error) { const filename = "etc/resolv.conf" _, err = aghos.FileWalker(func(r io.Reader) (_ []string, _ bool, err error) { sc := bufio.NewScanner(r) for sc.Scan() { matches := etcResolvConfReg.FindAllStringSubmatch(sc.Text(), -1) if len(matches) == 0 { continue } for _, m := range matches { addrs = append(addrs, m[1]) } } return nil, false, sc.Err() }).Walk(rootDirFS, filename) </s> remove return nil, err } re := regexp.MustCompile("nameserver ([a-zA-Z0-9.:]+)") matches := re.FindAllStringSubmatch(string(body), -1) if len(matches) == 0 { return nil, errors.Error("found no DNS servers in /etc/resolv.conf") } addrs := make([]string, 0) for i := range matches { addrs = append(addrs, matches[i][1]) </s> add return nil, fmt.Errorf("parsing etc/resolv.conf file: %w", err) } else if len(addrs) == 0 { return nil, fmt.Errorf("found no dns servers in %s", filename) </s> remove // First of all we should find hardware port name </s> add // First of all we should find hardware port name. </s> remove // getCurrentHardwarePortInfo gets information for the specified network interface. </s> add // getCurrentHardwarePortInfo gets information for the specified network // interface.
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_darwin.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> <mask> return m <mask> } <mask> <mask> func getHardwarePortInfo(hardwarePort string) (hardwarePortInfo, error) { <mask> h := hardwarePortInfo{} <mask> <mask> _, out, err := aghos.RunCommand("networksetup", "-getinfo", hardwarePort) <mask> if err != nil { <mask> return h, err <mask> } </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove _, out, err := aghos.RunCommand("networksetup", "-getinfo", hardwarePort) </s> add func getHardwarePortInfo(hardwarePort string) (h hardwarePortInfo, err error) { _, out, err := aghosRunCommand("networksetup", "-getinfo", hardwarePort) </s> remove return m </s> add return reports </s> remove func getNetworkSetupHardwareReports() map[string]string { _, out, err := aghos.RunCommand("networksetup", "-listallhardwareports") if err != nil { return nil } re, err := regexp.Compile("Hardware Port: (.*?)\nDevice: (.*?)\n") </s> add func getNetworkSetupHardwareReports() (reports map[string]string) { _, out, err := aghosRunCommand("networksetup", "-listallhardwareports") </s> remove func ifaceHasStaticIP(ifaceName string) (bool, error) { </s> add func ifaceHasStaticIP(ifaceName string) (ok bool, err error) { </s> remove // getCurrentHardwarePortInfo gets information for the specified network interface. </s> add // getCurrentHardwarePortInfo gets information for the specified network // interface. </s> remove h.name = hardwarePort h.ip = match[1] h.subnet = match[2] h.gatewayIP = match[3] if strings.Index(out, "Manual Configuration") == 0 { h.static = true } return h, nil </s> add return hardwarePortInfo{ name: hardwarePort, ip: string(match[1]), subnet: string(match[2]), gatewayIP: string(match[3]), static: bytes.Index(out, []byte("Manual Configuration")) == 0, }, nil
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_darwin.go
keep keep keep replace keep keep keep keep replace replace replace replace keep
<mask> func getHardwarePortInfo(hardwarePort string) (hardwarePortInfo, error) { <mask> h := hardwarePortInfo{} <mask> <mask> _, out, err := aghos.RunCommand("networksetup", "-getinfo", hardwarePort) <mask> if err != nil { <mask> return h, err <mask> } <mask> <mask> re := regexp.MustCompile("IP address: (.*?)\nSubnet mask: (.*?)\nRouter: (.*?)\n") <mask> <mask> match := re.FindStringSubmatch(out) <mask> if len(match) == 0 { <mask> return h, errors.Error("could not find hardware port info") </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove func getHardwarePortInfo(hardwarePort string) (hardwarePortInfo, error) { h := hardwarePortInfo{} </s> add // hardwarePortReg is the regular expression matching the lines of networksetup // command output lines containing the port information. var hardwarePortReg = regexp.MustCompile("IP address: (.*?)\nSubnet mask: (.*?)\nRouter: (.*?)\n") </s> remove h.name = hardwarePort h.ip = match[1] h.subnet = match[2] h.gatewayIP = match[3] if strings.Index(out, "Manual Configuration") == 0 { h.static = true } return h, nil </s> add return hardwarePortInfo{ name: hardwarePort, ip: string(match[1]), subnet: string(match[2]), gatewayIP: string(match[3]), static: bytes.Index(out, []byte("Manual Configuration")) == 0, }, nil </s> remove return m </s> add return reports </s> remove // First of all we should find hardware port name </s> add // First of all we should find hardware port name. </s> remove // getCurrentHardwarePortInfo gets information for the specified network interface. </s> add // getCurrentHardwarePortInfo gets information for the specified network // interface.
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_darwin.go
keep keep keep keep replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
<mask> if len(match) == 0 { <mask> return h, errors.Error("could not find hardware port info") <mask> } <mask> <mask> h.name = hardwarePort <mask> h.ip = match[1] <mask> h.subnet = match[2] <mask> h.gatewayIP = match[3] <mask> <mask> if strings.Index(out, "Manual Configuration") == 0 { <mask> h.static = true <mask> } <mask> <mask> return h, nil <mask> } <mask> <mask> func ifaceSetStaticIP(ifaceName string) (err error) { <mask> portInfo, err := getCurrentHardwarePortInfo(ifaceName) <mask> if err != nil { </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove re := regexp.MustCompile("IP address: (.*?)\nSubnet mask: (.*?)\nRouter: (.*?)\n") match := re.FindStringSubmatch(out) if len(match) == 0 { </s> add match := hardwarePortReg.FindSubmatch(out) if len(match) != 4 { </s> remove func ifaceHasStaticIP(ifaceName string) (bool, error) { </s> add func ifaceHasStaticIP(ifaceName string) (ok bool, err error) { </s> remove return nil, err } re := regexp.MustCompile("nameserver ([a-zA-Z0-9.:]+)") matches := re.FindAllStringSubmatch(string(body), -1) if len(matches) == 0 { return nil, errors.Error("found no DNS servers in /etc/resolv.conf") } addrs := make([]string, 0) for i := range matches { addrs = append(addrs, matches[i][1]) </s> add return nil, fmt.Errorf("parsing etc/resolv.conf file: %w", err) } else if len(addrs) == 0 { return nil, fmt.Errorf("found no dns servers in %s", filename) </s> remove // First of all we should find hardware port name </s> add // First of all we should find hardware port name. </s> remove var netInterfaces []*NetInterface </s> add </s> remove func GetValidNetInterfacesForWeb() ([]*NetInterface, error) { </s> add func GetValidNetInterfacesForWeb() (netInterfaces []*NetInterface, err error) {
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_darwin.go
keep keep keep keep replace keep keep keep keep keep
<mask> return err <mask> } <mask> <mask> if portInfo.static { <mask> return errors.Error("IP address is already static") <mask> } <mask> <mask> dnsAddrs, err := getEtcResolvConfServers() <mask> if err != nil { <mask> return err </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove func getEtcResolvConfServers() ([]string, error) { body, err := os.ReadFile("/etc/resolv.conf") </s> add func getEtcResolvConfServers() (addrs []string, err error) { const filename = "etc/resolv.conf" _, err = aghos.FileWalker(func(r io.Reader) (_ []string, _ bool, err error) { sc := bufio.NewScanner(r) for sc.Scan() { matches := etcResolvConfReg.FindAllStringSubmatch(sc.Text(), -1) if len(matches) == 0 { continue } for _, m := range matches { addrs = append(addrs, m[1]) } } return nil, false, sc.Err() }).Walk(rootDirFS, filename) </s> remove return nil, err } re := regexp.MustCompile("nameserver ([a-zA-Z0-9.:]+)") matches := re.FindAllStringSubmatch(string(body), -1) if len(matches) == 0 { return nil, errors.Error("found no DNS servers in /etc/resolv.conf") } addrs := make([]string, 0) for i := range matches { addrs = append(addrs, matches[i][1]) </s> add return nil, fmt.Errorf("parsing etc/resolv.conf file: %w", err) } else if len(addrs) == 0 { return nil, fmt.Errorf("found no dns servers in %s", filename) </s> remove fields := strings.Fields(string(d)) </s> add fields := bytes.Fields(out) </s> remove func GatewayIP(ifaceName string) net.IP { cmd := exec.Command("ip", "route", "show", "dev", ifaceName) log.Tracef("executing %s %v", cmd.Path, cmd.Args) d, err := cmd.Output() if err != nil || cmd.ProcessState.ExitCode() != 0 { </s> add // // TODO(e.burkov): Investigate if the gateway address may be fetched in another // way since not every machine has the software installed. func GatewayIP(ifaceName string) (ip net.IP) { code, out, err := aghosRunCommand("ip", "route", "show", "dev", ifaceName) if err != nil { log.Debug("%s", err) return nil } else if code != 0 { log.Debug("fetching gateway ip: unexpected exit code: %d", code) </s> remove if errors.As(err, new(*exec.ExitError)) { return cmd.ProcessState.ExitCode(), string(out), nil } else if err != nil { return 1, "", fmt.Errorf("command %q failed: %w: %s", command, err, out) </s> add if err != nil { if eerr := new(exec.ExitError); errors.As(err, &eerr) { return eerr.ExitCode(), eerr.Stderr, nil } return 1, nil, fmt.Errorf("command %q failed: %w: %s", command, err, out) </s> remove if len(fields) < 3 || fields[0] != "default" { </s> add if len(fields) < 3 || string(fields[0]) != "default" {
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_darwin.go
keep replace replace replace keep keep replace
<mask> <mask> args := make([]string, 0) <mask> args = append(args, "-setdnsservers", portInfo.name) <mask> args = append(args, dnsAddrs...) <mask> <mask> // Setting DNS servers is necessary when configuring a static IP <mask> code, _, err := aghos.RunCommand("networksetup", args...) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove } if code != 0 { </s> add } else if code != 0 { </s> remove code, _, err = aghos.RunCommand("networksetup", "-setmanual", portInfo.name, portInfo.ip, portInfo.subnet, portInfo.gatewayIP) </s> add code, _, err = aghosRunCommand( "networksetup", "-setmanual", portInfo.name, portInfo.ip, portInfo.subnet, portInfo.gatewayIP, ) </s> remove return nil, err } re := regexp.MustCompile("nameserver ([a-zA-Z0-9.:]+)") matches := re.FindAllStringSubmatch(string(body), -1) if len(matches) == 0 { return nil, errors.Error("found no DNS servers in /etc/resolv.conf") } addrs := make([]string, 0) for i := range matches { addrs = append(addrs, matches[i][1]) </s> add return nil, fmt.Errorf("parsing etc/resolv.conf file: %w", err) } else if len(addrs) == 0 { return nil, fmt.Errorf("found no dns servers in %s", filename) </s> remove // runCmd runs the cmd with it's args and returns the result wrapped to be an // io.Reader. The error is returned either if the exit code retured by command // not equals 0 or the execution itself failed. func runCmd(cmd string, args ...string) (r io.Reader, err error) { var code int var out string code, out, err = aghos.RunCommand(cmd, args...) if err != nil { return nil, err } else if code != 0 { return nil, fmt.Errorf("unexpected exit code %d", code) } return strings.NewReader(out), nil } </s> add </s> add // aghosRunCommand is the function to run shell commands. It's an unexported // variable instead of a direct call to make it substitutable in tests. var aghosRunCommand = aghos.RunCommand // rootDirFS is the filesystem pointing to the root directory. It's an // unexported variable instead to make it substitutable in tests. var rootDirFS = aghos.RootDirFS()
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_darwin.go
keep keep keep replace replace keep keep keep keep replace replace keep keep
<mask> code, _, err := aghos.RunCommand("networksetup", args...) <mask> if err != nil { <mask> return err <mask> } <mask> if code != 0 { <mask> return fmt.Errorf("failed to set DNS servers, code=%d", code) <mask> } <mask> <mask> // Actually configures hardware port to have static IP <mask> code, _, err = aghos.RunCommand("networksetup", "-setmanual", <mask> portInfo.name, portInfo.ip, portInfo.subnet, portInfo.gatewayIP) <mask> if err != nil { <mask> return err </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove } if code != 0 { </s> add } else if code != 0 { </s> remove code, _, err := aghos.RunCommand("networksetup", args...) </s> add code, _, err := aghosRunCommand("networksetup", args...) </s> remove args := make([]string, 0) args = append(args, "-setdnsservers", portInfo.name) args = append(args, dnsAddrs...) </s> add args := append([]string{"-setdnsservers", portInfo.name}, dnsAddrs...) </s> add } else if code != 0 { return fmt.Errorf("running command: unexpected exit code %d", code) </s> remove // runCmd runs the cmd with it's args and returns the result wrapped to be an // io.Reader. The error is returned either if the exit code retured by command // not equals 0 or the execution itself failed. func runCmd(cmd string, args ...string) (r io.Reader, err error) { var code int var out string code, out, err = aghos.RunCommand(cmd, args...) if err != nil { return nil, err } else if code != 0 { return nil, fmt.Errorf("unexpected exit code %d", code) } return strings.NewReader(out), nil } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_darwin.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> code, _, err = aghos.RunCommand("networksetup", "-setmanual", <mask> portInfo.name, portInfo.ip, portInfo.subnet, portInfo.gatewayIP) <mask> if err != nil { <mask> return err <mask> } <mask> if code != 0 { <mask> return fmt.Errorf("failed to set DNS servers, code=%d", code) <mask> } <mask> <mask> return nil <mask> } </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove code, _, err = aghos.RunCommand("networksetup", "-setmanual", portInfo.name, portInfo.ip, portInfo.subnet, portInfo.gatewayIP) </s> add code, _, err = aghosRunCommand( "networksetup", "-setmanual", portInfo.name, portInfo.ip, portInfo.subnet, portInfo.gatewayIP, ) </s> remove } if code != 0 { </s> add } else if code != 0 { </s> remove code, _, err := aghos.RunCommand("networksetup", args...) </s> add code, _, err := aghosRunCommand("networksetup", args...) </s> add } else if code != 0 { return fmt.Errorf("running command: unexpected exit code %d", code) </s> remove args := make([]string, 0) args = append(args, "-setdnsservers", portInfo.name) args = append(args, dnsAddrs...) </s> add args := append([]string{"-setdnsservers", portInfo.name}, dnsAddrs...) </s> remove var netInterfaces []*NetInterface </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_darwin.go
keep keep keep add keep keep keep keep keep
<mask> <mask> return nil <mask> } <mask> <mask> // getEtcResolvConfServers returns a list of nameservers configured in <mask> // /etc/resolv.conf. <mask> func getEtcResolvConfServers() (addrs []string, err error) { <mask> const filename = "etc/resolv.conf" <mask> </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove func getEtcResolvConfServers() ([]string, error) { body, err := os.ReadFile("/etc/resolv.conf") </s> add func getEtcResolvConfServers() (addrs []string, err error) { const filename = "etc/resolv.conf" _, err = aghos.FileWalker(func(r io.Reader) (_ []string, _ bool, err error) { sc := bufio.NewScanner(r) for sc.Scan() { matches := etcResolvConfReg.FindAllStringSubmatch(sc.Text(), -1) if len(matches) == 0 { continue } for _, m := range matches { addrs = append(addrs, m[1]) } } return nil, false, sc.Err() }).Walk(rootDirFS, filename) </s> remove return aghos.FileWalker(hostnameIfStaticConfig).Walk(aghos.RootDirFS(), filename) </s> add return aghos.FileWalker(hostnameIfStaticConfig).Walk(rootDirFS, filename) </s> remove return walker.Walk(aghos.RootDirFS(), rcConfFilename) </s> add return walker.Walk(rootDirFS, rcConfFilename) </s> remove return nil, err } re := regexp.MustCompile("nameserver ([a-zA-Z0-9.:]+)") matches := re.FindAllStringSubmatch(string(body), -1) if len(matches) == 0 { return nil, errors.Error("found no DNS servers in /etc/resolv.conf") } addrs := make([]string, 0) for i := range matches { addrs = append(addrs, matches[i][1]) </s> add return nil, fmt.Errorf("parsing etc/resolv.conf file: %w", err) } else if len(addrs) == 0 { return nil, fmt.Errorf("found no dns servers in %s", filename) </s> remove ifaceFound := findIfaceLine(s, string(n)) if !ifaceFound { </s> add if !findIfaceLine(s, string(n)) { </s> remove require.NotPanics(t, func() { a = NewARPDB() }) </s> add require.NotPanics(t, func() { a = NewARPDB() })
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_darwin.go
keep keep replace replace keep replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep
<mask> // getEtcResolvConfServers returns a list of nameservers configured in <mask> // /etc/resolv.conf. <mask> func getEtcResolvConfServers() ([]string, error) { <mask> body, err := os.ReadFile("/etc/resolv.conf") <mask> if err != nil { <mask> return nil, err <mask> } <mask> <mask> re := regexp.MustCompile("nameserver ([a-zA-Z0-9.:]+)") <mask> <mask> matches := re.FindAllStringSubmatch(string(body), -1) <mask> if len(matches) == 0 { <mask> return nil, errors.Error("found no DNS servers in /etc/resolv.conf") <mask> } <mask> <mask> addrs := make([]string, 0) <mask> for i := range matches { <mask> addrs = append(addrs, matches[i][1]) <mask> } <mask> </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> add // etcResolvConfReg is the regular expression matching the lines of resolv.conf // file containing a name server information. var etcResolvConfReg = regexp.MustCompile("nameserver ([a-zA-Z0-9.:]+)") </s> remove matches := re.FindAllStringSubmatch(out, -1) for i := range matches { port := matches[i][1] device := matches[i][2] m[device] = port </s> add matches := hardwareReportsReg.FindAllSubmatch(out, -1) for _, m := range matches { reports[string(m[2])] = string(m[1]) </s> remove m := make(map[string]string) </s> add reports = make(map[string]string) </s> remove var netInterfaces []*NetInterface </s> add </s> remove args := make([]string, 0) args = append(args, "-setdnsservers", portInfo.name) args = append(args, dnsAddrs...) </s> add args := append([]string{"-setdnsservers", portInfo.name}, dnsAddrs...)
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_darwin.go
keep keep keep keep replace keep keep keep keep keep
<mask> const rcConfFilename = "etc/rc.conf" <mask> <mask> walker := aghos.FileWalker(interfaceName(ifaceName).rcConfStaticConfig) <mask> <mask> return walker.Walk(aghos.RootDirFS(), rcConfFilename) <mask> } <mask> <mask> // rcConfStaticConfig checks if the interface is configured by /etc/rc.conf to <mask> // have a static IP. <mask> func (n interfaceName) rcConfStaticConfig(r io.Reader) (_ []string, cont bool, err error) { </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove ifaceFound := findIfaceLine(s, string(n)) if !ifaceFound { </s> add if !findIfaceLine(s, string(n)) { </s> remove return aghos.FileWalker(hostnameIfStaticConfig).Walk(aghos.RootDirFS(), filename) </s> add return aghos.FileWalker(hostnameIfStaticConfig).Walk(rootDirFS, filename) </s> remove func getEtcResolvConfServers() ([]string, error) { body, err := os.ReadFile("/etc/resolv.conf") </s> add func getEtcResolvConfServers() (addrs []string, err error) { const filename = "etc/resolv.conf" _, err = aghos.FileWalker(func(r io.Reader) (_ []string, _ bool, err error) { sc := bufio.NewScanner(r) for sc.Scan() { matches := etcResolvConfReg.FindAllStringSubmatch(sc.Text(), -1) if len(matches) == 0 { continue } for _, m := range matches { addrs = append(addrs, m[1]) } } return nil, false, sc.Err() }).Walk(rootDirFS, filename) </s> add // aghosRunCommand is the function to run shell commands. It's an unexported // variable instead of a direct call to make it substitutable in tests. var aghosRunCommand = aghos.RunCommand // rootDirFS is the filesystem pointing to the root directory. It's an // unexported variable instead to make it substitutable in tests. var rootDirFS = aghos.RootDirFS() </s> add // etcResolvConfReg is the regular expression matching the lines of resolv.conf // file containing a name server information. var etcResolvConfReg = regexp.MustCompile("nameserver ([a-zA-Z0-9.:]+)") </s> remove } if code != 0 { </s> add } else if code != 0 {
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_freebsd.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> package aghnet <mask> <mask> import ( <mask> "strings" <mask> "testing" <mask> <mask> "github.com/stretchr/testify/assert" <mask> "github.com/stretchr/testify/require" <mask> ) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove "strings" </s> add "fmt" "io/fs" </s> remove "bytes" </s> add "io/fs" </s> remove "io" </s> add </s> remove "io" </s> add </s> add "fmt" </s> remove "strings" </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_freebsd_test.go
keep add keep keep keep keep
<mask> "io/fs" <mask> "testing" <mask> <mask> "github.com/stretchr/testify/assert" <mask> "github.com/stretchr/testify/require" <mask> ) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> add "testing/fstest" </s> remove "strings" </s> add "io/fs" </s> remove "strings" </s> add "fmt" "io/fs" </s> remove "bytes" </s> add "io/fs" </s> add "testing/fstest" </s> add "testing/fstest"
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_freebsd_test.go
keep keep keep keep replace replace keep keep replace replace replace keep keep keep keep
<mask> "github.com/stretchr/testify/require" <mask> ) <mask> <mask> func TestRcConfStaticConfig(t *testing.T) { <mask> const iface interfaceName = `em0` <mask> const nl = "\n" <mask> <mask> testCases := []struct { <mask> name string <mask> rcconfData string <mask> wantCont bool <mask> }{{ <mask> name: "simple", <mask> rcconfData: `ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl, <mask> wantCont: false, </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove name: "simple", rcconfData: `ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl, wantCont: false, </s> add name: "simple", rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{ Data: []byte(`ifconfig_` + ifaceName + `="inet 127.0.0.253 netmask 0xffffffff"` + nl), }}, wantHas: assert.True, </s> remove name string rcconfData string wantHas bool </s> add name string rootFsys fs.FS wantHas assert.BoolAssertionFunc </s> remove func TestHostnameIfStaticConfig(t *testing.T) { const nl = "\n" </s> add func TestIfaceHasStaticIP(t *testing.T) { const ifaceName = "em0" confFile := fmt.Sprintf("etc/hostname.%s", ifaceName) </s> remove name string data []byte wantCont bool wantPatterns []string </s> add rootFsys fs.FS name string wantHas assert.BoolAssertionFunc wantErrMsg string </s> remove func TestDHCPCDStaticConfig(t *testing.T) { const iface interfaceName = `wlan0` </s> add func TestHasStaticIP(t *testing.T) { const ifaceName = "wlan0"
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_freebsd_test.go
keep replace replace replace keep replace replace replace keep
<mask> }{{ <mask> name: "simple", <mask> rcconfData: `ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl, <mask> wantCont: false, <mask> }, { <mask> name: "case_insensitiveness", <mask> rcconfData: `ifconfig_em0="InEt 127.0.0.253 NeTmAsK 0xffffffff"` + nl, <mask> wantCont: false, <mask> }, { </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove rcconfData: `# comment 1` + nl + `` + nl + `# comment 2` + nl + `ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl, wantCont: false, </s> add rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{ Data: []byte(`# comment 1` + nl + `` + nl + `# comment 2` + nl + `ifconfig_` + ifaceName + `="inet 127.0.0.253 netmask 0xffffffff"` + nl, ), }}, wantHas: assert.True, </s> remove rcconfData: `ifconfig_em0_alias="inet 127.0.0.1/24"` + nl + `ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl, wantCont: false, </s> add rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{ Data: []byte(`ifconfig_` + ifaceName + `_alias="inet 127.0.0.1/24"` + nl + `ifconfig_` + ifaceName + `="inet 127.0.0.253 netmask 0xffffffff"` + nl, ), }}, wantHas: assert.True, </s> remove rcconfData: `ifconfig_em0="inet6 127.0.0.253 netmask 0xffffffff"` + nl + `ifconfig_em0="inet 256.256.256.256 netmask 0xffffffff"` + nl + `ifconfig_em0=""` + nl, wantCont: true, </s> add rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{ Data: []byte( `ifconfig_` + ifaceName + `="inet6 127.0.0.253 netmask 0xffffffff"` + nl + `ifconfig_` + ifaceName + `="inet 256.256.256.256 netmask 0xffffffff"` + nl + `ifconfig_` + ifaceName + `=""` + nl, ), }}, wantHas: assert.False, </s> remove name string rcconfData string wantCont bool </s> add name string rootFsys fs.FS wantHas assert.BoolAssertionFunc </s> remove name: "simple", rcconfData: `inet 127.0.0.253` + nl, wantHas: true, </s> add name: "simple", rootFsys: fstest.MapFS{ confFile: &fstest.MapFile{ Data: []byte(`inet 127.0.0.253` + nl), }, }, wantHas: assert.True,
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_freebsd_test.go
keep keep replace replace replace replace replace keep keep keep keep keep keep keep replace replace replace keep keep
<mask> }, { <mask> name: "comments_and_trash", <mask> rcconfData: `# comment 1` + nl + <mask> `` + nl + <mask> `# comment 2` + nl + <mask> `ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl, <mask> wantCont: false, <mask> }, { <mask> name: "aliases", <mask> rcconfData: `ifconfig_em0_alias="inet 127.0.0.1/24"` + nl + <mask> `ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl, <mask> wantCont: false, <mask> }, { <mask> name: "aliases", <mask> rcconfData: `ifconfig_em0_alias="inet 127.0.0.1/24"` + nl + <mask> `ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl, <mask> wantCont: false, <mask> }, { <mask> name: "incorrect_config", </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove name: "case_insensitiveness", rcconfData: `ifconfig_em0="InEt 127.0.0.253 NeTmAsK 0xffffffff"` + nl, wantCont: false, </s> add name: "case_insensitiveness", rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{ Data: []byte(`ifconfig_` + ifaceName + `="InEt 127.0.0.253 NeTmAsK 0xffffffff"` + nl), }}, wantHas: assert.True, </s> remove rcconfData: `ifconfig_em0="inet6 127.0.0.253 netmask 0xffffffff"` + nl + `ifconfig_em0="inet 256.256.256.256 netmask 0xffffffff"` + nl + `ifconfig_em0=""` + nl, wantCont: true, </s> add rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{ Data: []byte( `ifconfig_` + ifaceName + `="inet6 127.0.0.253 netmask 0xffffffff"` + nl + `ifconfig_` + ifaceName + `="inet 256.256.256.256 netmask 0xffffffff"` + nl + `ifconfig_` + ifaceName + `=""` + nl, ), }}, wantHas: assert.False, </s> remove name: "simple", rcconfData: `ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl, wantCont: false, </s> add name: "simple", rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{ Data: []byte(`ifconfig_` + ifaceName + `="inet 127.0.0.253 netmask 0xffffffff"` + nl), }}, wantHas: assert.True, </s> remove rcconfData: `# comment 1` + nl + `` + nl + `# inet 127.0.0.253` + nl + `inet` + nl, wantHas: false, </s> add rootFsys: fstest.MapFS{ confFile: &fstest.MapFile{ Data: []byte(`# comment 1` + nl + nl + `# inet 127.0.0.253` + nl + `inet` + nl, ), }, }, wantHas: assert.False, </s> remove name: "case_sensitiveness", rcconfData: `InEt 127.0.0.253` + nl, wantHas: false, </s> add name: "case_sensitiveness", rootFsys: fstest.MapFS{ confFile: &fstest.MapFile{ Data: []byte(`InEt 127.0.0.253` + nl), }, }, wantHas: assert.False,
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_freebsd_test.go
keep keep keep replace replace replace replace keep keep keep replace keep keep
<mask> wantCont: false, <mask> }, { <mask> name: "incorrect_config", <mask> rcconfData: `ifconfig_em0="inet6 127.0.0.253 netmask 0xffffffff"` + nl + <mask> `ifconfig_em0="inet 256.256.256.256 netmask 0xffffffff"` + nl + <mask> `ifconfig_em0=""` + nl, <mask> wantCont: true, <mask> }} <mask> <mask> for _, tc := range testCases { <mask> r := strings.NewReader(tc.rcconfData) <mask> t.Run(tc.name, func(t *testing.T) { <mask> _, cont, err := iface.rcConfStaticConfig(r) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_freebsd_test.go
keep keep keep keep replace keep keep replace keep
<mask> <mask> for _, tc := range testCases { <mask> r := strings.NewReader(tc.rcconfData) <mask> t.Run(tc.name, func(t *testing.T) { <mask> _, cont, err := iface.rcConfStaticConfig(r) <mask> require.NoError(t, err) <mask> <mask> assert.Equal(t, tc.wantCont, cont) <mask> }) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove r := strings.NewReader(tc.rcconfData) </s> add </s> remove _, has, err := hostnameIfStaticConfig(r) </s> add substRootDirFS(t, tc.rootFsys) has, err := IfaceHasStaticIP(ifaceName) </s> remove r := strings.NewReader(tc.rcconfData) </s> add </s> remove r := bytes.NewReader(tc.data) </s> add </s> remove patterns, has, err := iface.ifacesStaticConfig(r) require.NoError(t, err) </s> add substRootDirFS(t, tc.rootFsys) has, err := IfaceHasStaticIP(ifaceName) testutil.AssertErrorMsg(t, tc.wantErrMsg, err)
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_freebsd_test.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> // dhcpcdStaticConfig checks if interface is configured by /etc/dhcpcd.conf to <mask> // have a static IP. <mask> func (n interfaceName) dhcpcdStaticConfig(r io.Reader) (subsources []string, cont bool, err error) { <mask> s := bufio.NewScanner(r) <mask> ifaceFound := findIfaceLine(s, string(n)) <mask> if !ifaceFound { <mask> return nil, true, s.Err() <mask> } <mask> <mask> for s.Scan() { <mask> line := strings.TrimSpace(s.Text()) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove return walker.Walk(aghos.RootDirFS(), rcConfFilename) </s> add return walker.Walk(rootDirFS, rcConfFilename) </s> remove return aghos.FileWalker(hostnameIfStaticConfig).Walk(aghos.RootDirFS(), filename) </s> add return aghos.FileWalker(hostnameIfStaticConfig).Walk(rootDirFS, filename) </s> remove func getEtcResolvConfServers() ([]string, error) { body, err := os.ReadFile("/etc/resolv.conf") </s> add func getEtcResolvConfServers() (addrs []string, err error) { const filename = "etc/resolv.conf" _, err = aghos.FileWalker(func(r io.Reader) (_ []string, _ bool, err error) { sc := bufio.NewScanner(r) for sc.Scan() { matches := etcResolvConfReg.FindAllStringSubmatch(sc.Text(), -1) if len(matches) == 0 { continue } for _, m := range matches { addrs = append(addrs, m[1]) } } return nil, false, sc.Err() }).Walk(rootDirFS, filename) </s> remove // TODO(a.garipov): Currently, this function returns the first // definitive result. So if /etc/dhcpcd.conf has a static IP while // /etc/network/interfaces doesn't, it will return true. Perhaps this // is not the most desirable behavior. </s> add // TODO(a.garipov): Currently, this function returns the first definitive // result. So if /etc/dhcpcd.conf has and /etc/network/interfaces has no // static IP configuration, it will return true. Perhaps this is not the // most desirable behavior. </s> remove } if code != 0 { </s> add } else if code != 0 { </s> add // aghosRunCommand is the function to run shell commands. It's an unexported // variable instead of a direct call to make it substitutable in tests. var aghosRunCommand = aghos.RunCommand // rootDirFS is the filesystem pointing to the root directory. It's an // unexported variable instead to make it substitutable in tests. var rootDirFS = aghos.RootDirFS()
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_linux.go
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> <mask> fields := strings.Fields(line) <mask> fieldsNum := len(fields) <mask> <mask> // Man page interfaces(5) declares that interface definition <mask> // should consist of the key word "iface" followed by interface <mask> // name, and method at fourth field. <mask> if fieldsNum >= 4 && <mask> fields[0] == "iface" && fields[1] == string(n) && fields[3] == "static" { <mask> return nil, false, nil <mask> } <mask> </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove fields := strings.Fields(string(d)) </s> add fields := bytes.Fields(out) </s> remove if len(fields) < 3 || fields[0] != "default" { </s> add if len(fields) < 3 || string(fields[0]) != "default" { </s> remove if l := len(arp.arps); l > 0 && arp.last < l { return arp.arps[arp.last].Neighbors() } return nil </s> add return arp.clone() </s> remove func GetValidNetInterfacesForWeb() ([]*NetInterface, error) { </s> add func GetValidNetInterfacesForWeb() (netInterfaces []*NetInterface, err error) { </s> remove return nil, err } re := regexp.MustCompile("nameserver ([a-zA-Z0-9.:]+)") matches := re.FindAllStringSubmatch(string(body), -1) if len(matches) == 0 { return nil, errors.Error("found no DNS servers in /etc/resolv.conf") } addrs := make([]string, 0) for i := range matches { addrs = append(addrs, matches[i][1]) </s> add return nil, fmt.Errorf("parsing etc/resolv.conf file: %w", err) } else if len(addrs) == 0 { return nil, fmt.Errorf("found no dns servers in %s", filename) </s> add // hardwareReportsReg is the regular expression matching the lines of // networksetup command output lines containing the interface information. var hardwareReportsReg = regexp.MustCompile("Hardware Port: (.*?)\nDevice: (.*?)\n")
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_linux.go
keep keep keep keep replace replace replace replace keep keep keep keep keep
<mask> return sub, true, s.Err() <mask> } <mask> <mask> func ifaceHasStaticIP(ifaceName string) (has bool, err error) { <mask> // TODO(a.garipov): Currently, this function returns the first <mask> // definitive result. So if /etc/dhcpcd.conf has a static IP while <mask> // /etc/network/interfaces doesn't, it will return true. Perhaps this <mask> // is not the most desirable behavior. <mask> <mask> iface := interfaceName(ifaceName) <mask> <mask> for _, pair := range [...]struct { <mask> aghos.FileWalker </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove return nil, fmt.Errorf("got iface.Addrs() element %s that is not net.IPNet, it is %T", addr, addr) </s> add return nil, fmt.Errorf("got %s that is not net.IPNet, it is %T", addr, addr) </s> remove ifaceFound := findIfaceLine(s, string(n)) if !ifaceFound { </s> add if !findIfaceLine(s, string(n)) { </s> remove return aghos.FileWalker(hostnameIfStaticConfig).Walk(aghos.RootDirFS(), filename) </s> add return aghos.FileWalker(hostnameIfStaticConfig).Walk(rootDirFS, filename) </s> add // aghosRunCommand is the function to run shell commands. It's an unexported // variable instead of a direct call to make it substitutable in tests. var aghosRunCommand = aghos.RunCommand // rootDirFS is the filesystem pointing to the root directory. It's an // unexported variable instead to make it substitutable in tests. var rootDirFS = aghos.RootDirFS() </s> remove func ifaceHasStaticIP(ifaceName string) (bool, error) { </s> add func ifaceHasStaticIP(ifaceName string) (ok bool, err error) { </s> remove func GatewayIP(ifaceName string) net.IP { cmd := exec.Command("ip", "route", "show", "dev", ifaceName) log.Tracef("executing %s %v", cmd.Path, cmd.Args) d, err := cmd.Output() if err != nil || cmd.ProcessState.ExitCode() != 0 { </s> add // // TODO(e.burkov): Investigate if the gateway address may be fetched in another // way since not every machine has the software installed. func GatewayIP(ifaceName string) (ip net.IP) { code, out, err := aghosRunCommand("ip", "route", "show", "dev", ifaceName) if err != nil { log.Debug("%s", err) return nil } else if code != 0 { log.Debug("fetching gateway ip: unexpected exit code: %d", code)
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_linux.go
keep replace keep keep replace replace replace keep keep
<mask> }} { <mask> has, err = pair.Walk(aghos.RootDirFS(), pair.filename) <mask> if err != nil { <mask> return false, err <mask> } <mask> <mask> if has { <mask> return true, nil <mask> } </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove } if code != 0 { </s> add } else if code != 0 { </s> remove if errors.As(err, new(*exec.ExitError)) { return cmd.ProcessState.ExitCode(), string(out), nil } else if err != nil { return 1, "", fmt.Errorf("command %q failed: %w: %s", command, err, out) </s> add if err != nil { if eerr := new(exec.ExitError); errors.As(err, &eerr) { return eerr.ExitCode(), eerr.Stderr, nil } return 1, nil, fmt.Errorf("command %q failed: %w: %s", command, err, out) </s> remove func ifaceHasStaticIP(ifaceName string) (bool, error) { </s> add func ifaceHasStaticIP(ifaceName string) (ok bool, err error) { </s> remove sc := bufio.NewScanner(r) </s> add sc := bufio.NewScanner(bytes.NewReader(out)) </s> remove func GatewayIP(ifaceName string) net.IP { cmd := exec.Command("ip", "route", "show", "dev", ifaceName) log.Tracef("executing %s %v", cmd.Path, cmd.Args) d, err := cmd.Output() if err != nil || cmd.ProcessState.ExitCode() != 0 { </s> add // // TODO(e.burkov): Investigate if the gateway address may be fetched in another // way since not every machine has the software installed. func GatewayIP(ifaceName string) (ip net.IP) { code, out, err := aghosRunCommand("ip", "route", "show", "dev", ifaceName) if err != nil { log.Debug("%s", err) return nil } else if code != 0 { log.Debug("fetching gateway ip: unexpected exit code: %d", code)
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_linux.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> gatewayIP := GatewayIP(ifaceName) <mask> add := dhcpcdConfIface(ifaceName, ipNet, gatewayIP, ipNet.IP) <mask> <mask> body, err := os.ReadFile("/etc/dhcpcd.conf") <mask> if err != nil && !errors.Is(err, os.ErrNotExist) { <mask> return err <mask> } <mask> <mask> body = append(body, []byte(add)...) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove err = maybe.WriteFile("/etc/dhcpcd.conf", body, 0o644) </s> add err = maybe.WriteFile(filename, body, 0o644) </s> remove return nil, err } re := regexp.MustCompile("nameserver ([a-zA-Z0-9.:]+)") matches := re.FindAllStringSubmatch(string(body), -1) if len(matches) == 0 { return nil, errors.Error("found no DNS servers in /etc/resolv.conf") } addrs := make([]string, 0) for i := range matches { addrs = append(addrs, matches[i][1]) </s> add return nil, fmt.Errorf("parsing etc/resolv.conf file: %w", err) } else if len(addrs) == 0 { return nil, fmt.Errorf("found no dns servers in %s", filename) </s> remove func getEtcResolvConfServers() ([]string, error) { body, err := os.ReadFile("/etc/resolv.conf") </s> add func getEtcResolvConfServers() (addrs []string, err error) { const filename = "etc/resolv.conf" _, err = aghos.FileWalker(func(r io.Reader) (_ []string, _ bool, err error) { sc := bufio.NewScanner(r) for sc.Scan() { matches := etcResolvConfReg.FindAllStringSubmatch(sc.Text(), -1) if len(matches) == 0 { continue } for _, m := range matches { addrs = append(addrs, m[1]) } } return nil, false, sc.Err() }).Walk(rootDirFS, filename) </s> remove sc := bufio.NewScanner(r) </s> add sc := bufio.NewScanner(bytes.NewReader(out)) </s> remove m := make(map[string]string) </s> add reports = make(map[string]string) </s> remove if l := len(arp.arps); l > 0 && arp.last < l { return arp.arps[arp.last].Neighbors() } return nil </s> add return arp.clone()
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_linux.go
keep keep keep keep replace keep keep keep keep keep
<mask> return err <mask> } <mask> <mask> body = append(body, []byte(add)...) <mask> err = maybe.WriteFile("/etc/dhcpcd.conf", body, 0o644) <mask> if err != nil { <mask> return fmt.Errorf("writing conf: %w", err) <mask> } <mask> <mask> return nil </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove body, err := os.ReadFile("/etc/dhcpcd.conf") </s> add const filename = "/etc/dhcpcd.conf" body, err := os.ReadFile(filename) </s> remove sc := bufio.NewScanner(r) </s> add sc := bufio.NewScanner(bytes.NewReader(out)) </s> remove return nil, err } re := regexp.MustCompile("nameserver ([a-zA-Z0-9.:]+)") matches := re.FindAllStringSubmatch(string(body), -1) if len(matches) == 0 { return nil, errors.Error("found no DNS servers in /etc/resolv.conf") } addrs := make([]string, 0) for i := range matches { addrs = append(addrs, matches[i][1]) </s> add return nil, fmt.Errorf("parsing etc/resolv.conf file: %w", err) } else if len(addrs) == 0 { return nil, fmt.Errorf("found no dns servers in %s", filename) </s> add // TODO(e.burkov): This error seems unreachable. Investigate. </s> add } else if code != 0 { return fmt.Errorf("running command: unexpected exit code %d", code) </s> remove var netInterfaces []*NetInterface </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_linux.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> package aghnet <mask> <mask> import ( <mask> "bytes" <mask> "net" <mask> "testing" <mask> <mask> "github.com/stretchr/testify/assert" <mask> "github.com/stretchr/testify/require" </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove "strings" </s> add "io/fs" </s> remove "strings" </s> add "fmt" "io/fs" </s> add "bytes" </s> remove "io" </s> add </s> add "fmt" </s> remove "io" </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_linux_test.go
keep keep add keep keep keep keep keep keep
<mask> "io/fs" <mask> "net" <mask> "testing" <mask> <mask> "github.com/AdguardTeam/golibs/testutil" <mask> "github.com/stretchr/testify/assert" <mask> ) <mask> <mask> func TestHasStaticIP(t *testing.T) { </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> add "github.com/AdguardTeam/golibs/testutil" </s> remove "testing/iotest" </s> add </s> remove "github.com/stretchr/testify/require" </s> add </s> add "testing/fstest" </s> remove "bytes" </s> add "io/fs" </s> add "testing/fstest"
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_linux_test.go
keep keep keep add keep keep keep keep
<mask> "net" <mask> "testing" <mask> "testing/fstest" <mask> <mask> "github.com/stretchr/testify/assert" <mask> ) <mask> <mask> func TestHasStaticIP(t *testing.T) { </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> add "testing/fstest" </s> add "testing/fstest" </s> add "testing/fstest" </s> remove "github.com/stretchr/testify/require" </s> add </s> add "testing/fstest" </s> remove func TestDHCPCDStaticConfig(t *testing.T) { const iface interfaceName = `wlan0` </s> add func TestHasStaticIP(t *testing.T) { const ifaceName = "wlan0"
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_linux_test.go
keep keep keep keep replace keep keep replace replace keep keep
<mask> "net" <mask> "testing" <mask> <mask> "github.com/stretchr/testify/assert" <mask> "github.com/stretchr/testify/require" <mask> ) <mask> <mask> func TestDHCPCDStaticConfig(t *testing.T) { <mask> const iface interfaceName = `wlan0` <mask> <mask> testCases := []struct { </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove const iface interfaceName = `em0` const nl = "\n" </s> add const ( ifaceName = `em0` rcConf = "etc/rc.conf" ) </s> remove func TestHostnameIfStaticConfig(t *testing.T) { const nl = "\n" </s> add func TestIfaceHasStaticIP(t *testing.T) { const ifaceName = "em0" confFile := fmt.Sprintf("etc/hostname.%s", ifaceName) </s> remove testCases := []struct { name string data []byte wantCont bool }{{ name: "has_not", data: []byte(`#comment` + nl + `# comment` + nl + `interface eth0` + nl + `static ip_address=192.168.0.1/24` + nl + `# interface ` + iface + nl + `static ip_address=192.168.1.1/24` + nl + `# comment` + nl, ), wantCont: true, }, { name: "has", data: []byte(`#comment` + nl + `# comment` + nl + `interface eth0` + nl + `static ip_address=192.168.0.1/24` + nl + `# interface ` + iface + nl + `static ip_address=192.168.1.1/24` + nl + `# comment` + nl + `interface ` + iface + nl + `# comment` + nl + `static ip_address=192.168.2.1/24` + nl, ), wantCont: false, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { r := bytes.NewReader(tc.data) _, cont, err := iface.dhcpcdStaticConfig(r) require.NoError(t, err) assert.Equal(t, tc.wantCont, cont) }) } } func TestIfacesStaticConfig(t *testing.T) { const iface interfaceName = `enp0s3` </s> add const ( dhcpcd = "etc/dhcpcd.conf" netifaces = "etc/network/interfaces" ) </s> add "testing/fstest" </s> remove name string rcconfData string wantCont bool </s> add name string rootFsys fs.FS wantHas assert.BoolAssertionFunc
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_linux_test.go
keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep replace replace replace replace
<mask> const iface interfaceName = `wlan0` <mask> <mask> testCases := []struct { <mask> name string <mask> data []byte <mask> wantCont bool <mask> }{{ <mask> name: "has_not", <mask> data: []byte(`#comment` + nl + <mask> `# comment` + nl + <mask> `interface eth0` + nl + <mask> `static ip_address=192.168.0.1/24` + nl + <mask> `# interface ` + iface + nl + <mask> `static ip_address=192.168.1.1/24` + nl + <mask> `# comment` + nl, <mask> ), <mask> wantCont: true, <mask> }, { <mask> name: "has", <mask> data: []byte(`#comment` + nl + <mask> `# comment` + nl + <mask> `interface eth0` + nl + <mask> `static ip_address=192.168.0.1/24` + nl + <mask> `# interface ` + iface + nl + <mask> `static ip_address=192.168.1.1/24` + nl + <mask> `# comment` + nl + <mask> `interface ` + iface + nl + <mask> `# comment` + nl + <mask> `static ip_address=192.168.2.1/24` + nl, <mask> ), <mask> wantCont: false, <mask> }} <mask> <mask> for _, tc := range testCases { <mask> t.Run(tc.name, func(t *testing.T) { <mask> r := bytes.NewReader(tc.data) <mask> _, cont, err := iface.dhcpcdStaticConfig(r) <mask> require.NoError(t, err) <mask> <mask> assert.Equal(t, tc.wantCont, cont) <mask> }) <mask> } <mask> } <mask> <mask> func TestIfacesStaticConfig(t *testing.T) { <mask> const iface interfaceName = `enp0s3` <mask> <mask> testCases := []struct { <mask> name string <mask> data []byte <mask> wantCont bool <mask> wantPatterns []string </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove name: "has_not", data: []byte(`allow-hotplug ` + iface + nl + `#iface enp0s3 inet static` + nl + `# address 192.168.0.200` + nl + `# netmask 255.255.255.0` + nl + `# gateway 192.168.0.1` + nl + `iface ` + iface + ` inet dhcp` + nl, ), wantCont: true, wantPatterns: []string{}, </s> add rootFsys: fstest.MapFS{ dhcpcd: &fstest.MapFile{ Data: []byte(`#comment` + nl + `# comment` + nl + `interface eth0` + nl + `static ip_address=192.168.0.1/24` + nl + `# interface ` + ifaceName + nl + `static ip_address=192.168.1.1/24` + nl + `# comment` + nl, ), }, }, name: "dhcpcd_has_not", wantHas: assert.False, wantErrMsg: `no information about static ip`, }, { rootFsys: fstest.MapFS{ dhcpcd: &fstest.MapFile{ Data: []byte(`#comment` + nl + `# comment` + nl + `interface ` + ifaceName + nl + `static ip_address=192.168.0.1/24` + nl + `# interface ` + ifaceName + nl + `static ip_address=192.168.1.1/24` + nl + `# comment` + nl, ), }, }, name: "dhcpcd_has", wantHas: assert.True, wantErrMsg: ``, </s> remove name: "has", data: []byte(`allow-hotplug ` + iface + nl + `iface ` + iface + ` inet static` + nl + ` address 192.168.0.200` + nl + ` netmask 255.255.255.0` + nl + ` gateway 192.168.0.1` + nl + `#iface ` + iface + ` inet dhcp` + nl, ), wantCont: false, wantPatterns: []string{}, </s> add rootFsys: fstest.MapFS{ netifaces: &fstest.MapFile{ Data: []byte(`allow-hotplug ` + ifaceName + nl + `#iface enp0s3 inet static` + nl + `# address 192.168.0.200` + nl + `# netmask 255.255.255.0` + nl + `# gateway 192.168.0.1` + nl + `iface ` + ifaceName + ` inet dhcp` + nl, ), }, }, name: "netifaces_has_not", wantHas: assert.False, wantErrMsg: `no information about static ip`, </s> remove rcconfData: `# comment 1` + nl + `` + nl + `# comment 2` + nl + `ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl, wantCont: false, </s> add rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{ Data: []byte(`# comment 1` + nl + `` + nl + `# comment 2` + nl + `ifconfig_` + ifaceName + `="inet 127.0.0.253 netmask 0xffffffff"` + nl, ), }}, wantHas: assert.True, </s> remove rcconfData: `# comment 1` + nl + `` + nl + `# inet 127.0.0.253` + nl + `inet` + nl, wantHas: false, </s> add rootFsys: fstest.MapFS{ confFile: &fstest.MapFile{ Data: []byte(`# comment 1` + nl + nl + `# inet 127.0.0.253` + nl + `inet` + nl, ), }, }, wantHas: assert.False, </s> remove name: "return_patterns", data: []byte(`source hello` + nl + `source world` + nl + `#iface ` + iface + ` inet static` + nl, ), wantCont: true, wantPatterns: []string{"hello", "world"}, </s> add rootFsys: fstest.MapFS{ netifaces: &fstest.MapFile{ Data: []byte(`allow-hotplug ` + ifaceName + nl + `iface ` + ifaceName + ` inet static` + nl + ` address 192.168.0.200` + nl + ` netmask 255.255.255.0` + nl + ` gateway 192.168.0.1` + nl + `#iface ` + ifaceName + ` inet dhcp` + nl, ), }, }, name: "netifaces_has", wantHas: assert.True, wantErrMsg: ``,
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_linux_test.go
keep replace replace replace replace replace replace replace replace replace replace keep replace replace replace replace replace replace replace replace replace replace keep
<mask> }{{ <mask> name: "has_not", <mask> data: []byte(`allow-hotplug ` + iface + nl + <mask> `#iface enp0s3 inet static` + nl + <mask> `# address 192.168.0.200` + nl + <mask> `# netmask 255.255.255.0` + nl + <mask> `# gateway 192.168.0.1` + nl + <mask> `iface ` + iface + ` inet dhcp` + nl, <mask> ), <mask> wantCont: true, <mask> wantPatterns: []string{}, <mask> }, { <mask> name: "has", <mask> data: []byte(`allow-hotplug ` + iface + nl + <mask> `iface ` + iface + ` inet static` + nl + <mask> ` address 192.168.0.200` + nl + <mask> ` netmask 255.255.255.0` + nl + <mask> ` gateway 192.168.0.1` + nl + <mask> `#iface ` + iface + ` inet dhcp` + nl, <mask> ), <mask> wantCont: false, <mask> wantPatterns: []string{}, <mask> }, { </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove name: "return_patterns", data: []byte(`source hello` + nl + `source world` + nl + `#iface ` + iface + ` inet static` + nl, ), wantCont: true, wantPatterns: []string{"hello", "world"}, </s> add rootFsys: fstest.MapFS{ netifaces: &fstest.MapFile{ Data: []byte(`allow-hotplug ` + ifaceName + nl + `iface ` + ifaceName + ` inet static` + nl + ` address 192.168.0.200` + nl + ` netmask 255.255.255.0` + nl + ` gateway 192.168.0.1` + nl + `#iface ` + ifaceName + ` inet dhcp` + nl, ), }, }, name: "netifaces_has", wantHas: assert.True, wantErrMsg: ``, </s> remove // This one tests if the first found valid interface prevents // checking files under the `source` directive. name: "ignore_patterns", data: []byte(`source hello` + nl + `source world` + nl + `iface ` + iface + ` inet static` + nl, ), wantCont: false, wantPatterns: []string{}, </s> add rootFsys: fstest.MapFS{ netifaces: &fstest.MapFile{ Data: []byte(`source hello` + nl + `#iface ` + ifaceName + ` inet static` + nl, ), }, "hello": &fstest.MapFile{ Data: []byte(`iface ` + ifaceName + ` inet static` + nl), }, }, name: "netifaces_another_file", wantHas: assert.True, wantErrMsg: ``, }, { rootFsys: fstest.MapFS{ netifaces: &fstest.MapFile{ Data: []byte(`source hello` + nl + `iface ` + ifaceName + ` inet static` + nl, ), }, }, name: "netifaces_ignore_another", wantHas: assert.True, wantErrMsg: ``, </s> remove name string data []byte wantCont bool wantPatterns []string </s> add rootFsys fs.FS name string wantHas assert.BoolAssertionFunc wantErrMsg string </s> remove testCases := []struct { name string data []byte wantCont bool }{{ name: "has_not", data: []byte(`#comment` + nl + `# comment` + nl + `interface eth0` + nl + `static ip_address=192.168.0.1/24` + nl + `# interface ` + iface + nl + `static ip_address=192.168.1.1/24` + nl + `# comment` + nl, ), wantCont: true, }, { name: "has", data: []byte(`#comment` + nl + `# comment` + nl + `interface eth0` + nl + `static ip_address=192.168.0.1/24` + nl + `# interface ` + iface + nl + `static ip_address=192.168.1.1/24` + nl + `# comment` + nl + `interface ` + iface + nl + `# comment` + nl + `static ip_address=192.168.2.1/24` + nl, ), wantCont: false, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { r := bytes.NewReader(tc.data) _, cont, err := iface.dhcpcdStaticConfig(r) require.NoError(t, err) assert.Equal(t, tc.wantCont, cont) }) } } func TestIfacesStaticConfig(t *testing.T) { const iface interfaceName = `enp0s3` </s> add const ( dhcpcd = "etc/dhcpcd.conf" netifaces = "etc/network/interfaces" ) </s> remove rcconfData: `# comment 1` + nl + `` + nl + `# inet 127.0.0.253` + nl + `inet` + nl, wantHas: false, </s> add rootFsys: fstest.MapFS{ confFile: &fstest.MapFile{ Data: []byte(`# comment 1` + nl + nl + `# inet 127.0.0.253` + nl + `inet` + nl, ), }, }, wantHas: assert.False,
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_linux_test.go
keep keep keep replace replace replace replace replace replace replace keep replace replace replace replace replace replace replace replace replace
<mask> wantCont: false, <mask> wantPatterns: []string{}, <mask> }, { <mask> name: "return_patterns", <mask> data: []byte(`source hello` + nl + <mask> `source world` + nl + <mask> `#iface ` + iface + ` inet static` + nl, <mask> ), <mask> wantCont: true, <mask> wantPatterns: []string{"hello", "world"}, <mask> }, { <mask> // This one tests if the first found valid interface prevents <mask> // checking files under the `source` directive. <mask> name: "ignore_patterns", <mask> data: []byte(`source hello` + nl + <mask> `source world` + nl + <mask> `iface ` + iface + ` inet static` + nl, <mask> ), <mask> wantCont: false, <mask> wantPatterns: []string{}, </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove name: "has", data: []byte(`allow-hotplug ` + iface + nl + `iface ` + iface + ` inet static` + nl + ` address 192.168.0.200` + nl + ` netmask 255.255.255.0` + nl + ` gateway 192.168.0.1` + nl + `#iface ` + iface + ` inet dhcp` + nl, ), wantCont: false, wantPatterns: []string{}, </s> add rootFsys: fstest.MapFS{ netifaces: &fstest.MapFile{ Data: []byte(`allow-hotplug ` + ifaceName + nl + `#iface enp0s3 inet static` + nl + `# address 192.168.0.200` + nl + `# netmask 255.255.255.0` + nl + `# gateway 192.168.0.1` + nl + `iface ` + ifaceName + ` inet dhcp` + nl, ), }, }, name: "netifaces_has_not", wantHas: assert.False, wantErrMsg: `no information about static ip`, </s> remove name: "has_not", data: []byte(`allow-hotplug ` + iface + nl + `#iface enp0s3 inet static` + nl + `# address 192.168.0.200` + nl + `# netmask 255.255.255.0` + nl + `# gateway 192.168.0.1` + nl + `iface ` + iface + ` inet dhcp` + nl, ), wantCont: true, wantPatterns: []string{}, </s> add rootFsys: fstest.MapFS{ dhcpcd: &fstest.MapFile{ Data: []byte(`#comment` + nl + `# comment` + nl + `interface eth0` + nl + `static ip_address=192.168.0.1/24` + nl + `# interface ` + ifaceName + nl + `static ip_address=192.168.1.1/24` + nl + `# comment` + nl, ), }, }, name: "dhcpcd_has_not", wantHas: assert.False, wantErrMsg: `no information about static ip`, }, { rootFsys: fstest.MapFS{ dhcpcd: &fstest.MapFile{ Data: []byte(`#comment` + nl + `# comment` + nl + `interface ` + ifaceName + nl + `static ip_address=192.168.0.1/24` + nl + `# interface ` + ifaceName + nl + `static ip_address=192.168.1.1/24` + nl + `# comment` + nl, ), }, }, name: "dhcpcd_has", wantHas: assert.True, wantErrMsg: ``, </s> remove testCases := []struct { name string data []byte wantCont bool }{{ name: "has_not", data: []byte(`#comment` + nl + `# comment` + nl + `interface eth0` + nl + `static ip_address=192.168.0.1/24` + nl + `# interface ` + iface + nl + `static ip_address=192.168.1.1/24` + nl + `# comment` + nl, ), wantCont: true, }, { name: "has", data: []byte(`#comment` + nl + `# comment` + nl + `interface eth0` + nl + `static ip_address=192.168.0.1/24` + nl + `# interface ` + iface + nl + `static ip_address=192.168.1.1/24` + nl + `# comment` + nl + `interface ` + iface + nl + `# comment` + nl + `static ip_address=192.168.2.1/24` + nl, ), wantCont: false, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { r := bytes.NewReader(tc.data) _, cont, err := iface.dhcpcdStaticConfig(r) require.NoError(t, err) assert.Equal(t, tc.wantCont, cont) }) } } func TestIfacesStaticConfig(t *testing.T) { const iface interfaceName = `enp0s3` </s> add const ( dhcpcd = "etc/dhcpcd.conf" netifaces = "etc/network/interfaces" ) </s> remove name string data []byte wantCont bool wantPatterns []string </s> add rootFsys fs.FS name string wantHas assert.BoolAssertionFunc wantErrMsg string </s> remove rcconfData: `# comment 1` + nl + `` + nl + `# inet 127.0.0.253` + nl + `inet` + nl, wantHas: false, </s> add rootFsys: fstest.MapFS{ confFile: &fstest.MapFile{ Data: []byte(`# comment 1` + nl + nl + `# inet 127.0.0.253` + nl + `inet` + nl, ), }, }, wantHas: assert.False,
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_linux_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> wantPatterns: []string{}, <mask> }} <mask> <mask> for _, tc := range testCases { <mask> r := bytes.NewReader(tc.data) <mask> t.Run(tc.name, func(t *testing.T) { <mask> patterns, has, err := iface.ifacesStaticConfig(r) <mask> require.NoError(t, err) <mask> <mask> assert.Equal(t, tc.wantCont, has) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove patterns, has, err := iface.ifacesStaticConfig(r) require.NoError(t, err) </s> add substRootDirFS(t, tc.rootFsys) has, err := IfaceHasStaticIP(ifaceName) testutil.AssertErrorMsg(t, tc.wantErrMsg, err) </s> remove r := strings.NewReader(tc.rcconfData) </s> add </s> remove r := strings.NewReader(tc.rcconfData) </s> add </s> remove _, has, err := hostnameIfStaticConfig(r) </s> add substRootDirFS(t, tc.rootFsys) has, err := IfaceHasStaticIP(ifaceName) </s> remove assert.Equal(t, tc.wantCont, has) assert.ElementsMatch(t, tc.wantPatterns, patterns) </s> add tc.wantHas(t, has) </s> remove _, cont, err := iface.rcConfStaticConfig(r) </s> add substRootDirFS(t, tc.rootFsys) has, err := IfaceHasStaticIP(ifaceName)
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_linux_test.go
keep keep keep replace replace keep replace replace keep
<mask> for _, tc := range testCases { <mask> r := bytes.NewReader(tc.data) <mask> t.Run(tc.name, func(t *testing.T) { <mask> patterns, has, err := iface.ifacesStaticConfig(r) <mask> require.NoError(t, err) <mask> <mask> assert.Equal(t, tc.wantCont, has) <mask> assert.ElementsMatch(t, tc.wantPatterns, patterns) <mask> }) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove r := bytes.NewReader(tc.data) </s> add </s> remove _, has, err := hostnameIfStaticConfig(r) </s> add substRootDirFS(t, tc.rootFsys) has, err := IfaceHasStaticIP(ifaceName) </s> remove _, cont, err := iface.rcConfStaticConfig(r) </s> add substRootDirFS(t, tc.rootFsys) has, err := IfaceHasStaticIP(ifaceName) </s> remove r := strings.NewReader(tc.rcconfData) </s> add </s> remove r := strings.NewReader(tc.rcconfData) </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_linux_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> }) <mask> } <mask> } <mask> <mask> func TestSetStaticIPdhcpcdConf(t *testing.T) { <mask> testCases := []struct { <mask> name string <mask> dhcpcdConf string <mask> routers net.IP <mask> }{{ </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove name string rcconfData string wantHas bool </s> add name string rootFsys fs.FS wantHas assert.BoolAssertionFunc </s> add require.NoError(t, fstest.TestFS(testdata, "etc_hosts")) </s> remove name string rcconfData string wantCont bool </s> add name string rootFsys fs.FS wantHas assert.BoolAssertionFunc </s> remove func TestHostnameIfStaticConfig(t *testing.T) { const nl = "\n" </s> add func TestIfaceHasStaticIP(t *testing.T) { const ifaceName = "em0" confFile := fmt.Sprintf("etc/hostname.%s", ifaceName) </s> remove name string data []byte wantCont bool wantPatterns []string </s> add rootFsys fs.FS name string wantHas assert.BoolAssertionFunc wantErrMsg string </s> remove const iface interfaceName = `em0` const nl = "\n" </s> add const ( ifaceName = `em0` rcConf = "etc/rc.conf" )
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_linux_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> func ifaceHasStaticIP(ifaceName string) (ok bool, err error) { <mask> filename := fmt.Sprintf("etc/hostname.%s", ifaceName) <mask> <mask> return aghos.FileWalker(hostnameIfStaticConfig).Walk(aghos.RootDirFS(), filename) <mask> } <mask> <mask> // hostnameIfStaticConfig checks if the interface is configured by <mask> // /etc/hostname.* to have a static IP. <mask> func hostnameIfStaticConfig(r io.Reader) (_ []string, ok bool, err error) { </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove return walker.Walk(aghos.RootDirFS(), rcConfFilename) </s> add return walker.Walk(rootDirFS, rcConfFilename) </s> remove ifaceFound := findIfaceLine(s, string(n)) if !ifaceFound { </s> add if !findIfaceLine(s, string(n)) { </s> remove func ifaceHasStaticIP(ifaceName string) (bool, error) { </s> add func ifaceHasStaticIP(ifaceName string) (ok bool, err error) { </s> remove func getEtcResolvConfServers() ([]string, error) { body, err := os.ReadFile("/etc/resolv.conf") </s> add func getEtcResolvConfServers() (addrs []string, err error) { const filename = "etc/resolv.conf" _, err = aghos.FileWalker(func(r io.Reader) (_ []string, _ bool, err error) { sc := bufio.NewScanner(r) for sc.Scan() { matches := etcResolvConfReg.FindAllStringSubmatch(sc.Text(), -1) if len(matches) == 0 { continue } for _, m := range matches { addrs = append(addrs, m[1]) } } return nil, false, sc.Err() }).Walk(rootDirFS, filename) </s> remove // TODO(a.garipov): Currently, this function returns the first // definitive result. So if /etc/dhcpcd.conf has a static IP while // /etc/network/interfaces doesn't, it will return true. Perhaps this // is not the most desirable behavior. </s> add // TODO(a.garipov): Currently, this function returns the first definitive // result. So if /etc/dhcpcd.conf has and /etc/network/interfaces has no // static IP configuration, it will return true. Perhaps this is not the // most desirable behavior. </s> remove return net.ParseIP(fields[2]) </s> add return net.ParseIP(string(fields[2]))
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_openbsd.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> package aghnet <mask> <mask> import ( <mask> "strings" <mask> "testing" <mask> <mask> "github.com/stretchr/testify/assert" <mask> "github.com/stretchr/testify/require" <mask> ) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove "strings" </s> add "io/fs" </s> remove "bytes" </s> add "io/fs" </s> remove "io" </s> add </s> remove "io" </s> add </s> add "fmt" </s> remove "strings" </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_openbsd_test.go
keep keep keep add keep keep keep keep keep
<mask> import ( <mask> "fmt" <mask> "io/fs" <mask> "testing" <mask> <mask> "github.com/stretchr/testify/assert" <mask> "github.com/stretchr/testify/require" <mask> ) <mask> </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove "strings" </s> add "fmt" "io/fs" </s> remove "strings" </s> add "io/fs" </s> remove "bytes" </s> add "io/fs" </s> add "testing/fstest" </s> add "fmt" </s> remove "strings" </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_openbsd_test.go
keep keep keep replace replace keep keep replace replace replace keep keep keep
<mask> "github.com/stretchr/testify/require" <mask> ) <mask> <mask> func TestHostnameIfStaticConfig(t *testing.T) { <mask> const nl = "\n" <mask> <mask> testCases := []struct { <mask> name string <mask> rcconfData string <mask> wantHas bool <mask> }{{ <mask> name: "simple", <mask> rcconfData: `inet 127.0.0.253` + nl, </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove name string rcconfData string wantCont bool </s> add name string rootFsys fs.FS wantHas assert.BoolAssertionFunc </s> remove name: "simple", rcconfData: `inet 127.0.0.253` + nl, wantHas: true, </s> add name: "simple", rootFsys: fstest.MapFS{ confFile: &fstest.MapFile{ Data: []byte(`inet 127.0.0.253` + nl), }, }, wantHas: assert.True, </s> remove const iface interfaceName = `em0` const nl = "\n" </s> add const ( ifaceName = `em0` rcConf = "etc/rc.conf" ) </s> remove name string data []byte wantCont bool wantPatterns []string </s> add rootFsys fs.FS name string wantHas assert.BoolAssertionFunc wantErrMsg string </s> remove name: "simple", rcconfData: `ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl, wantCont: false, </s> add name: "simple", rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{ Data: []byte(`ifconfig_` + ifaceName + `="inet 127.0.0.253 netmask 0xffffffff"` + nl), }}, wantHas: assert.True,
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_openbsd_test.go
keep replace replace replace keep replace replace replace keep keep keep
<mask> }{{ <mask> name: "simple", <mask> rcconfData: `inet 127.0.0.253` + nl, <mask> wantHas: true, <mask> }, { <mask> name: "case_sensitiveness", <mask> rcconfData: `InEt 127.0.0.253` + nl, <mask> wantHas: false, <mask> }, { <mask> name: "comments_and_trash", <mask> rcconfData: `# comment 1` + nl + </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove rcconfData: `# comment 1` + nl + `` + nl + `# inet 127.0.0.253` + nl + `inet` + nl, wantHas: false, </s> add rootFsys: fstest.MapFS{ confFile: &fstest.MapFile{ Data: []byte(`# comment 1` + nl + nl + `# inet 127.0.0.253` + nl + `inet` + nl, ), }, }, wantHas: assert.False, </s> remove name: "case_insensitiveness", rcconfData: `ifconfig_em0="InEt 127.0.0.253 NeTmAsK 0xffffffff"` + nl, wantCont: false, </s> add name: "case_insensitiveness", rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{ Data: []byte(`ifconfig_` + ifaceName + `="InEt 127.0.0.253 NeTmAsK 0xffffffff"` + nl), }}, wantHas: assert.True, </s> remove rcconfData: `# comment 1` + nl + `` + nl + `# comment 2` + nl + `ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl, wantCont: false, </s> add rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{ Data: []byte(`# comment 1` + nl + `` + nl + `# comment 2` + nl + `ifconfig_` + ifaceName + `="inet 127.0.0.253 netmask 0xffffffff"` + nl, ), }}, wantHas: assert.True, </s> remove rcconfData: `inet6 127.0.0.253` + nl + `inet 256.256.256.256` + nl, wantHas: false, </s> add rootFsys: fstest.MapFS{ confFile: &fstest.MapFile{ Data: []byte(`inet6 127.0.0.253` + nl + `inet 256.256.256.256` + nl), }, }, wantHas: assert.False, </s> remove name string rcconfData string wantHas bool </s> add name string rootFsys fs.FS wantHas assert.BoolAssertionFunc
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_openbsd_test.go
keep keep replace replace replace replace replace keep keep replace replace replace keep keep keep
<mask> }, { <mask> name: "comments_and_trash", <mask> rcconfData: `# comment 1` + nl + <mask> `` + nl + <mask> `# inet 127.0.0.253` + nl + <mask> `inet` + nl, <mask> wantHas: false, <mask> }, { <mask> name: "incorrect_config", <mask> rcconfData: `inet6 127.0.0.253` + nl + <mask> `inet 256.256.256.256` + nl, <mask> wantHas: false, <mask> }} <mask> <mask> for _, tc := range testCases { </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove name: "case_sensitiveness", rcconfData: `InEt 127.0.0.253` + nl, wantHas: false, </s> add name: "case_sensitiveness", rootFsys: fstest.MapFS{ confFile: &fstest.MapFile{ Data: []byte(`InEt 127.0.0.253` + nl), }, }, wantHas: assert.False, </s> remove rcconfData: `# comment 1` + nl + `` + nl + `# comment 2` + nl + `ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl, wantCont: false, </s> add rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{ Data: []byte(`# comment 1` + nl + `` + nl + `# comment 2` + nl + `ifconfig_` + ifaceName + `="inet 127.0.0.253 netmask 0xffffffff"` + nl, ), }}, wantHas: assert.True, </s> remove name: "case_insensitiveness", rcconfData: `ifconfig_em0="InEt 127.0.0.253 NeTmAsK 0xffffffff"` + nl, wantCont: false, </s> add name: "case_insensitiveness", rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{ Data: []byte(`ifconfig_` + ifaceName + `="InEt 127.0.0.253 NeTmAsK 0xffffffff"` + nl), }}, wantHas: assert.True, </s> remove rcconfData: `ifconfig_em0="inet6 127.0.0.253 netmask 0xffffffff"` + nl + `ifconfig_em0="inet 256.256.256.256 netmask 0xffffffff"` + nl + `ifconfig_em0=""` + nl, wantCont: true, </s> add rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{ Data: []byte( `ifconfig_` + ifaceName + `="inet6 127.0.0.253 netmask 0xffffffff"` + nl + `ifconfig_` + ifaceName + `="inet 256.256.256.256 netmask 0xffffffff"` + nl + `ifconfig_` + ifaceName + `=""` + nl, ), }}, wantHas: assert.False, </s> remove rcconfData: `ifconfig_em0_alias="inet 127.0.0.1/24"` + nl + `ifconfig_em0="inet 127.0.0.253 netmask 0xffffffff"` + nl, wantCont: false, </s> add rootFsys: fstest.MapFS{rcConf: &fstest.MapFile{ Data: []byte(`ifconfig_` + ifaceName + `_alias="inet 127.0.0.1/24"` + nl + `ifconfig_` + ifaceName + `="inet 127.0.0.253 netmask 0xffffffff"` + nl, ), }}, wantHas: assert.True,
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_openbsd_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> wantHas: false, <mask> }} <mask> <mask> for _, tc := range testCases { <mask> r := strings.NewReader(tc.rcconfData) <mask> t.Run(tc.name, func(t *testing.T) { <mask> _, has, err := hostnameIfStaticConfig(r) <mask> require.NoError(t, err) <mask> <mask> assert.Equal(t, tc.wantHas, has) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove _, has, err := hostnameIfStaticConfig(r) </s> add substRootDirFS(t, tc.rootFsys) has, err := IfaceHasStaticIP(ifaceName) </s> remove r := bytes.NewReader(tc.data) </s> add </s> remove r := strings.NewReader(tc.rcconfData) </s> add </s> remove _, cont, err := iface.rcConfStaticConfig(r) </s> add substRootDirFS(t, tc.rootFsys) has, err := IfaceHasStaticIP(ifaceName) </s> remove assert.Equal(t, tc.wantHas, has) </s> add tc.wantHas(t, has) </s> remove patterns, has, err := iface.ifacesStaticConfig(r) require.NoError(t, err) </s> add substRootDirFS(t, tc.rootFsys) has, err := IfaceHasStaticIP(ifaceName) testutil.AssertErrorMsg(t, tc.wantErrMsg, err)
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_openbsd_test.go
keep replace keep keep replace keep
<mask> t.Run(tc.name, func(t *testing.T) { <mask> _, has, err := hostnameIfStaticConfig(r) <mask> require.NoError(t, err) <mask> <mask> assert.Equal(t, tc.wantHas, has) <mask> }) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove r := strings.NewReader(tc.rcconfData) </s> add </s> remove assert.Equal(t, tc.wantCont, has) assert.ElementsMatch(t, tc.wantPatterns, patterns) </s> add tc.wantHas(t, has) </s> remove patterns, has, err := iface.ifacesStaticConfig(r) require.NoError(t, err) </s> add substRootDirFS(t, tc.rootFsys) has, err := IfaceHasStaticIP(ifaceName) testutil.AssertErrorMsg(t, tc.wantErrMsg, err) </s> remove assert.Equal(t, tc.wantCont, cont) </s> add tc.wantHas(t, has) </s> remove r := bytes.NewReader(tc.data) </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_openbsd_test.go
keep keep add keep keep keep keep keep
<mask> package aghnet <mask> <mask> import ( <mask> "io/fs" <mask> "net" <mask> "os" <mask> "strings" <mask> "testing" </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove "strings" </s> add "io/fs" </s> remove "strings" </s> add "fmt" "io/fs" </s> remove "bytes" </s> add "io/fs" </s> remove "io" </s> add </s> remove "io" </s> add </s> remove "os" </s> add "io"
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_test.go
keep keep add keep keep keep keep keep
<mask> "io/fs" <mask> "net" <mask> "os" <mask> "testing" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghtest" <mask> "github.com/AdguardTeam/golibs/errors" <mask> "github.com/AdguardTeam/golibs/netutil" </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> add "fmt" </s> add "bytes" </s> remove "strings" </s> add </s> remove "os/exec" "strings" </s> add </s> remove "github.com/AdguardTeam/AdGuardHome/internal/aghos" </s> add </s> remove "bytes" </s> add "io/fs"
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_test.go
keep keep keep add keep keep keep keep keep
<mask> "github.com/stretchr/testify/assert" <mask> "github.com/stretchr/testify/require" <mask> ) <mask> <mask> // testdata is the filesystem containing data for testing the package. <mask> var testdata fs.FS = os.DirFS("./testdata") <mask> <mask> // substRootDirFS replaces the aghos.RootDirFS function used throughout the <mask> // package with fsys for tests ran under t. </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove func TestMain(m *testing.M) { aghtest.DiscardLogOutput(m) </s> add // substRootDirFS replaces the aghos.RootDirFS function used throughout the // package with fsys for tests ran under t. func substRootDirFS(t testing.TB, fsys fs.FS) { t.Helper() prev := rootDirFS t.Cleanup(func() { rootDirFS = prev }) rootDirFS = fsys } // RunCmdFunc is the signature of aghos.RunCommand function. type RunCmdFunc func(cmd string, args ...string) (code int, out []byte, err error) // substShell replaces the the aghos.RunCommand function used throughout the // package with rc for tests ran under t. func substShell(t testing.TB, rc RunCmdFunc) { t.Helper() prev := aghosRunCommand t.Cleanup(func() { aghosRunCommand = prev }) aghosRunCommand = rc } // mapShell is a substitution of aghos.RunCommand that maps the command to it's // execution result. It's only needed to simplify testing. // // TODO(e.burkov): Perhaps put all the shell interactions behind an interface. type mapShell map[string]struct { err error out string code int } // theOnlyCmd returns s that only handles a single command and arguments // combination from cmd. func theOnlyCmd(cmd string, code int, out string, err error) (s mapShell) { return mapShell{cmd: {code: code, out: out, err: err}} } // RunCmd is a RunCmdFunc handled by s. func (s mapShell) RunCmd(cmd string, args ...string) (code int, out []byte, err error) { key := strings.Join(append([]string{cmd}, args...), " ") ret, ok := s[key] if !ok { return 0, nil, fmt.Errorf("unexpected shell command %q", key) } return ret.code, []byte(ret.out), ret.err } func TestGatewayIP(t *testing.T) { testCases := []struct { name string shell mapShell want net.IP }{{ name: "success_v4", shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via 1.2.3.4 onlink`, nil), want: net.IP{1, 2, 3, 4}.To16(), }, { name: "success_v6", shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via ::ffff onlink`, nil), want: net.IP{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xFF, 0xFF, }, }, { name: "bad_output", shell: theOnlyCmd("ip route show dev ifaceName", 0, `non-default via 1.2.3.4 onlink`, nil), want: nil, }, { name: "err_runcmd", shell: theOnlyCmd("ip route show dev ifaceName", 0, "", errors.Error("can't run command")), want: nil, }, { name: "bad_code", shell: theOnlyCmd("ip route show dev ifaceName", 1, "", nil), want: nil, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { substShell(t, tc.shell.RunCmd) assert.Equal(t, tc.want, GatewayIP("ifaceName")) }) } </s> add // aghosRunCommand is the function to run shell commands. It's an unexported // variable instead of a direct call to make it substitutable in tests. var aghosRunCommand = aghos.RunCommand // rootDirFS is the filesystem pointing to the root directory. It's an // unexported variable instead to make it substitutable in tests. var rootDirFS = aghos.RootDirFS() </s> add // hardwareReportsReg is the regular expression matching the lines of // networksetup command output lines containing the interface information. var hardwareReportsReg = regexp.MustCompile("Hardware Port: (.*?)\nDevice: (.*?)\n") </s> remove // runCmdFunc is the function that runs some command and returns its output // wrapped to be a io.Reader. type runCmdFunc func() (r io.Reader, err error) </s> add </s> remove // runCmd runs the cmd with it's args and returns the result wrapped to be an // io.Reader. The error is returned either if the exit code retured by command // not equals 0 or the execution itself failed. func runCmd(cmd string, args ...string) (r io.Reader, err error) { var code int var out string code, out, err = aghos.RunCommand(cmd, args...) if err != nil { return nil, err } else if code != 0 { return nil, fmt.Errorf("unexpected exit code %d", code) } return strings.NewReader(out), nil } </s> add </s> add // etcResolvConfReg is the regular expression matching the lines of resolv.conf // file containing a name server information. var etcResolvConfReg = regexp.MustCompile("nameserver ([a-zA-Z0-9.:]+)")
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_test.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> <mask> // testdata is the filesystem containing data for testing the package. <mask> var testdata fs.FS = os.DirFS("./testdata") <mask> <mask> func TestMain(m *testing.M) { <mask> aghtest.DiscardLogOutput(m) <mask> } <mask> <mask> func TestGetInterfaceByIP(t *testing.T) { <mask> ifaces, err := GetValidNetInterfacesForWeb() <mask> require.NoError(t, err) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> add func TestMain(m *testing.M) { aghtest.DiscardLogOutput(m) } </s> remove func GetValidNetInterfacesForWeb() ([]*NetInterface, error) { </s> add func GetValidNetInterfacesForWeb() (netInterfaces []*NetInterface, err error) { </s> remove func getHardwarePortInfo(hardwarePort string) (hardwarePortInfo, error) { h := hardwarePortInfo{} </s> add // hardwarePortReg is the regular expression matching the lines of networksetup // command output lines containing the port information. var hardwarePortReg = regexp.MustCompile("IP address: (.*?)\nSubnet mask: (.*?)\nRouter: (.*?)\n") </s> add // etcResolvConfReg is the regular expression matching the lines of resolv.conf // file containing a name server information. var etcResolvConfReg = regexp.MustCompile("nameserver ([a-zA-Z0-9.:]+)") </s> remove l := len(arp.arps) // Start from the last succeeded implementation. for i := 0; i < l; i++ { cur := (arp.last + i) % l err = arp.arps[cur].Refresh() if err == nil { // The succeeded implementation found so update the last succeeded // index. arp.last = cur return nil </s> add for _, a := range arp.arps { err = a.Refresh() if err != nil { errs = append(errs, err) continue </s> add t.Skip("TODO(e.burkov): Substitute the net.Interfaces.")
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_test.go
keep keep keep add keep keep keep keep
<mask> }) <mask> } <mask> <mask> func TestCollectAllIfacesAddrs(t *testing.T) { <mask> addrs, err := CollectAllIfacesAddrs() <mask> require.NoError(t, err) <mask> <mask> assert.NotEmpty(t, addrs) </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove assert.Equal(t, 2, succRefrCount) </s> add assert.Equal(t, 1, succRefrCount) </s> remove assert.Equal(t, tc.wantCont, has) assert.ElementsMatch(t, tc.wantPatterns, patterns) </s> add tc.wantHas(t, has) </s> remove assert.Equal(t, tc.wantHas, has) </s> add tc.wantHas(t, has) </s> remove assert.Equal(t, tc.wantCont, cont) </s> add tc.wantHas(t, has) </s> remove _, cont, err := iface.rcConfStaticConfig(r) </s> add substRootDirFS(t, tc.rootFsys) has, err := IfaceHasStaticIP(ifaceName) </s> remove _, has, err := hostnameIfStaticConfig(r) </s> add substRootDirFS(t, tc.rootFsys) has, err := IfaceHasStaticIP(ifaceName)
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghnet/net_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> // bytes. <mask> const MaxCmdOutputSize = 64 * 1024 <mask> <mask> // RunCommand runs shell command. <mask> func RunCommand(command string, arguments ...string) (code int, output string, err error) { <mask> cmd := exec.Command(command, arguments...) <mask> out, err := cmd.Output() <mask> if len(out) > MaxCmdOutputSize { <mask> out = out[:MaxCmdOutputSize] <mask> } </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove if errors.As(err, new(*exec.ExitError)) { return cmd.ProcessState.ExitCode(), string(out), nil } else if err != nil { return 1, "", fmt.Errorf("command %q failed: %w: %s", command, err, out) </s> add if err != nil { if eerr := new(exec.ExitError); errors.As(err, &eerr) { return eerr.ExitCode(), eerr.Stderr, nil } return 1, nil, fmt.Errorf("command %q failed: %w: %s", command, err, out) </s> remove func TestMain(m *testing.M) { aghtest.DiscardLogOutput(m) </s> add // substRootDirFS replaces the aghos.RootDirFS function used throughout the // package with fsys for tests ran under t. func substRootDirFS(t testing.TB, fsys fs.FS) { t.Helper() prev := rootDirFS t.Cleanup(func() { rootDirFS = prev }) rootDirFS = fsys } // RunCmdFunc is the signature of aghos.RunCommand function. type RunCmdFunc func(cmd string, args ...string) (code int, out []byte, err error) // substShell replaces the the aghos.RunCommand function used throughout the // package with rc for tests ran under t. func substShell(t testing.TB, rc RunCmdFunc) { t.Helper() prev := aghosRunCommand t.Cleanup(func() { aghosRunCommand = prev }) aghosRunCommand = rc } // mapShell is a substitution of aghos.RunCommand that maps the command to it's // execution result. It's only needed to simplify testing. // // TODO(e.burkov): Perhaps put all the shell interactions behind an interface. type mapShell map[string]struct { err error out string code int } // theOnlyCmd returns s that only handles a single command and arguments // combination from cmd. func theOnlyCmd(cmd string, code int, out string, err error) (s mapShell) { return mapShell{cmd: {code: code, out: out, err: err}} } // RunCmd is a RunCmdFunc handled by s. func (s mapShell) RunCmd(cmd string, args ...string) (code int, out []byte, err error) { key := strings.Join(append([]string{cmd}, args...), " ") ret, ok := s[key] if !ok { return 0, nil, fmt.Errorf("unexpected shell command %q", key) } return ret.code, []byte(ret.out), ret.err } func TestGatewayIP(t *testing.T) { testCases := []struct { name string shell mapShell want net.IP }{{ name: "success_v4", shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via 1.2.3.4 onlink`, nil), want: net.IP{1, 2, 3, 4}.To16(), }, { name: "success_v6", shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via ::ffff onlink`, nil), want: net.IP{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xFF, 0xFF, }, }, { name: "bad_output", shell: theOnlyCmd("ip route show dev ifaceName", 0, `non-default via 1.2.3.4 onlink`, nil), want: nil, }, { name: "err_runcmd", shell: theOnlyCmd("ip route show dev ifaceName", 0, "", errors.Error("can't run command")), want: nil, }, { name: "bad_code", shell: theOnlyCmd("ip route show dev ifaceName", 1, "", nil), want: nil, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { substShell(t, tc.shell.RunCmd) assert.Equal(t, tc.want, GatewayIP("ifaceName")) }) } </s> remove // runCmd runs the cmd with it's args and returns the result wrapped to be an // io.Reader. The error is returned either if the exit code retured by command // not equals 0 or the execution itself failed. func runCmd(cmd string, args ...string) (r io.Reader, err error) { var code int var out string code, out, err = aghos.RunCommand(cmd, args...) if err != nil { return nil, err } else if code != 0 { return nil, fmt.Errorf("unexpected exit code %d", code) } return strings.NewReader(out), nil } </s> add </s> remove return cmd.ProcessState.ExitCode(), string(out), nil </s> add return cmd.ProcessState.ExitCode(), out, nil </s> remove func GatewayIP(ifaceName string) net.IP { cmd := exec.Command("ip", "route", "show", "dev", ifaceName) log.Tracef("executing %s %v", cmd.Path, cmd.Args) d, err := cmd.Output() if err != nil || cmd.ProcessState.ExitCode() != 0 { </s> add // // TODO(e.burkov): Investigate if the gateway address may be fetched in another // way since not every machine has the software installed. func GatewayIP(ifaceName string) (ip net.IP) { code, out, err := aghosRunCommand("ip", "route", "show", "dev", ifaceName) if err != nil { log.Debug("%s", err) return nil } else if code != 0 { log.Debug("fetching gateway ip: unexpected exit code: %d", code) </s> remove func getHardwarePortInfo(hardwarePort string) (hardwarePortInfo, error) { h := hardwarePortInfo{} </s> add // hardwarePortReg is the regular expression matching the lines of networksetup // command output lines containing the port information. var hardwarePortReg = regexp.MustCompile("IP address: (.*?)\nSubnet mask: (.*?)\nRouter: (.*?)\n")
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghos/os.go
keep keep replace replace replace replace keep keep replace keep
<mask> } <mask> <mask> if errors.As(err, new(*exec.ExitError)) { <mask> return cmd.ProcessState.ExitCode(), string(out), nil <mask> } else if err != nil { <mask> return 1, "", fmt.Errorf("command %q failed: %w: %s", command, err, out) <mask> } <mask> <mask> return cmd.ProcessState.ExitCode(), string(out), nil <mask> } </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove } if has { </s> add } else if has { </s> remove } if code != 0 { </s> add } else if code != 0 { </s> remove return nil, err } re := regexp.MustCompile("nameserver ([a-zA-Z0-9.:]+)") matches := re.FindAllStringSubmatch(string(body), -1) if len(matches) == 0 { return nil, errors.Error("found no DNS servers in /etc/resolv.conf") } addrs := make([]string, 0) for i := range matches { addrs = append(addrs, matches[i][1]) </s> add return nil, fmt.Errorf("parsing etc/resolv.conf file: %w", err) } else if len(addrs) == 0 { return nil, fmt.Errorf("found no dns servers in %s", filename) </s> add } else if code != 0 { return fmt.Errorf("running command: unexpected exit code %d", code) </s> remove } if code != 0 { </s> add } else if code != 0 {
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/aghos/os.go
keep replace keep keep keep keep replace keep keep keep
<mask> // in mind, when replace the aghos.RunCommand. <mask> _, out, err = aghos.RunCommand(scriptPath, cmd) <mask> if errors.Is(err, os.ErrNotExist) { <mask> return "", service.ErrNotInstalled <mask> } <mask> <mask> return out, err <mask> } <mask> <mask> // Status implements service.Service interface for *openbsdRunComService. </s> Pull request: 2846 cover aghnet vol.3 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.3 to master Updates #2846. Squashed commit of the following: commit cb22987c43c17bbc8d098e65639cc84e2284bc7b Merge: cf995e9d f31ffcc5 Author: Eugene Burkov <[email protected]> Date: Wed Mar 30 15:01:10 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit cf995e9dce635f16e10406a61e2ab12f06407f1f Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:29:50 2022 +0300 aghnet: imp tests commit bc225fe8800633b29216840bc7d5b82d7c2d2bfb Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 18:03:06 2022 +0300 aghnet: imp tests commit a82eb6045495b94a2e81ced9a3ef5bfe65788e56 Merge: f8081249 0d562a7b Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:39:13 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit f80812490c49f69655d409c6f015b069affa2f19 Merge: edccaa79 3603b1fc Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 17:29:20 2022 +0300 Merge branch 'master' into 2846-cover-aghnet-vol.3 commit edccaa79fca061ffeea1985c293eed123b16a09c Author: Eugene Burkov <[email protected]> Date: Mon Mar 28 13:53:40 2022 +0300 aghnet: imp tests commit 7c5028c92f0a6680516bda67c73e794182c9b825 Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 18:01:28 2022 +0300 aghnet: imp code & docs commit 7897c6b13e9be340ae8a71947a8a0bab82c682eb Author: Eugene Burkov <[email protected]> Date: Fri Mar 25 17:11:46 2022 +0300 aghnet: imp coverage commit 1eef110af3bf721a0275c695bf27c31815abff04 Author: Eugene Burkov <[email protected]> Date: Wed Mar 23 21:10:29 2022 +0300 all: return byte slice </s> remove var r io.Reader r, err = arp.runcmd() </s> add code, out, err := aghosRunCommand(arp.cmd, arp.args...) </s> remove return cmd.ProcessState.ExitCode(), string(out), nil </s> add return cmd.ProcessState.ExitCode(), out, nil </s> remove func getNetworkSetupHardwareReports() map[string]string { _, out, err := aghos.RunCommand("networksetup", "-listallhardwareports") if err != nil { return nil } re, err := regexp.Compile("Hardware Port: (.*?)\nDevice: (.*?)\n") </s> add func getNetworkSetupHardwareReports() (reports map[string]string) { _, out, err := aghosRunCommand("networksetup", "-listallhardwareports") </s> remove if l := len(arp.arps); l > 0 && arp.last < l { return arp.arps[arp.last].Neighbors() } return nil </s> add return arp.clone() </s> remove // runCmd runs the cmd with it's args and returns the result wrapped to be an // io.Reader. The error is returned either if the exit code retured by command // not equals 0 or the execution itself failed. func runCmd(cmd string, args ...string) (r io.Reader, err error) { var code int var out string code, out, err = aghos.RunCommand(cmd, args...) if err != nil { return nil, err } else if code != 0 { return nil, fmt.Errorf("unexpected exit code %d", code) } return strings.NewReader(out), nil } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5e71f5df6a8cd12a65fecd2f1e28b2aa69609193
internal/home/service_openbsd.go
keep keep keep keep replace keep keep keep keep keep
<mask> formatTime, <mask> formatDateTime, <mask> isToday, <mask> } from '../../helpers/helpers'; <mask> import { SERVICES, FILTERED_STATUS, TABLE_DEFAULT_PAGE_SIZE } from '../../helpers/constants'; <mask> import { getTrackerData } from '../../helpers/trackers/trackers'; <mask> import { formatClientCell } from '../../helpers/formatClientCell'; <mask> <mask> import Filters from './Filters'; <mask> import PageTitle from '../ui/PageTitle'; </s> Merge: + client: show filter name for blocked items in the query log Closes #993 Squashed commit of the following: commit 4c5e17226c6efa8a7847a8c565c491a7bae2db59 Author: Ildar Kamalov <[email protected]> Date: Wed Jan 29 12:21:40 2020 +0300 - client: use constant commit 818c07d1cfb210965a6413dc8370fc8867979c7b Author: Ildar Kamalov <[email protected]> Date: Wed Jan 29 12:18:31 2020 +0300 - client: fix filter find commit 1f9132151c843dacbf26f814faeeea3cfdff9b73 Author: Ildar Kamalov <[email protected]> Date: Tue Jan 28 15:52:29 2020 +0300 + client: show filter name for blocked items in the query log </s> remove if (typeof filterItem !== 'undefined' && typeof filters[filterItem] !== 'undefined') { filterName = filters[filterItem].name; } if (!filterName) { filterName = t('unknown_filter', { filterId }); } </s> add return ( <div className="logs__row logs__row--column"> <div className="logs__text-wrap"> <span className="logs__text"> <Trans>blocked_by_response</Trans> </span> </div> <div className="logs__list-wrap"> {this.renderResponseList(normalizedAnswer, status)} </div> </div> ); </s> remove if (filterId === 0) { filterName = t('custom_filter_rules'); } else { const filterItem = Object.keys(filters).filter(key => filters[key].id === filterId)[0]; </s> add if (isBlockedCnameIp) { const normalizedAnswer = this.normalizeResponse(originalAnswer); </s> remove const filterKey = reason.replace(FILTERED_REASON, ''); const parsedFilteredReason = t('query_log_filtered', { filter: filterKey }); </s> add const isBlackList = this.checkBlackList(reason); </s> remove const normalizedAnswer = originalAnswer && this.normalizeResponse(originalAnswer); let filterName = ''; </s> add const filterName = this.getFilterName(filters, filterId, t); </s> remove {originalAnswer ? this.renderResponseList(normalizedAnswer, status) : this.renderResponseList(responses, status) } </s> add {this.renderResponseList(responses, status)} </s> add checkBlackList = reason => reason === FILTERED_STATUS.FILTERED_BLACK_LIST; checkBlockedService = reason => reason === FILTERED_STATUS.FILTERED_BLOCKED_SERVICE;
https://github.com/AdguardTeam/AdGuardHome/commit/5e9c21b0a7917d0b89fe25cbf8b5790029ea2ac6
client/src/components/Logs/index.js
keep keep add keep keep keep keep keep
<mask> <mask> checkWhiteList = reason => reason === FILTERED_STATUS.NOT_FILTERED_WHITE_LIST; <mask> <mask> <mask> getDateCell = row => CellWrap( <mask> row, <mask> (isToday(row.value) ? formatTime : formatDateTime), <mask> formatDateTime, </s> Merge: + client: show filter name for blocked items in the query log Closes #993 Squashed commit of the following: commit 4c5e17226c6efa8a7847a8c565c491a7bae2db59 Author: Ildar Kamalov <[email protected]> Date: Wed Jan 29 12:21:40 2020 +0300 - client: use constant commit 818c07d1cfb210965a6413dc8370fc8867979c7b Author: Ildar Kamalov <[email protected]> Date: Wed Jan 29 12:18:31 2020 +0300 - client: fix filter find commit 1f9132151c843dacbf26f814faeeea3cfdff9b73 Author: Ildar Kamalov <[email protected]> Date: Tue Jan 28 15:52:29 2020 +0300 + client: show filter name for blocked items in the query log </s> remove const normalizedAnswer = originalAnswer && this.normalizeResponse(originalAnswer); let filterName = ''; </s> add const filterName = this.getFilterName(filters, filterId, t); </s> remove const filterKey = reason.replace(FILTERED_REASON, ''); const parsedFilteredReason = t('query_log_filtered', { filter: filterKey }); </s> add const isBlackList = this.checkBlackList(reason); </s> remove const isBlockedService = reason === FILTERED_STATUS.FILTERED_BLOCKED_SERVICE; </s> add const isBlockedService = this.checkBlockedService(reason); const isBlockedCnameIp = originalAnswer; const filterKey = reason.replace(FILTERED_REASON, ''); const parsedFilteredReason = t('query_log_filtered', { filter: filterKey }); </s> remove if (filterId === 0) { filterName = t('custom_filter_rules'); } else { const filterItem = Object.keys(filters).filter(key => filters[key].id === filterId)[0]; </s> add if (isBlockedCnameIp) { const normalizedAnswer = this.normalizeResponse(originalAnswer); </s> remove if (typeof filterItem !== 'undefined' && typeof filters[filterItem] !== 'undefined') { filterName = filters[filterItem].name; } if (!filterName) { filterName = t('unknown_filter', { filterId }); } </s> add return ( <div className="logs__row logs__row--column"> <div className="logs__text-wrap"> <span className="logs__text"> <Trans>blocked_by_response</Trans> </span> </div> <div className="logs__list-wrap"> {this.renderResponseList(normalizedAnswer, status)} </div> </div> ); </s> remove {originalAnswer ? this.renderResponseList(normalizedAnswer, status) : this.renderResponseList(responses, status) } </s> add {this.renderResponseList(responses, status)}
https://github.com/AdguardTeam/AdGuardHome/commit/5e9c21b0a7917d0b89fe25cbf8b5790029ea2ac6
client/src/components/Logs/index.js
keep keep replace replace keep keep replace keep keep keep keep
<mask> <mask> const isFiltered = this.checkFiltered(reason); <mask> const filterKey = reason.replace(FILTERED_REASON, ''); <mask> const parsedFilteredReason = t('query_log_filtered', { filter: filterKey }); <mask> const isRewrite = this.checkRewrite(reason); <mask> const isWhiteList = this.checkWhiteList(reason); <mask> const isBlockedService = reason === FILTERED_STATUS.FILTERED_BLOCKED_SERVICE; <mask> const currentService = SERVICES.find(service => service.id === original.serviceName); <mask> const serviceName = currentService && currentService.name; <mask> const normalizedAnswer = originalAnswer && this.normalizeResponse(originalAnswer); <mask> let filterName = ''; </s> Merge: + client: show filter name for blocked items in the query log Closes #993 Squashed commit of the following: commit 4c5e17226c6efa8a7847a8c565c491a7bae2db59 Author: Ildar Kamalov <[email protected]> Date: Wed Jan 29 12:21:40 2020 +0300 - client: use constant commit 818c07d1cfb210965a6413dc8370fc8867979c7b Author: Ildar Kamalov <[email protected]> Date: Wed Jan 29 12:18:31 2020 +0300 - client: fix filter find commit 1f9132151c843dacbf26f814faeeea3cfdff9b73 Author: Ildar Kamalov <[email protected]> Date: Tue Jan 28 15:52:29 2020 +0300 + client: show filter name for blocked items in the query log </s> remove const normalizedAnswer = originalAnswer && this.normalizeResponse(originalAnswer); let filterName = ''; </s> add const filterName = this.getFilterName(filters, filterId, t); </s> remove if (filterId === 0) { filterName = t('custom_filter_rules'); } else { const filterItem = Object.keys(filters).filter(key => filters[key].id === filterId)[0]; </s> add if (isBlockedCnameIp) { const normalizedAnswer = this.normalizeResponse(originalAnswer); </s> add checkBlackList = reason => reason === FILTERED_STATUS.FILTERED_BLACK_LIST; checkBlockedService = reason => reason === FILTERED_STATUS.FILTERED_BLOCKED_SERVICE; </s> remove if (typeof filterItem !== 'undefined' && typeof filters[filterItem] !== 'undefined') { filterName = filters[filterItem].name; } if (!filterName) { filterName = t('unknown_filter', { filterId }); } </s> add return ( <div className="logs__row logs__row--column"> <div className="logs__text-wrap"> <span className="logs__text"> <Trans>blocked_by_response</Trans> </span> </div> <div className="logs__list-wrap"> {this.renderResponseList(normalizedAnswer, status)} </div> </div> ); </s> add {isBlackList && ( <span className="logs__text"> <Trans values={{ filter: filterName }}> query_log_filtered </Trans> </span> )}
https://github.com/AdguardTeam/AdGuardHome/commit/5e9c21b0a7917d0b89fe25cbf8b5790029ea2ac6
client/src/components/Logs/index.js
keep keep replace replace keep replace replace replace replace
<mask> const currentService = SERVICES.find(service => service.id === original.serviceName); <mask> const serviceName = currentService && currentService.name; <mask> const normalizedAnswer = originalAnswer && this.normalizeResponse(originalAnswer); <mask> let filterName = ''; <mask> <mask> if (filterId === 0) { <mask> filterName = t('custom_filter_rules'); <mask> } else { <mask> const filterItem = Object.keys(filters).filter(key => filters[key].id === filterId)[0]; </s> Merge: + client: show filter name for blocked items in the query log Closes #993 Squashed commit of the following: commit 4c5e17226c6efa8a7847a8c565c491a7bae2db59 Author: Ildar Kamalov <[email protected]> Date: Wed Jan 29 12:21:40 2020 +0300 - client: use constant commit 818c07d1cfb210965a6413dc8370fc8867979c7b Author: Ildar Kamalov <[email protected]> Date: Wed Jan 29 12:18:31 2020 +0300 - client: fix filter find commit 1f9132151c843dacbf26f814faeeea3cfdff9b73 Author: Ildar Kamalov <[email protected]> Date: Tue Jan 28 15:52:29 2020 +0300 + client: show filter name for blocked items in the query log </s> remove const isBlockedService = reason === FILTERED_STATUS.FILTERED_BLOCKED_SERVICE; </s> add const isBlockedService = this.checkBlockedService(reason); const isBlockedCnameIp = originalAnswer; const filterKey = reason.replace(FILTERED_REASON, ''); const parsedFilteredReason = t('query_log_filtered', { filter: filterKey }); </s> remove if (typeof filterItem !== 'undefined' && typeof filters[filterItem] !== 'undefined') { filterName = filters[filterItem].name; } if (!filterName) { filterName = t('unknown_filter', { filterId }); } </s> add return ( <div className="logs__row logs__row--column"> <div className="logs__text-wrap"> <span className="logs__text"> <Trans>blocked_by_response</Trans> </span> </div> <div className="logs__list-wrap"> {this.renderResponseList(normalizedAnswer, status)} </div> </div> ); </s> remove const filterKey = reason.replace(FILTERED_REASON, ''); const parsedFilteredReason = t('query_log_filtered', { filter: filterKey }); </s> add const isBlackList = this.checkBlackList(reason); </s> add checkBlackList = reason => reason === FILTERED_STATUS.FILTERED_BLACK_LIST; checkBlockedService = reason => reason === FILTERED_STATUS.FILTERED_BLOCKED_SERVICE; </s> remove import { SERVICES, FILTERED_STATUS, TABLE_DEFAULT_PAGE_SIZE } from '../../helpers/constants'; </s> add import { SERVICES, FILTERED_STATUS, TABLE_DEFAULT_PAGE_SIZE, CUSTOM_FILTERING_RULES_ID } from '../../helpers/constants';
https://github.com/AdguardTeam/AdGuardHome/commit/5e9c21b0a7917d0b89fe25cbf8b5790029ea2ac6
client/src/components/Logs/index.js