Skip to content

Commit

Permalink
ut: add the unit tests for pkg/ingress/mcp
Browse files Browse the repository at this point in the history
Signed-off-by: charlie <qianglin98@qq.com>
  • Loading branch information
Charlie17Li committed Dec 7, 2022
1 parent 6737ede commit 44aab80
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions pkg/ingress/mcp/generator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package mcp

import (
"testing"

extensions "istio.io/api/extensions/v1alpha1"
networking "istio.io/api/networking/v1alpha3"
"istio.io/istio/pkg/config"
)

func Test_generate(t *testing.T) {
tests := []struct {
Name string
Spec config.Spec
IsErr bool
}{
{
Name: "VirtualService",
Spec: &networking.VirtualService{},
IsErr: false,
},
{
Name: "Gateway",
Spec: &networking.Gateway{},
IsErr: false,
},
{
Name: "EnvoyFilter",
Spec: &networking.EnvoyFilter{},
IsErr: false,
},
{
Name: "DestinationRule",
Spec: &networking.DestinationRule{},
IsErr: false,
},
{
Name: "WasmPlugin",
Spec: extensions.WasmPlugin{},
IsErr: false,
},
{
Name: "string",
Spec: "test",
IsErr: true,
},
}

for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
cfg := config.Config{
Spec: test.Spec,
}
_, _, err := generate(nil, []config.Config{cfg}, nil, nil)
if (err != nil && !test.IsErr) || (err == nil && test.IsErr) {
t.Errorf("Failed to generate config: %v", err)
}
})
}
}

0 comments on commit 44aab80

Please sign in to comment.