From 63fe2e91c26829ab19d5e1bf2afe58d55aa78da4 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Mon, 23 May 2022 09:16:36 +1000 Subject: [PATCH 1/2] fix: ingress json --- cmd/identify_ingress.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/identify_ingress.go b/cmd/identify_ingress.go index 6c97a7d3..50d1e424 100644 --- a/cmd/identify_ingress.go +++ b/cmd/identify_ingress.go @@ -9,9 +9,9 @@ import ( ) type ingressIdentifyJSON struct { - primary string `json:"primary"` - secondary []string `json:"secondary"` - autogenerated []string `json:"autogenerated"` + Primary string `json:"primary"` + Secondary []string `json:"secondary"` + Autogenerated []string `json:"autogenerated"` } var primaryIngressIdentify = &cobra.Command{ @@ -38,9 +38,9 @@ var ingressIdentify = &cobra.Command{ return err } ret := ingressIdentifyJSON{ - primary: primary, - secondary: secondary, - autogenerated: autogen, + Primary: primary, + Secondary: secondary, + Autogenerated: autogen, } retJSON, _ := json.Marshal(ret) fmt.Println(string(retJSON)) From 9205b8489fee6219a78cebb0db5591453db800ff Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Mon, 23 May 2022 09:20:41 +1000 Subject: [PATCH 2/2] test: add tests for json --- cmd/identify_ingress_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/cmd/identify_ingress_test.go b/cmd/identify_ingress_test.go index a62f1f99..e83c50aa 100644 --- a/cmd/identify_ingress_test.go +++ b/cmd/identify_ingress_test.go @@ -1,6 +1,7 @@ package cmd import ( + "encoding/json" "os" "reflect" "testing" @@ -34,6 +35,7 @@ func TestIdentifyRoute(t *testing.T) { name string args args want string + wantJSON string wantRemain []string wantautoGen []string }{ @@ -57,6 +59,7 @@ func TestIdentifyRoute(t *testing.T) { want: "https://example.com", wantRemain: []string{"https://node-example-project-main.example.com"}, wantautoGen: []string{"https://node-example-project-main.example.com"}, + wantJSON: `{"primary":"https://example.com","secondary":["https://node-example-project-main.example.com"],"autogenerated":["https://node-example-project-main.example.com"]}`, }, { name: "test2 check LAGOON_FASTLY_SERVICE_IDS no secret and no values", @@ -78,6 +81,7 @@ func TestIdentifyRoute(t *testing.T) { want: "https://example.com", wantRemain: []string{"https://node-example-project-main.example.com"}, wantautoGen: []string{"https://node-example-project-main.example.com"}, + wantJSON: `{"primary":"https://example.com","secondary":["https://node-example-project-main.example.com"],"autogenerated":["https://node-example-project-main.example.com"]}`, }, { name: "test3 check LAGOON_FASTLY_SERVICE_ID no secret and no values", @@ -99,6 +103,7 @@ func TestIdentifyRoute(t *testing.T) { want: "https://example.com", wantRemain: []string{"https://node-example-project-main.example.com"}, wantautoGen: []string{"https://node-example-project-main.example.com"}, + wantJSON: `{"primary":"https://example.com","secondary":["https://node-example-project-main.example.com"],"autogenerated":["https://node-example-project-main.example.com"]}`, }, { name: "test4 check no fastly and no values", @@ -120,6 +125,7 @@ func TestIdentifyRoute(t *testing.T) { want: "https://example.com", wantRemain: []string{"https://node-example-project-main.example.com"}, wantautoGen: []string{"https://node-example-project-main.example.com"}, + wantJSON: `{"primary":"https://example.com","secondary":["https://node-example-project-main.example.com"],"autogenerated":["https://node-example-project-main.example.com"]}`, }, { name: "test5 multiproject1 no values", @@ -141,6 +147,7 @@ func TestIdentifyRoute(t *testing.T) { want: "https://multiproject1.com", wantRemain: []string{"https://node-multiproject1-multiproject.example.com"}, wantautoGen: []string{"https://node-multiproject1-multiproject.example.com"}, + wantJSON: `{"primary":"https://multiproject1.com","secondary":["https://node-multiproject1-multiproject.example.com"],"autogenerated":["https://node-multiproject1-multiproject.example.com"]}`, }, { name: "test6 multiproject2 no values", @@ -162,6 +169,7 @@ func TestIdentifyRoute(t *testing.T) { want: "https://multiproject2.com", wantRemain: []string{"https://node-multiproject2-multiproject.example.com"}, wantautoGen: []string{"https://node-multiproject2-multiproject.example.com"}, + wantJSON: `{"primary":"https://multiproject2.com","secondary":["https://node-multiproject2-multiproject.example.com"],"autogenerated":["https://node-multiproject2-multiproject.example.com"]}`, }, { name: "test7 multidomain no values", @@ -183,6 +191,7 @@ func TestIdentifyRoute(t *testing.T) { want: "https://example.com", wantRemain: []string{"https://node-example-project-main.example.com", "https://www.example.com"}, wantautoGen: []string{"https://node-example-project-main.example.com"}, + wantJSON: `{"primary":"https://example.com","secondary":["https://node-example-project-main.example.com","https://www.example.com"],"autogenerated":["https://node-example-project-main.example.com"]}`, }, { name: "test8 multidomain no values", @@ -204,6 +213,7 @@ func TestIdentifyRoute(t *testing.T) { want: "https://customdomain-will-be-main-domain.com", wantRemain: []string{"https://node-example-project-branch-routes.example.com", "https://customdomain-will-be-not-be-main-domain.com"}, wantautoGen: []string{"https://node-example-project-branch-routes.example.com"}, + wantJSON: `{"primary":"https://customdomain-will-be-main-domain.com","secondary":["https://node-example-project-branch-routes.example.com","https://customdomain-will-be-not-be-main-domain.com"],"autogenerated":["https://node-example-project-branch-routes.example.com"]}`, }, { name: "test9 active no values", @@ -226,6 +236,7 @@ func TestIdentifyRoute(t *testing.T) { want: "https://active.example.com", wantRemain: []string{"https://node-example-project-main.example.com", "https://main.example.com"}, wantautoGen: []string{"https://node-example-project-main.example.com"}, + wantJSON: `{"primary":"https://active.example.com","secondary":["https://node-example-project-main.example.com","https://main.example.com"],"autogenerated":["https://node-example-project-main.example.com"]}`, }, { name: "test10 standby no values", @@ -248,6 +259,7 @@ func TestIdentifyRoute(t *testing.T) { want: "https://standby.example.com", wantRemain: []string{"https://node-example-project-main2.example.com", "https://main2.example.com"}, wantautoGen: []string{"https://node-example-project-main2.example.com"}, + wantJSON: `{"primary":"https://standby.example.com","secondary":["https://node-example-project-main2.example.com","https://main2.example.com"],"autogenerated":["https://node-example-project-main2.example.com"]}`, }, { name: "test11 no custom ingress", @@ -270,6 +282,7 @@ func TestIdentifyRoute(t *testing.T) { want: "https://node-example-project-no-ingress.example.com", wantRemain: []string{}, wantautoGen: []string{"https://node-example-project-no-ingress.example.com"}, + wantJSON: `{"primary":"https://node-example-project-no-ingress.example.com","secondary":[],"autogenerated":["https://node-example-project-no-ingress.example.com"]}`, }, { name: "test12 no custom ingress", @@ -303,6 +316,7 @@ func TestIdentifyRoute(t *testing.T) { "https://de.node-example-project-no-ingress.example.com", "https://fi.node-example-project-no-ingress.example.com", }, + wantJSON: `{"primary":"https://node-example-project-no-ingress.example.com","secondary":["https://www.node-example-project-no-ingress.example.com","https://en.node-example-project-no-ingress.example.com","https://de.node-example-project-no-ingress.example.com","https://fi.node-example-project-no-ingress.example.com"],"autogenerated":["https://node-example-project-no-ingress.example.com","https://www.node-example-project-no-ingress.example.com","https://en.node-example-project-no-ingress.example.com","https://de.node-example-project-no-ingress.example.com","https://fi.node-example-project-no-ingress.example.com"]}`, }, } for _, tt := range tests { @@ -395,6 +409,17 @@ func TestIdentifyRoute(t *testing.T) { if !reflect.DeepEqual(autogen, tt.wantautoGen) { t.Errorf("returned autogen %v doesn't match want %v", autogen, tt.wantautoGen) } + + ret := ingressIdentifyJSON{ + Primary: primary, + Secondary: remainders, + Autogenerated: autogen, + } + retJSON, _ := json.Marshal(ret) + + if string(retJSON) != tt.wantJSON { + t.Errorf("returned autogen %v doesn't match want %v", string(retJSON), tt.wantJSON) + } }) } }