1717 * limitations under the License.
1818 */
1919
20- package kmesh
20+ package kmesh
2121
22- import (
23- "context"
24- "testing"
25- "time"
26-
27- "istio.io/api/label"
28- "istio.io/istio/pkg/config/protocol"
29- "istio.io/istio/pkg/test"
30- "istio.io/istio/pkg/test/framework"
31- "istio.io/istio/pkg/test/framework/components/echo"
32- "istio.io/istio/pkg/test/framework/components/namespace"
33- "istio.io/istio/pkg/test/framework/resource"
34- )
35-
36- var (
37- apps = & EchoDeployments {}
38- )
39-
40- type EchoDeployments struct {
41- Namespace namespace.Instance
42- All echo.Instances
43- }
44-
45- const (
46- ServiceName = "echo-service"
47- Timeout = 2 * time .Minute
48- )
49-
50- func TestMain (m * testing.M ) {
51- framework .
52- NewSuite (m ).
53- Setup (func (t resource.Context ) error {
54- t .Settings ().Ambient = true
55- return nil
56- }).
57- Setup (func (t resource.Context ) error {
58- return SetupApps (t , apps )
59- }).
60- Run ()
61- }
62-
63- func SetupApps (t resource.Context , apps * EchoDeployments ) error {
64- var err error
65- apps .Namespace , err = namespace .New (t , namespace.Config {
66- Prefix : "echo" ,
67- Inject : true , // 启用自动注入
68- Labels : map [string ]string {
69- label .IoIstioDataplaneMode .Name : "Kmesh" ,
70- },
71- })
72- if err != nil {
73- return err
74- }
75-
76- builder := echo .New (t ).
77- WithClusters (t .Clusters ()... ).
78- WithConfig (echo.Config {
79- Service : ServiceName ,
80- Namespace : apps .Namespace ,
81- Ports : echo.Ports {{
82- Name : "http" ,
83- Protocol : protocol .HTTP ,
84- Port : 8080 ,
85- }},
86- ServiceAccount : true ,
87- Subsets : []echo.SubsetConfig {
88- {
89- Replicas : 1 ,
90- Version : "v1" ,
91- Labels : map [string ]string {
92- "app" : ServiceName ,
93- "version" : "v1" ,
94- },
95- },
96- {
97- Replicas : 1 ,
98- Version : "v2" ,
99- Labels : map [string ]string {
100- "app" : ServiceName ,
101- "version" : "v2" ,
102- },
103- },
104- },
105- })
106-
107- echos , err := builder .Build ()
108- if err != nil {
109- return err
110- }
111-
112- apps .All = echos
113- return nil
114- }
115-
22+ import (
23+ "testing"
24+ "time"
25+
26+ "istio.io/api/label"
27+ "istio.io/istio/pkg/config/protocol"
28+ "istio.io/istio/pkg/test/framework"
29+ "istio.io/istio/pkg/test/framework/components/echo"
30+ "istio.io/istio/pkg/test/framework/components/namespace"
31+ "istio.io/istio/pkg/test/framework/resource"
32+ )
33+
34+ var (
35+ apps = & EchoDeployments {}
36+ )
37+
38+ type EchoDeployments struct {
39+ Namespace namespace.Instance
40+ All echo.Instances
41+ }
42+
43+ const (
44+ ServiceName = "echo-service"
45+ EnrolledToKmesh = "enrolled-to-kmesh"
46+ Timeout = 2 * time .Minute
47+ KmeshReleaseName = "kmesh"
48+ KmeshDaemonsetName = "kmesh"
49+ KmeshNamespace = "kmesh-system"
50+ DataplaneModeKmesh = "Kmesh"
51+ )
52+
53+ func TestMain (m * testing.M ) {
54+ framework .
55+ NewSuite (m ).
56+ Setup (func (t resource.Context ) error {
57+ t .Settings ().Ambient = true
58+ return nil
59+ }).
60+ Setup (func (t resource.Context ) error {
61+ return SetupApps (t , apps )
62+ }).
63+ Run ()
64+ }
65+
66+ func SetupApps (t resource.Context , apps * EchoDeployments ) error {
67+ var err error
68+ apps .Namespace , err = namespace .New (t , namespace.Config {
69+ Prefix : "echo" ,
70+ Inject : false ,
71+ Labels : map [string ]string {
72+ label .IoIstioDataplaneMode .Name : DataplaneModeKmesh ,
73+ },
74+ })
75+ if err != nil {
76+ return err
77+ }
78+
79+ builder := echo .New (t ).
80+ WithClusters (t .Clusters ()... ).
81+ WithConfig (echo.Config {
82+ Service : ServiceName ,
83+ Namespace : apps .Namespace ,
84+ Ports : echo.Ports {{
85+ Name : "http" ,
86+ Protocol : protocol .HTTP ,
87+ Port : 8080 ,
88+ }},
89+ ServiceAccount : true ,
90+ Subsets : []echo.SubsetConfig {
91+ {
92+ Replicas : 1 ,
93+ Version : "v1" ,
94+ Labels : map [string ]string {
95+ "app" : ServiceName ,
96+ "version" : "v1" ,
97+ },
98+ },
99+ {
100+ Replicas : 1 ,
101+ Version : "v2" ,
102+ Labels : map [string ]string {
103+ "app" : ServiceName ,
104+ "version" : "v2" ,
105+ },
106+ },
107+ },
108+ })
109+
110+ echos , err := builder .Build ()
111+ if err != nil {
112+ return err
113+ }
114+
115+ apps .All = echos
116+ return nil
117+ }
0 commit comments