summaryrefslogtreecommitdiffstats
path: root/msb2pilot/src/msb2pilot/pilot/controller_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'msb2pilot/src/msb2pilot/pilot/controller_test.go')
-rw-r--r--msb2pilot/src/msb2pilot/pilot/controller_test.go193
1 files changed, 159 insertions, 34 deletions
diff --git a/msb2pilot/src/msb2pilot/pilot/controller_test.go b/msb2pilot/src/msb2pilot/pilot/controller_test.go
index d7fe7d9..3c01b44 100644
--- a/msb2pilot/src/msb2pilot/pilot/controller_test.go
+++ b/msb2pilot/src/msb2pilot/pilot/controller_test.go
@@ -13,14 +13,16 @@ package pilot
import (
"fmt"
- "msb2pilot/models"
- "os"
- "reflect"
+
+ // "fmt"
+ // "msb2pilot/models"
+ // "os"
+ // "reflect"
"testing"
)
func TestList(t *testing.T) {
- res, err := List("routerules", "default")
+ res, err := List("virtualservice", "default")
if err != nil {
t.Errorf("List() => got %v", err)
} else {
@@ -28,39 +30,162 @@ func TestList(t *testing.T) {
}
}
-func TestUpdateK8sAddress(t *testing.T) {
- cases := []struct {
- path, addr, want, err string
- }{
- {
- path: "k8s.yml222",
- addr: "filenoteexisttest",
- want: "",
- err: "*os.PathError",
- },
- {
- path: configPath,
- addr: "",
- want: "",
- err: "",
- },
+//func TestParseParam(t *testing.T) {
+// cases := []struct {
+// in string
+// }{
+// // {
+// // in: `{
+// //"apiVersion": "networking.istio.io/v1alpha3",
+// //"kind": "VirtualService",
+// //"metadata": {"name": "default-apigateway"},
+// //"spec": {"hosts":["apigateway"],"http":[{
+// //"match":{"uri": {"prefix": "/portaladmin"}},
+// //"rewrite": {"uri": "/portaladmin"},
+// //"route": [{"destination": {"host": "portaladmin"}}]
+// //},{
+// //"match":{"uri": {"prefix": "/pm_mgt/v1"}},
+// //"rewrite": {"uri": "/pm_mgt/v1"},
+// //"route": [{"destination": {"host": "pm_mgt"}}]
+// //}]}
+// //}`,
+// // },
+// {
+// in: `{
+//"apiVersion": "networking.istio.io/v1alpha3",
+//"kind": "VirtualService",
+//"metadata": {"name": "default-apigateway"},
+//"spec": {"destination":{"service":"reviews.service.consul"},"http":[{
+//"match":{"uri": {"prefix": "/portaladmin"}},
+//"rewrite": {"uri": "/portaladmin"},
+//}]}
+//}`,
+// },
+// {
+// in: `{
+//"apiVersion": "networking.istio.io/v1alpha3",
+//"kind": "VirtualService",
+//"metadata": {"name": "default-apigateway"},
+//"spec": {"hosts":["test"],"http":[]}
+//}`,
+// },
+// }
+
+// for _, cas := range cases {
+// res, err := ParseParam(cas.in)
+// if err != nil {
+// t.Errorf("ParseParam() => got %v", err)
+// } else {
+// fmt.Print(res)
+// }
+// }
+//}
+
+func TestCreate(t *testing.T) {
+ str := `
{
- path: configPath,
- addr: "k8stest",
- want: "k8stest",
- err: "",
- },
+ "apiVersion": "networking.istio.io/v1alpha3",
+ "kind": "VirtualService",
+ "metadata":{
+ "name": "reviews"},
+ "spec":{
+ "hosts":["reviews.service.consul"],
+ "http":[{
+ "match":[{"uri": {"prefix": "/pm_mgt/v1"}}],
+ "rewrite": {"uri": "/portaladmin"},
+ "route":[{
+ "destination":{
+ "host": "reviews.service.consul",
+ "subset": "v3"
+ }}]
+ }]
+ }
+ }
+ `
+
+ config, exist := Get("virtualservice", "default", "reviews")
+ if exist {
+ Delete("virtualservice", "default", "reviews")
+ }
+ configs, err := ParseParam(str)
+ if err != nil {
+ t.Errorf("ParseParam() => got %v", err)
+ } else {
+ fmt.Println(configs)
}
- oldEnv := os.Getenv(models.EnvK8sAddress)
- for _, cas := range cases {
- os.Unsetenv(models.EnvK8sAddress)
- os.Setenv(models.EnvK8sAddress, cas.addr)
+ res, err := Create(&configs[0])
+ if err != nil {
+ t.Errorf("Create() => got %v", err)
+ } else {
+ fmt.Println(res)
+ }
- got, err := updateK8sAddress(cas.path)
- if got != cas.want || (err != nil && reflect.TypeOf(err).String() != cas.err) {
- t.Errorf("updateK8sAddress(%s, %s) => got %s %v, want %s", cas.path, cas.addr, got, reflect.TypeOf(err), cas.want)
- }
+ if exist {
+ Create(config)
}
- os.Setenv(models.EnvK8sAddress, oldEnv)
}
+
+//func TestParseParam(t *testing.T) {
+// str := `
+// {
+// "apiVersion": "networking.istio.io/v1alpha3",
+// "kind": "VirtualService",
+// "metadata":{
+// "name": "reviews"},
+// "spec":{
+// "hosts":["reviews.service.consul"],
+// "http":[{
+// "route":[{
+// "destination":{
+// "host": "reviews.service.consul",
+// "subset": "v3"
+// }}]
+// }]
+// }
+// }
+// `
+// res, err := ParseParam(str)
+// if err != nil {
+// t.Errorf("ParseParam() => got %v", err)
+// } else {
+// fmt.Println(res)
+// }
+//}
+
+//func TestUpdateK8sAddress(t *testing.T) {
+// cases := []struct {
+// path, addr, want, err string
+// }{
+// {
+// path: "k8s.yml222",
+// addr: "filenoteexisttest",
+// want: "",
+// err: "*os.PathError",
+// },
+// {
+// path: configPath,
+// addr: "",
+// want: "",
+// err: "",
+// },
+// {
+// path: configPath,
+// addr: "k8stest",
+// want: "k8stest",
+// err: "",
+// },
+// }
+
+// oldEnv := os.Getenv(models.EnvK8sAddress)
+// for _, cas := range cases {
+// os.Unsetenv(models.EnvK8sAddress)
+// os.Setenv(models.EnvK8sAddress, cas.addr)
+
+// got, err := updateK8sAddress(cas.path)
+// if got != cas.want || (err != nil && reflect.TypeOf(err).String() != cas.err) {
+// t.Errorf("updateK8sAddress(%s, %s) => got %s %v, want %s", cas.path, cas.addr, got, reflect.TypeOf(err), cas.want)
+// }
+// }
+// os.Setenv(models.EnvK8sAddress, oldEnv)
+//}