1// Copyright 2019 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
15package processor
16
17import (
18	"testing"
19	"time"
20
21	. "github.com/onsi/gomega"
22
23	"istio.io/istio/galley/pkg/config/mesh"
24	"istio.io/istio/galley/pkg/config/processing/snapshotter"
25	"istio.io/istio/galley/pkg/config/processor/transforms"
26	"istio.io/istio/galley/pkg/config/source/kube/inmemory"
27	"istio.io/istio/pkg/config/event"
28	"istio.io/istio/pkg/config/schema"
29	"istio.io/istio/pkg/config/schema/snapshots"
30)
31
32const yml = `
33apiVersion: networking.istio.io/v1alpha3
34kind: Gateway
35metadata:
36  name: helloworld-gateway
37spec:
38  selector:
39    istio: ingressgateway # use istio default controller
40  servers:
41  - port:
42      number: 80
43      name: http
44      protocol: HTTP
45    hosts:
46    - "*"
47
48`
49
50func TestProcessor(t *testing.T) {
51	g := NewGomegaWithT(t)
52
53	meshSrc := mesh.NewInmemoryMeshCfg()
54	src := inmemory.NewKubeSource(schema.MustGet().KubeCollections())
55	srcs := []event.Source{
56		meshSrc,
57		src,
58	}
59
60	meshSrc.Set(mesh.DefaultMeshConfig())
61	distributor := snapshotter.NewInMemoryDistributor()
62	transformProviders := transforms.Providers(schema.MustGet())
63
64	processorSettings := Settings{
65		Metadata:           schema.MustGet(),
66		DomainSuffix:       "svc.local",
67		Source:             event.CombineSources(srcs...),
68		TransformProviders: transformProviders,
69		Distributor:        distributor,
70		EnabledSnapshots:   []string{snapshots.Default},
71	}
72
73	rt, err := Initialize(processorSettings)
74	g.Expect(err).To(BeNil())
75
76	rt.Start()
77
78	err = src.ApplyContent("foo", yml)
79	g.Expect(err).To(BeNil())
80
81	time.Sleep(time.Second)
82	_ = distributor.GetSnapshot("default")
83}
84