-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ut: add the unit tests for pkg/ingress/mcp
Signed-off-by: charlie <qianglin98@qq.com>
- Loading branch information
1 parent
6737ede
commit 44aab80
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} | ||
} |