From bd058ee91265a13d0bc6ca4909b417627183f724 Mon Sep 17 00:00:00 2001 From: Dimas Yudha P Date: Tue, 25 Oct 2022 18:57:25 +0700 Subject: [PATCH 1/4] removing else flow (#38) --- pkg/dashboard/handlers/helmHandlers.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/dashboard/handlers/helmHandlers.go b/pkg/dashboard/handlers/helmHandlers.go index f55a42b..617e136 100644 --- a/pkg/dashboard/handlers/helmHandlers.go +++ b/pkg/dashboard/handlers/helmHandlers.go @@ -248,11 +248,11 @@ func handleGetSection(data *subproc.DataLayer, section string, rDiff string, qp return "", err } return res, nil - } else { - res, err := functor(qp.Namespace, qp.Name, qp.Revision, flag) - if err != nil { - return "", err - } - return res, nil } + + res, err := functor(qp.Namespace, qp.Name, qp.Revision, flag) + if err != nil { + return "", err + } + return res, nil } From 91df9392c08a6ce81bcc16372ddf117a9c18a86c Mon Sep 17 00:00:00 2001 From: Dimas Yudha P Date: Tue, 25 Oct 2022 20:02:48 +0700 Subject: [PATCH 2/4] adding unit test for GetQueryProps (utils). (#39) * adding unit test for GetQueryProps (utils). * add unit test chart and version --- pkg/dashboard/utils/utils_test.go | 96 +++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 pkg/dashboard/utils/utils_test.go diff --git a/pkg/dashboard/utils/utils_test.go b/pkg/dashboard/utils/utils_test.go new file mode 100644 index 0000000..20dea41 --- /dev/null +++ b/pkg/dashboard/utils/utils_test.go @@ -0,0 +1,96 @@ +package utils + +import ( + "github.com/gin-gonic/gin" + "net/http/httptest" + "testing" +) + +func TestGetQueryProps(t *testing.T) { + gin.SetMode(gin.TestMode) + tests := []struct { + name string + endpoint string + revRequired bool + wantErr bool + }{ + { + name: "Get query props - all set with revRequired true", + wantErr: false, + revRequired: true, + endpoint: "/api/v1/namespaces/komodorio/charts?name=testing&namespace=testing&revision=1", + }, + { + name: "Get query props - no revision with revRequired true", + wantErr: true, + revRequired: true, + endpoint: "/api/v1/namespaces/komodorio/charts?name=testing&namespace=testing", + }, + { + name: "Get query props - no namespace with revRequired true", + wantErr: false, + revRequired: true, + endpoint: "/api/v1/namespaces/komodorio/charts?name=testing&revision=1", + }, + { + name: "Get query props - no name with revRequired true", + wantErr: true, + revRequired: true, + endpoint: "/api/v1/namespaces/komodorio/charts?namespace=testing&revision=1", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + w := httptest.NewRecorder() + c, _ := gin.CreateTestContext(w) + c.Request = httptest.NewRequest("GET", tt.endpoint, nil) + _, err := GetQueryProps(c, tt.revRequired) + if (err != nil) != tt.wantErr { + t.Errorf("GetQueryProps() error = %v, wantErr %v", err, tt.wantErr) + return + } + }) + } +} + +func TestChartAndVersion(t *testing.T) { + tests := []struct { + name string + params string + wantChart string + wantVer string + wantError bool + }{ + { + name: "Chart and version - successfully parsing chart and version", + params: "chart-1.0.0", + wantChart: "chart", + wantVer: "1.0.0", + wantError: false, + }, + { + name: "Chart and version - parsing chart without version", + params: "chart", + wantError: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + a, b, err := ChartAndVersion(tt.params) + if (err != nil) != tt.wantError { + t.Errorf("ChartAndVersion() error = %v, wantErr %v", err, tt.wantError) + return + } + + if a != tt.wantChart { + t.Errorf("ChartAndVersion() got = %v, want %v", a, tt.wantChart) + } + + if b != tt.wantVer { + t.Errorf("ChartAndVersion() got1 = %v, want %v", b, tt.wantVer) + } + }) + } +} From be6666373b1c1ac54bd9cf5b1d6dac63c58ffe5a Mon Sep 17 00:00:00 2001 From: Lior Noy Date: Tue, 25 Oct 2022 16:08:28 +0300 Subject: [PATCH 3/4] Add version information into UI (#35) This commit adds the tool version into the UI in the top bar. --- pkg/dashboard/static/index.html | 3 +++ pkg/dashboard/static/scripts.js | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/pkg/dashboard/static/index.html b/pkg/dashboard/static/index.html index a7d9425..132b0f9 100644 --- a/pkg/dashboard/static/index.html +++ b/pkg/dashboard/static/index.html @@ -44,6 +44,9 @@ +
+
+