2018-06-28 13:39:48 +02:00
|
|
|
// Copyright 2018 Google Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2018-06-02 18:05:09 +02:00
|
|
|
package dnsmasq_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2018-07-09 08:54:04 +02:00
|
|
|
"github.com/rtr7/router7/internal/testing/dnsmasq"
|
|
|
|
|
2018-06-02 18:05:09 +02:00
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Example(t *testing.T) {
|
2018-06-24 11:45:18 +02:00
|
|
|
dnsmasq := dnsmasq.Run(t, "veth0b", "ns0")
|
2018-06-02 18:05:09 +02:00
|
|
|
defer dnsmasq.Kill()
|
|
|
|
// test code here
|
|
|
|
|
|
|
|
// optionally introspect the dnsmasq log:
|
|
|
|
dnsmasq.Kill()
|
|
|
|
got := dnsmasq.Actions()
|
|
|
|
want := []string{
|
|
|
|
"DHCPDISCOVER(veth0b)",
|
|
|
|
"DHCPOFFER(veth0b)",
|
|
|
|
"DHCPREQUEST(veth0b)",
|
|
|
|
"DHCPACK(veth0b)",
|
|
|
|
"DHCPRELEASE(veth0b)",
|
|
|
|
}
|
|
|
|
actionOnly := func(line string) string {
|
|
|
|
result := line
|
|
|
|
if idx := strings.Index(result, " "); idx > -1 {
|
|
|
|
return result[:idx]
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
2019-07-11 08:42:21 +02:00
|
|
|
if diff := cmp.Diff(want, got, cmp.Transformer("ActionOnly", actionOnly)); diff != "" {
|
|
|
|
t.Errorf("dnsmasq log does not contain expected DHCP sequence: diff (-want +got):\n%s", diff)
|
2018-06-02 18:05:09 +02:00
|
|
|
}
|
|
|
|
}
|