go.ligato.io/vpp-agent/v3@v3.5.0/tests/integration/vpp/180_dns_test.go (about) 1 // Copyright (c) 2021 Pantheon.tech 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at: 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package vpp 16 17 import ( 18 "net" 19 "testing" 20 21 "github.com/go-errors/errors" 22 23 . "github.com/onsi/gomega" 24 "go.ligato.io/cn-infra/v2/logging/logrus" 25 "go.ligato.io/vpp-agent/v3/plugins/vpp/dnsplugin/vppcalls" 26 27 _ "go.ligato.io/vpp-agent/v3/plugins/vpp/dnsplugin" 28 ) 29 30 var ( 31 upstreamDNSServer1 = net.ParseIP("8.8.8.8") // google dns 1 32 upstreamDNSServer2 = net.ParseIP("8.8.4.4") // google dns 2 33 upstreamDNSServer3 = net.ParseIP("1.1.1.1") // cloudflare dns 34 ) 35 36 // TestDNSServerCRUD test basic CRUD scenario (currently testing only call capabilities without VPP state verification) 37 func TestDNSServerCRUD(t *testing.T) { 38 // TODO add read operation testing/assertion of VPP state - currently is missing VPP dumping functionality 39 // due to inability to find out whether DNS functionality is swithed on or off (the only way is to make 40 // DNS request, but no binary or CLI API can tell it) => testing here blindly VPP state by non-nil errors 41 // from commands 42 ctx := setupVPP(t) 43 defer ctx.teardownVPP() 44 45 // ignoring unsupported VPP versions 46 release := ctx.versionInfo.Release() 47 48 // get VPP handler 49 dnsHandler := vppcalls.CompatibleDNSHandler(ctx.vppClient, logrus.NewLogger("test-dns")) 50 Expect(dnsHandler).ToNot(BeNil(), errors.Errorf("dns vpp handler for VPP %s is not available", release)) 51 52 // create DNS server 53 Expect(dnsHandler.AddUpstreamDNSServer(upstreamDNSServer1)).To(Succeed()) 54 Expect(dnsHandler.AddUpstreamDNSServer(upstreamDNSServer2)).To(Succeed()) 55 Expect(dnsHandler.EnableDNS()).To(Succeed()) 56 57 // update upstream DNS server for DNS server configuration 58 Expect(dnsHandler.DeleteUpstreamDNSServer(upstreamDNSServer1)).To(Succeed()) 59 Expect(dnsHandler.AddUpstreamDNSServer(upstreamDNSServer3)).To(Succeed()) 60 61 // delete DNS server and cleanup 62 Expect(dnsHandler.DisableDNS()).To(Succeed()) 63 Expect(dnsHandler.DeleteUpstreamDNSServer(upstreamDNSServer2)).To(Succeed()) 64 Expect(dnsHandler.DeleteUpstreamDNSServer(upstreamDNSServer3)).To(Succeed()) 65 }