istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pilot/pkg/networking/apigen/apigen_test.go (about) 1 // Copyright Istio Authors 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 apigen_test 16 17 import ( 18 "testing" 19 "time" 20 21 "istio.io/istio/pilot/pkg/config/memory" 22 "istio.io/istio/pilot/pkg/model" 23 "istio.io/istio/pilot/test/xds" 24 "istio.io/istio/pkg/config/schema/collections" 25 "istio.io/istio/pkg/config/schema/gvk" 26 ) 27 28 // Creates an in-process discovery server, using the same code as Istiod, but 29 // backed by an in-memory config and endpoint Store. 30 func initDS(t *testing.T) *xds.FakeDiscoveryServer { 31 ds := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{}) 32 sd := ds.MemRegistry 33 sd.AddHTTPService("fortio1.fortio.svc.cluster.local", "10.10.10.1", 8081) 34 sd.SetEndpoints("fortio1.fortio.svc.cluster.local", "", []*model.IstioEndpoint{ 35 { 36 Address: "127.0.0.1", 37 EndpointPort: uint32(14056), 38 ServicePortName: "http-main", 39 }, 40 }) 41 return ds 42 } 43 44 // Test using resolving DNS over GRPC. This uses XDS protocol, and Listener resources 45 // to represent the names. The protocol is based on GRPC resolution of XDS resources. 46 func TestAPIGen(t *testing.T) { 47 ds := initDS(t) 48 49 // Verify we can receive the DNS cluster IPs using XDS 50 t.Run("adsc", func(t *testing.T) { 51 proxy := &model.Proxy{Metadata: &model.NodeMetadata{ 52 Generator: "api", 53 }} 54 adscConn := ds.ConnectUnstarted(ds.SetupProxy(proxy), xds.APIWatches()) 55 store := memory.Make(collections.Pilot) 56 configController := memory.NewController(store) 57 adscConn.Store = configController 58 err := adscConn.Run() 59 if err != nil { 60 t.Fatal("ADSC: failed running ", err) 61 } 62 63 _, err = adscConn.WaitVersion(10*time.Second, gvk.ServiceEntry.String(), "") 64 if err != nil { 65 t.Fatal("Failed to receive lds", err) 66 } 67 68 ses := adscConn.Store.List(gvk.ServiceEntry, "") 69 for _, se := range ses { 70 t.Log(se) 71 } 72 sec := adscConn.Store.List(gvk.EnvoyFilter, "") 73 for _, se := range sec { 74 t.Log(se) 75 } 76 }) 77 }