You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/02/05 08:52:38 UTC

[GitHub] [apisix-dashboard] Jaycean opened a new pull request #1436: feat: refactor ssl unit test

Jaycean opened a new pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436


   Please answer these questions before submitting a pull request
   
   - Why submit this pull request?
   - [ ] Bugfix
   - [s] New feature provided
   - [ ] Improve performance
   - [ ] Backport patches
   
   - Related issues
   #1161 
   #1332
   ___
   ### Bugfix
   - Description
   Refactor SSL unit testing to remove etcd dependency
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] codecov-io commented on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
codecov-io commented on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-773958991


   # [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=h1) Report
   > Merging [#1436](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=desc) (a4d7296) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/42f3bf6f2ecb2668177efb3e620d57b3b820d5dc?el=desc) (42f3bf6) will **decrease** coverage by `10.97%`.
   > The diff coverage is `75.00%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=tree)
   
   ```diff
   @@             Coverage Diff             @@
   ##           master    #1436       +/-   ##
   ===========================================
   - Coverage   67.98%   57.00%   -10.98%     
   ===========================================
     Files          48       48               
     Lines        3042     3040        -2     
   ===========================================
   - Hits         2068     1733      -335     
   - Misses        734     1026      +292     
   - Partials      240      281       +41     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [api/internal/handler/ssl/ssl.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvc3NsL3NzbC5nbw==) | `33.15% <75.00%> (-15.00%)` | :arrow_down: |
   | [api/internal/handler/plugin/plugin.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvcGx1Z2luL3BsdWdpbi5nbw==) | `16.66% <0.00%> (-70.00%)` | :arrow_down: |
   | [api/internal/utils/runtime/runtime.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL3V0aWxzL3J1bnRpbWUvcnVudGltZS5nbw==) | `0.00% <0.00%> (-64.29%)` | :arrow_down: |
   | [api/internal/core/store/query.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvcXVlcnkuZ28=) | `45.23% <0.00%> (-52.39%)` | :arrow_down: |
   | [api/internal/core/store/selector.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc2VsZWN0b3IuZ28=) | `35.18% <0.00%> (-51.86%)` | :arrow_down: |
   | [api/internal/core/store/validate\_mock.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvdmFsaWRhdGVfbW9jay5nbw==) | `0.00% <0.00%> (-50.00%)` | :arrow_down: |
   | [api/internal/handler/service/service.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvc2VydmljZS9zZXJ2aWNlLmdv) | `54.25% <0.00%> (-37.24%)` | :arrow_down: |
   | [api/internal/filter/authentication.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2ZpbHRlci9hdXRoZW50aWNhdGlvbi5nbw==) | `41.66% <0.00%> (-30.56%)` | :arrow_down: |
   | [api/internal/core/store/store.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc3RvcmUuZ28=) | `58.43% <0.00%> (-28.32%)` | :arrow_down: |
   | [api/internal/filter/ip\_filter.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2ZpbHRlci9pcF9maWx0ZXIuZ28=) | `48.71% <0.00%> (-23.08%)` | :arrow_down: |
   | ... and [17 more](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=footer). Last update [42f3bf6...a4d7296](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] Jaycean commented on a change in pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
Jaycean commented on a change in pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#discussion_r571443311



##########
File path: api/internal/handler/ssl/ssl_test.go
##########
@@ -18,147 +18,737 @@
 package ssl
 
 import (
-	"encoding/json"
+	"errors"
+	"fmt"
+	"net/http"
 	"testing"
-	"time"
 
 	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/data"
 	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/mock"
 
-	"github.com/apisix/manager-api/internal/conf"
 	"github.com/apisix/manager-api/internal/core/entity"
-	"github.com/apisix/manager-api/internal/core/storage"
 	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils/consts"
 )
 
-func TestSSL(t *testing.T) {
-	// init
-	err := storage.InitETCDClient(conf.ETCDConfig)
-	assert.Nil(t, err)
-	err = store.InitStores()
-	assert.Nil(t, err)
-
-	handler := &Handler{
-		sslStore: store.GetStore(store.HubKeySsl),
-	}
-	assert.NotNil(t, handler)
-
-	//create
-	ctx := droplet.NewContext()
-	ssl := &entity.SSL{}
-	reqBody := `{
-        "id":"1",
-        "key": "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDGO0J9xrOcmvgh\npkqHIYHCw35FTfIT5uXOSzdF49M2ZAKBQwFG0ovYT8bc0glNLB+hpDhJPL531qSP\nl1ZOe0W1ofP1u0T5Zzc9Rub/kn7RMPq0BsSC6J3rF+rQEwh1PM8qUuD8DxZ7jaOL\niMNL6SyuZIPsS1kPPBtsioukdo666tbjNMixhQbI9Wpg55abdXRFh3i7Zu/9siF1\njCGcsskjOaUOY4sYQ3i5WU/HIIRhA82XuIL+Sxd32P8bKi2UT1sqFXRjAVR7KRWo\nIVvkmSLoZb9ucV6MsccDrRYBf6rLbI1tFj9l2rY6GTFlT+6z7K/ZI60DGi/hsBfl\nDeEQ5WuxAgMBAAECggEAVHQQyucpxHGdfzCKlfGnh+Oj20Du/p2jkHUpEkSSypxn\nGM0EMTkoTTsHvTJath8zRrlhJYqUlxfCOk6+fWc1dsGN30Yuh5b6yMd5S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VHREEGjAYgglyb3V
 0ZS5jb22CCyoucm91dGUuY29tMA0GCSqGSIb3\nDQEBCwUAA4IBgQAvKN2GEorAlx5sfUU2uiL49iFmQSMDLZQminQl1RIHTI/h+jz8\nNluZSdxDFmNq8am6B2ofD3VLl6StC/G+G6YuekPz+QrUNK4UB+8ftRmY4YRFGTQ6\nRnFli1wOq2ES9vPjKlIj77cznr8uwVHPHq8JxGbn/rx3oVDVPndXFCkJJ1DDjRT+\n22atHNzHt5bc9ut8Fq5NW61P+nnMMFShKJaPBkmm9Pf2pEOd8Y7OU8Iy1Kj65fsE\nUshGF5+RWoxdv6/9f6/uOQhmq3MEKqneUC3pjVZ8TiBlRvADxxR5krvujQswms0D\nFGpRMtGpPGMWTuptSIMwNcar/luVig7wGIBeV5ZaOlSOx3911le9mlS7+2lLqf5H\n5dsMkP30Sjv/jfrIL+SE1qeK3kjL0iIwA/PPARvhctExs9y2llT9+drbJofZUi+I\nZdYfAfyJT4htbcl7jHN8oY7vzwgTyxCcBxkbqKfBqabneutj0jfX39zP0G696tiZ\ndQFXCS4wkvw0CG0=\n-----END CERTIFICATE-----",
-        "labels":{
-            "build":"16",
-            "env":"production",
-            "version":"v2"
-        }
-	}`
-	err = json.Unmarshal([]byte(reqBody), ssl)
-	assert.Nil(t, err)
-	ctx.SetInput(ssl)
-	ret, err := handler.Create(ctx)
-	assert.Nil(t, err)
-	objRet, ok := ret.(*entity.SSL)
-	assert.True(t, ok)
-	assert.Equal(t, "1", objRet.ID)
-
-	//sleep
-	time.Sleep(time.Duration(100) * time.Millisecond)
-
-	//get
-	input := &GetInput{}
-	input.ID = "1"
-	ctx.SetInput(input)
-	ret, err = handler.Get(ctx)
-	stored := ret.(*entity.SSL)
-	assert.Nil(t, err)
-	assert.Equal(t, stored.ID, ssl.ID)
-	assert.Equal(t, stored.Labels["build"], "16")
-	assert.Equal(t, stored.Labels["env"], "production")
-	assert.Equal(t, stored.Labels["version"], "v2")
-
-	//update
-	ssl2 := &UpdateInput{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ctExs9y2llT9+drbJofZUi+I\nZdYfAfyJT4htbcl7jHN8oY7vzwgTyxCcBxkbqKfBqabneutj0jfX39zP0G696tiZ\ndQFXCS4wkvw0CG0=\n-----END CERTIFICATE-----",
-        "labels":{
-            "build":"18",
-            "env":"dev",
-            "version":"v3"
-        }
-	}`
-	err = json.Unmarshal([]byte(reqBody), ssl2)
-	assert.Nil(t, err)
-	ctx.SetInput(ssl2)
-	ret, err = handler.Update(ctx)
-	assert.Nil(t, err)
-	// check the returned value
-	objRet, ok = ret.(*entity.SSL)
-	assert.True(t, ok)
-	assert.Equal(t, "1", objRet.ID)
-	assert.Equal(t, ssl2.Key, objRet.Key)
-	assert.Equal(t, ssl2.Cert, objRet.Cert)
-
-	//sleep
-	time.Sleep(time.Duration(100) * time.Millisecond)
-
-	// get and check
-	input = &GetInput{}
-	input.ID = "1"
-	ctx.SetInput(input)
-	ret, err = handler.Get(ctx)
-	stored = ret.(*entity.SSL)
-	assert.Nil(t, err)
-	assert.Equal(t, stored.ID, ssl.ID)
-	assert.Equal(t, stored.Labels["build"], "18")
-	assert.Equal(t, stored.Labels["env"], "dev")
-	assert.Equal(t, stored.Labels["version"], "v3")
-
-	//list
-	listInput := &ListInput{}
-	reqBody = `{"page_size": 1, "page": 1}`
-	err = json.Unmarshal([]byte(reqBody), listInput)
-	assert.Nil(t, err)
-	ctx.SetInput(listInput)
-	retPage, err := handler.List(ctx)
-	assert.Nil(t, err)
-	dataPage := retPage.(*store.ListOutput)
-	assert.Equal(t, len(dataPage.Rows), 1)
-
-	//list search match
-	listInput2 := &ListInput{}
-	reqBody = `{"page_size": 1, "page": 1, "sni": "route"}`
-	err = json.Unmarshal([]byte(reqBody), listInput2)
-	assert.Nil(t, err)
-	ctx.SetInput(listInput2)
-	retPage, err = handler.List(ctx)
-	assert.Nil(t, err)
-	dataPage = retPage.(*store.ListOutput)
-	assert.Equal(t, len(dataPage.Rows), 1)
-
-	//list search not match
-	listInput3 := &ListInput{}
-	reqBody = `{"page_size": 1, "page": 1, "sni": "not-exists"}`
-	err = json.Unmarshal([]byte(reqBody), listInput3)
-	assert.Nil(t, err)
-	ctx.SetInput(listInput3)
-	retPage, err = handler.List(ctx)
-	assert.Nil(t, err)
-	dataPage = retPage.(*store.ListOutput)
-	assert.Equal(t, len(dataPage.Rows), 0)
-
-	//delete test data
-	inputDel := &BatchDelete{}
-	reqBody = `{"ids": "1"}`
-	err = json.Unmarshal([]byte(reqBody), inputDel)
-	assert.Nil(t, err)
-	ctx.SetInput(inputDel)
-	_, err = handler.BatchDelete(ctx)
-	assert.Nil(t, err)
+var (
+	_key  string = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDGO0J9xrOcmvgh\npkqHIYHCw35FTfIT5uXOSzdF49M2ZAKBQwFG0ovYT8bc0glNLB+hpDhJPL531qSP\nl1ZOe0W1ofP1u0T5Zzc9Rub/kn7RMPq0BsSC6J3rF+rQEwh1PM8qUuD8DxZ7jaOL\niMNL6SyuZIPsS1kPPBtsioukdo666tbjNMixhQbI9Wpg55abdXRFh3i7Zu/9siF1\njCGcsskjOaUOY4sYQ3i5WU/HIIRhA82XuIL+Sxd32P8bKi2UT1sqFXRjAVR7KRWo\nIVvkmSLoZb9ucV6MsccDrRYBf6rLbI1tFj9l2rY6GTFlT+6z7K/ZI60DGi/hsBfl\nDeEQ5WuxAgMBAAECggEAVHQQyucpxHGdfzCKlfGnh+Oj20Du/p2jkHUpEkSSypxn\nGM0EMTkoTTsHvTJath8zRrlhJYqUlxfCOk6+fWc1dsGN30Yuh5b6yMd5SK8QCm20\nkZhEhoU2Kl+hMY66TsBefmia46hF6tOYNq1IjwHDgHTgY35ibgQsptyLy8Ca5HTC\nrnoocP2AcKtM+qwOMGiNHpeh+/zfB91C9AszvS8H2ao5nq4u0/JavPO4A4WmVYol\n7Qv9ACY/8uaKC79syahutbkMjwGsQgYsq9G0QpcLSCuOb4vBbOb130mptSM9NzKg\nTjSxF2D8ob//roZMc1ueTpqAY6WedKV3y3BIBDKuAQKBgQDgGyEsxwR9QtA5EH/h\nJ4GiTQn0aep8G2LSlAtHGndL3sxaGGLt2pk3lNIeRAbOS3APmYskBN418JIF/Ren\nE0CYSrTaxpTs9UXXkgKNJ63Z6r+btswTAVVXG5Zoi/5JRSHRquEVmKccM4zg3v6R\ny/nVhwXigUaRuLx+wCtoaGsaUQK
 BgQDicXFZ0TvN8tohqc8dbmOu2A25+ifFKHUA\nn3yxZIJtbTC9bJeuwtkqIFol1DXHLqYvdD5jQT3c4z6HekcmI9sEy1YzO4a3WUTI\nP//ogjDLXj402k+WCx1Us2HASxwU5cRvOpMhfnppYPSDXqBoH196UCDmOQuS1+Q8\njyPsNQmDYQKBgQDcm5hCvf87V4QmSIm6GOvR20iLY6BCX6seZEHd0r3Q4BgGMK9i\nOahOQJ++z3Rrq3M6yAligbBFJPZ6ErUv8RHLWO9D1exQfvorxT3huke3lxDbtkya\nANwDjdK4Q+ckNXufLDm6yrTmXBC4ZIvw9fyQKASw/lV7qYFUvNN+Shv0oQKBgQC+\nraw3Z7smV0NbaXRgYh5KkuAsJPvsR38OwT3s2qgBoRqTx6eKn8Tidk+y3xlR2nRS\nLV6DkeKX6Ds1NcBH25WIWfkCNzPfnKoQveOuVELmXTugody2ijFuq4a6uASzjC93\nQim24JwPtHbxUHNeelyZ0HODqbGXO3iTji0/sAGMwQKBgQC8yDwapXgrCWK34qpN\nSdO9uA4VstI3Ovb+o3Evfp1CvJnfk56ypO2DaqbuvMJsInuWRFU40UWp7Vxyl/hP\nXvGgEI3dbBy9KWFjAKfI2Wv3i+zvJ1mAHM3u1jcX3zxOxSAN4LJVBudgkGpop1ps\nW5tWveXiXwxCUE/r9ax4mfJvXQ==\n-----END PRIVATE KEY-----"

Review comment:
       done.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] tokers commented on a change in pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#discussion_r571736462



##########
File path: api/internal/handler/ssl/ssl_test.go
##########
@@ -19,146 +19,859 @@ package ssl
 
 import (
 	"encoding/json"
+	"errors"
+	"fmt"
+	"io/ioutil"
+	"net/http"
 	"testing"
-	"time"
 
 	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/data"
 	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/mock"
 
-	"github.com/apisix/manager-api/internal/conf"
 	"github.com/apisix/manager-api/internal/core/entity"
-	"github.com/apisix/manager-api/internal/core/storage"
 	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils/consts"
 )
 
-func TestSSL(t *testing.T) {
-	// init
-	err := storage.InitETCDClient(conf.ETCDConfig)
+func getTestKeyCert(t *testing.T) (string, string) {
+	testCert, err := ioutil.ReadFile("../../../test/certs/test2.crt")
 	assert.Nil(t, err)
-	err = store.InitStores()
+	testKey, err := ioutil.ReadFile("../../../test/certs/test2.key")

Review comment:
       If the key pair is not used in other pleases, what about just put them in the `testdata` directory.

##########
File path: api/internal/handler/ssl/ssl.go
##########
@@ -494,3 +504,4 @@ func (h *Handler) Exist(c droplet.Context) (interface{}, error) {
 
 	return nil, nil
 }
+

Review comment:
       Redundant empty line.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] Jaycean commented on a change in pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
Jaycean commented on a change in pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#discussion_r571740505



##########
File path: api/internal/handler/ssl/ssl.go
##########
@@ -494,3 +504,4 @@ func (h *Handler) Exist(c droplet.Context) (interface{}, error) {
 
 	return nil, nil
 }
+

Review comment:
       Done. Thks.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] juzhiyuan commented on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-774386735


   This PR is ok IMO


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] nic-chen commented on a change in pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
nic-chen commented on a change in pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#discussion_r571738671



##########
File path: api/internal/handler/ssl/ssl_test.go
##########
@@ -19,146 +19,859 @@ package ssl
 
 import (
 	"encoding/json"
+	"errors"
+	"fmt"
+	"io/ioutil"
+	"net/http"
 	"testing"
-	"time"
 
 	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/data"
 	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/mock"
 
-	"github.com/apisix/manager-api/internal/conf"
 	"github.com/apisix/manager-api/internal/core/entity"
-	"github.com/apisix/manager-api/internal/core/storage"
 	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils/consts"
 )
 
-func TestSSL(t *testing.T) {
-	// init
-	err := storage.InitETCDClient(conf.ETCDConfig)
+func getTestKeyCert(t *testing.T) (string, string) {
+	testCert, err := ioutil.ReadFile("../../../test/certs/test2.crt")
 	assert.Nil(t, err)
-	err = store.InitStores()
+	testKey, err := ioutil.ReadFile("../../../test/certs/test2.key")
 	assert.Nil(t, err)
+	return string(testCert), string(testKey)
+}
 
-	handler := &Handler{
-		sslStore: store.GetStore(store.HubKeySsl),
-	}
-	assert.NotNil(t, handler)
-
-	//create
-	ctx := droplet.NewContext()
-	ssl := &entity.SSL{}
-	reqBody := `{
-        "id":"1",
-        "key": "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDGO0J9xrOcmvgh\npkqHIYHCw35FTfIT5uXOSzdF49M2ZAKBQwFG0ovYT8bc0glNLB+hpDhJPL531qSP\nl1ZOe0W1ofP1u0T5Zzc9Rub/kn7RMPq0BsSC6J3rF+rQEwh1PM8qUuD8DxZ7jaOL\niMNL6SyuZIPsS1kPPBtsioukdo666tbjNMixhQbI9Wpg55abdXRFh3i7Zu/9siF1\njCGcsskjOaUOY4sYQ3i5WU/HIIRhA82XuIL+Sxd32P8bKi2UT1sqFXRjAVR7KRWo\nIVvkmSLoZb9ucV6MsccDrRYBf6rLbI1tFj9l2rY6GTFlT+6z7K/ZI60DGi/hsBfl\nDeEQ5WuxAgMBAAECggEAVHQQyucpxHGdfzCKlfGnh+Oj20Du/p2jkHUpEkSSypxn\nGM0EMTkoTTsHvTJath8zRrlhJYqUlxfCOk6+fWc1dsGN30Yuh5b6yMd5SK8QCm20\nkZhEhoU2Kl+hMY66TsBefmia46hF6tOYNq1IjwHDgHTgY35ibgQsptyLy8Ca5HTC\nrnoocP2AcKtM+qwOMGiNHpeh+/zfB91C9AszvS8H2ao5nq4u0/JavPO4A4WmVYol\n7Qv9ACY/8uaKC79syahutbkMjwGsQgYsq9G0QpcLSCuOb4vBbOb130mptSM9NzKg\nTjSxF2D8ob//roZMc1ueTpqAY6WedKV3y3BIBDKuAQKBgQDgGyEsxwR9QtA5EH/h\nJ4GiTQn0aep8G2LSlAtHGndL3sxaGGLt2pk3lNIeRAbOS3APmYskBN418JIF/Ren\nE0CYSrTaxpTs9UXXkgKNJ63Z6r+btswTAVVXG5Zoi/5JRSHRquEVm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GpRMtGpPGMWTuptSIMwNcar/luVig7wGIBeV5ZaOlSOx3911le9mlS7+2lLqf5H\n5dsMkP30Sjv/jfrIL+SE1qeK3kjL0iIwA/PPARvhctExs9y2llT9+drbJofZUi+I\nZdYfAfyJT4htbcl7jHN8oY7vzwgTyxCcBxkbqKfBqabneutj0jfX39zP0G696tiZ\ndQFXCS4wkvw0CG0=\n-----END CERTIFICATE-----",
-        "labels":{
-            "build":"16",
-            "env":"production",
-            "version":"v2"
-        }
-	}`
-	err = json.Unmarshal([]byte(reqBody), ssl)
-	assert.Nil(t, err)
-	ctx.SetInput(ssl)
-	ret, err := handler.Create(ctx)
-	assert.Nil(t, err)
-	objRet, ok := ret.(*entity.SSL)
-	assert.True(t, ok)
-	assert.Equal(t, "1", objRet.ID)
-
-	//sleep
-	time.Sleep(time.Duration(100) * time.Millisecond)
-
-	//get
-	input := &GetInput{}
-	input.ID = "1"
-	ctx.SetInput(input)
-	ret, err = handler.Get(ctx)
-	stored := ret.(*entity.SSL)
-	assert.Nil(t, err)
-	assert.Equal(t, stored.ID, ssl.ID)
-	assert.Equal(t, stored.Labels["build"], "16")
-	assert.Equal(t, stored.Labels["env"], "production")
-	assert.Equal(t, stored.Labels["version"], "v2")
-
-	//update
-	ssl2 := &UpdateInput{}
-	ssl2.ID = "1"
-	reqBody = `{
-        "id":"1",
-        "key": "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDGO0J9xrOcmvgh\npkqHIYHCw35FTfIT5uXOSzdF49M2ZAKBQwFG0ovYT8bc0glNLB+hpDhJPL531qSP\nl1ZOe0W1ofP1u0T5Zzc9Rub/kn7RMPq0BsSC6J3rF+rQEwh1PM8qUuD8DxZ7jaOL\niMNL6SyuZIPsS1kPPBtsioukdo666tbjNMixhQbI9Wpg55abdXRFh3i7Zu/9siF1\njCGcsskjOaUOY4sYQ3i5WU/HIIRhA82XuIL+Sxd32P8bKi2UT1sqFXRjA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FejLHHA60WAX+qy2yNbRY/Zdq2OhkxZU/us+yv2SOtAxov4bAX\n5Q3hEOVrsQIDAQABo3kwdzAOBgNVHQ8BAf8EBAMCBaAwEwYDVR0lBAwwCgYIKwYB\nBQUHAwEwDAYDVR0TAQH/BAIwADAfBgNVHSMEGDAWgBRU+EbJj+Hp62gCrNvb3yQk\nYnPHXDAhBgNVHREEGjAYgglyb3V
 0ZS5jb22CCyoucm91dGUuY29tMA0GCSqGSIb3\nDQEBCwUAA4IBgQAvKN2GEorAlx5sfUU2uiL49iFmQSMDLZQminQl1RIHTI/h+jz8\nNluZSdxDFmNq8am6B2ofD3VLl6StC/G+G6YuekPz+QrUNK4UB+8ftRmY4YRFGTQ6\nRnFli1wOq2ES9vPjKlIj77cznr8uwVHPHq8JxGbn/rx3oVDVPndXFCkJJ1DDjRT+\n22atHNzHt5bc9ut8Fq5NW61P+nnMMFShKJaPBkmm9Pf2pEOd8Y7OU8Iy1Kj65fsE\nUshGF5+RWoxdv6/9f6/uOQhmq3MEKqneUC3pjVZ8TiBlRvADxxR5krvujQswms0D\nFGpRMtGpPGMWTuptSIMwNcar/luVig7wGIBeV5ZaOlSOx3911le9mlS7+2lLqf5H\n5dsMkP30Sjv/jfrIL+SE1qeK3kjL0iIwA/PPARvhctExs9y2llT9+drbJofZUi+I\nZdYfAfyJT4htbcl7jHN8oY7vzwgTyxCcBxkbqKfBqabneutj0jfX39zP0G696tiZ\ndQFXCS4wkvw0CG0=\n-----END CERTIFICATE-----",
-        "labels":{
-            "build":"18",
-            "env":"dev",
-            "version":"v3"
-        }
-	}`
-	err = json.Unmarshal([]byte(reqBody), ssl2)
-	assert.Nil(t, err)
-	ctx.SetInput(ssl2)
-	ret, err = handler.Update(ctx)
-	assert.Nil(t, err)
-	// check the returned value
-	objRet, ok = ret.(*entity.SSL)
-	assert.True(t, ok)
-	assert.Equal(t, "1", objRet.ID)
-	assert.Equal(t, ssl2.Key, objRet.Key)
-	assert.Equal(t, ssl2.Cert, objRet.Cert)
-
-	//sleep
-	time.Sleep(time.Duration(100) * time.Millisecond)
-
-	// get and check
-	input = &GetInput{}
-	input.ID = "1"
-	ctx.SetInput(input)
-	ret, err = handler.Get(ctx)
-	stored = ret.(*entity.SSL)
-	assert.Nil(t, err)
-	assert.Equal(t, stored.ID, ssl.ID)
-	assert.Equal(t, stored.Labels["build"], "18")
-	assert.Equal(t, stored.Labels["env"], "dev")
-	assert.Equal(t, stored.Labels["version"], "v3")
-
-	//list
-	listInput := &ListInput{}
-	reqBody = `{"page_size": 1, "page": 1}`
-	err = json.Unmarshal([]byte(reqBody), listInput)
-	assert.Nil(t, err)
-	ctx.SetInput(listInput)
-	retPage, err := handler.List(ctx)
-	assert.Nil(t, err)
-	dataPage := retPage.(*store.ListOutput)
-	assert.Equal(t, len(dataPage.Rows), 1)
+func TestSSL_Get(t *testing.T) {
+	_cert, _ := getTestKeyCert(t)
+	tests := []struct {
+		caseDesc   string
+		giveInput  *GetInput
+		giveRet    *entity.SSL
+		giveErr    error
+		wantErr    error
+		wantGetKey string
+		wantRet    interface{}
+	}{
+		{
+			caseDesc:   "normal",
+			giveInput:  &GetInput{ID: "ssl1"},
+			wantGetKey: "ssl1",
+			giveRet: &entity.SSL{
+				BaseInfo: entity.BaseInfo{
+					ID: "ssl1",
+				},
+				Key:  "",

Review comment:
       we should return un-empty `Key` to check whether the value of `Key` can be omit in the api response 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] starsz commented on a change in pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
starsz commented on a change in pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#discussion_r571541696



##########
File path: api/internal/handler/ssl/ssl.go
##########
@@ -198,7 +198,16 @@ func (h *Handler) Create(c droplet.Context) (interface{}, error) {
 		return handler.SpecCodeResponse(err), err
 	}
 
-	return ret, nil
+	//format respond
+	_ssl := &entity.SSL{}
+	err = utils.ObjectClone(ret, _ssl)

Review comment:
       > we could directly manipulate the returned value of Create/Update/Patch methods without any side effect.
   
   Yes.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] Jaycean commented on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
Jaycean commented on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-774659917


   @starsz @imjoey 
   I think we can submit a new issue to record the coverage problem. This PR is merged first, and then a new PR is submitted to solve the problem of inconsistent coverage


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] Jaycean commented on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
Jaycean commented on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-774572790


   > it seems that the coverage rate has decreased? need to confirm
   
   I'll check the test cases again.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] Jaycean commented on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
Jaycean commented on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-774487370


   
   
   
   > > ping @nic-chen @starsz @juzhiyuan
   > > I noticed that in code
   > > https://github.com/apache/apisix-dashboard/blob/8796fa1b00617f83b495798cc7b86418d1456533/api/internal/handler/ssl/ssl.go#L97-L98
   > > 
   > > , the `Key` and `Keys` properties are both set to empty value. This seems to hide private key from users, right? If so, I guess we should also hide them in Create/Update/Patch methods, also needing to update the `giveRet` for unit tests here. Looking forward to your feedbacks. Thanks.
   > 
   > @Jaycean Could you please set the `Key` and `Keys` to empty values within Create/Update/Patch methods here, just as what's done in Get/List ? Note that also change the relevant unit tests. Thank you very much.
   
   done.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] starsz commented on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
starsz commented on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-774580281


   > @nic-chen @starsz @imjoey
   > May I ask you some questions?
   > SSL has more unit test cases than before.
   > Why does the coverage rate decrease instead?
   > Is unit test unable to detect mock methods?
   
   It seems strange. Maybe we need to check the number that comes from first.
   
   ![image](https://user-images.githubusercontent.com/25628854/107134960-ab1c3a80-6931-11eb-982e-d9dcd1adc821.png)
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] imjoey commented on a change in pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
imjoey commented on a change in pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#discussion_r571527493



##########
File path: api/internal/handler/ssl/ssl.go
##########
@@ -198,7 +198,16 @@ func (h *Handler) Create(c droplet.Context) (interface{}, error) {
 		return handler.SpecCodeResponse(err), err
 	}
 
-	return ret, nil
+	//format respond
+	_ssl := &entity.SSL{}
+	err = utils.ObjectClone(ret, _ssl)

Review comment:
       > Oh, I only know the `Get` method.
   > Because the ret that return by the Get is a point. We will hide the key in the latter (see line 207 ~ 208). If we don't do the objectClone, then will influence the value in s.cache.
   
   @starsz thanks for your explanations. Agreed with you for getting the value instead of cloning. Maybe more comments could be added here for noticing other developers. As far as I know, we could directly manipulate the returned value of Create/Update/Patch methods without any side effect. Please correct me if I was wrong.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] imjoey commented on a change in pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
imjoey commented on a change in pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#discussion_r571542457



##########
File path: api/internal/handler/ssl/ssl.go
##########
@@ -198,7 +198,16 @@ func (h *Handler) Create(c droplet.Context) (interface{}, error) {
 		return handler.SpecCodeResponse(err), err
 	}
 
-	return ret, nil
+	//format respond
+	_ssl := &entity.SSL{}
+	err = utils.ObjectClone(ret, _ssl)

Review comment:
       @Jaycean  please directly manipulate the returned value instead of cloning within Create/Update/Patch methods.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] Jaycean commented on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
Jaycean commented on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-774145436


   > may sync the latest codes?
   
   Let me rebase the code.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] juzhiyuan commented on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-774386087


   Yep, once that resource is created, users couldn't fetch it anymore for security.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] imjoey commented on a change in pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
imjoey commented on a change in pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#discussion_r571541798



##########
File path: api/internal/handler/ssl/ssl.go
##########
@@ -198,7 +198,16 @@ func (h *Handler) Create(c droplet.Context) (interface{}, error) {
 		return handler.SpecCodeResponse(err), err
 	}
 
-	return ret, nil
+	//format respond
+	_ssl := &entity.SSL{}
+	err = utils.ObjectClone(ret, _ssl)

Review comment:
       > > we could directly manipulate the returned value of Create/Update/Patch methods without any side effect.
   > 
   > Yes.
   
   Thanks 👍 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] tokers commented on a change in pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#discussion_r571819668



##########
File path: api/internal/handler/ssl/ssl_test.go
##########
@@ -19,146 +19,859 @@ package ssl
 
 import (
 	"encoding/json"
+	"errors"
+	"fmt"
+	"io/ioutil"
+	"net/http"
 	"testing"
-	"time"
 
 	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/data"
 	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/mock"
 
-	"github.com/apisix/manager-api/internal/conf"
 	"github.com/apisix/manager-api/internal/core/entity"
-	"github.com/apisix/manager-api/internal/core/storage"
 	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils/consts"
 )
 
-func TestSSL(t *testing.T) {
-	// init
-	err := storage.InitETCDClient(conf.ETCDConfig)
+func getTestKeyCert(t *testing.T) (string, string) {
+	testCert, err := ioutil.ReadFile("../../../test/certs/test2.crt")
 	assert.Nil(t, err)
-	err = store.InitStores()
+	testKey, err := ioutil.ReadFile("../../../test/certs/test2.key")

Review comment:
       OK




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] Jaycean commented on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
Jaycean commented on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-774465397


   > > ping @nic-chen @starsz @juzhiyuan
   > > I noticed that in code
   > > https://github.com/apache/apisix-dashboard/blob/8796fa1b00617f83b495798cc7b86418d1456533/api/internal/handler/ssl/ssl.go#L97-L98
   > > 
   > > , the `Key` and `Keys` properties are both set to empty value. This seems to hide private key from users, right? If so, I guess we should also hide them in Create/Update/Patch methods, also needing to update the `giveRet` for unit tests here. Looking forward to your feedbacks. Thanks.
   > 
   > @Jaycean Could you please set the `Key` and `Keys` to empty values within Create/Update/Patch methods here, just as what's done in Get/List ? Note that also change the relevant unit tests. Thank you very much.
   
   OK, I will modify it in this pr.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] Jaycean commented on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
Jaycean commented on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-774660741


   @starsz @imjoey
   I think we can submit a new issue to record the coverage problem. This PR is merged first, and then a new PR is submitted to solve the problem of inconsistent coverage
   —
   You are receiving this because you were mentioned.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] codecov-io edited a comment on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-773958991


   # [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=h1) Report
   > Merging [#1436](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=desc) (089597a) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/8796fa1b00617f83b495798cc7b86418d1456533?el=desc) (8796fa1) will **increase** coverage by `1.22%`.
   > The diff coverage is `100.00%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #1436      +/-   ##
   ==========================================
   + Coverage   67.61%   68.84%   +1.22%     
   ==========================================
     Files          48       48              
     Lines        3042     3049       +7     
   ==========================================
   + Hits         2057     2099      +42     
   + Misses        741      707      -34     
   + Partials      244      243       -1     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [api/internal/handler/ssl/ssl.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvc3NsL3NzbC5nbw==) | `68.87% <100.00%> (+20.72%)` | :arrow_up: |
   | [api/internal/core/storage/etcd.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmFnZS9ldGNkLmdv) | `41.81% <0.00%> (-1.82%)` | :arrow_down: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=footer). Last update [8796fa1...089597a](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] imjoey commented on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
imjoey commented on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-774387932


   > ping @nic-chen @starsz @juzhiyuan
   > I noticed that in code
   > 
   > https://github.com/apache/apisix-dashboard/blob/8796fa1b00617f83b495798cc7b86418d1456533/api/internal/handler/ssl/ssl.go#L97-L98
   > 
   > , the `Key` and `Keys` properties are both set to empty value. This seems to hide private key from users, right? If so, I guess we should also hide them in Create/Update/Patch methods, also needing to update the `giveRet` for unit tests here. Looking forward to your feedbacks. Thanks.
   
   @Jaycean Could you please set the `Key` and `Keys` to empty values within Create/Update/Patch methods here, just as what's done in Get/List ? Note that also change the relevant unit tests. Thank you very much.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] imjoey commented on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
imjoey commented on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-774666668


   > @starsz @imjoey
   > I think we can submit a new issue to record the coverage problem. This PR is merged first, and then a new PR is submitted to solve the problem of inconsistent coverage
   > —
   > You are receiving this because you were mentioned.
   
   @Jaycean  it's ok for me. Thanks.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] imjoey commented on a change in pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
imjoey commented on a change in pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#discussion_r571519635



##########
File path: api/internal/handler/ssl/ssl.go
##########
@@ -198,7 +198,16 @@ func (h *Handler) Create(c droplet.Context) (interface{}, error) {
 		return handler.SpecCodeResponse(err), err
 	}
 
-	return ret, nil
+	//format respond
+	_ssl := &entity.SSL{}
+	err = utils.ObjectClone(ret, _ssl)

Review comment:
       @Jaycean @nic-chen @starsz  How about use type assertion here like the following?
   
   ```go
   ssl := ret.(*entity.SSL)
   ```
   
   I also noticed that current `Get` method also uses `ObjectClone()`. I'm a little confused and looking forward to your directions. Thank you very much.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] juzhiyuan commented on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-774123060


   may sync the latest codes?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] juzhiyuan merged pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
juzhiyuan merged pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] Jaycean commented on a change in pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
Jaycean commented on a change in pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#discussion_r571544037



##########
File path: api/internal/handler/ssl/ssl.go
##########
@@ -198,7 +198,16 @@ func (h *Handler) Create(c droplet.Context) (interface{}, error) {
 		return handler.SpecCodeResponse(err), err
 	}
 
-	return ret, nil
+	//format respond
+	_ssl := &entity.SSL{}
+	err = utils.ObjectClone(ret, _ssl)

Review comment:
       OK, thks.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] Jaycean commented on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
Jaycean commented on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-774608071


   @imjoey 
   https://github.com/apache/apisix-dashboard/pull/1436#discussion_r571542457
   done. 
   I used rebase, resulting in no review record.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] starsz commented on a change in pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
starsz commented on a change in pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#discussion_r571525517



##########
File path: api/internal/handler/ssl/ssl.go
##########
@@ -198,7 +198,16 @@ func (h *Handler) Create(c droplet.Context) (interface{}, error) {
 		return handler.SpecCodeResponse(err), err
 	}
 
-	return ret, nil
+	//format respond
+	_ssl := &entity.SSL{}
+	err = utils.ObjectClone(ret, _ssl)

Review comment:
       In fact, we can only get the value instead of using `ObjectClone()`
   
   ```
   ssl := ret.(*entity.SSL)
   _ssl = *ssl
   ```

##########
File path: api/internal/handler/ssl/ssl.go
##########
@@ -198,7 +198,16 @@ func (h *Handler) Create(c droplet.Context) (interface{}, error) {
 		return handler.SpecCodeResponse(err), err
 	}
 
-	return ret, nil
+	//format respond
+	_ssl := &entity.SSL{}
+	err = utils.ObjectClone(ret, _ssl)

Review comment:
       Oh,  I only know the `Get` method.
   Because the ret that return by the Get is a point. We will hide the key in the latter (see line 207 ~ 208). If we don't do the objectClone, then will influence the value in s.cache.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] Jaycean removed a comment on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
Jaycean removed a comment on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-774659917


   @starsz @imjoey 
   I think we can submit a new issue to record the coverage problem. This PR is merged first, and then a new PR is submitted to solve the problem of inconsistent coverage


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] Jaycean commented on a change in pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
Jaycean commented on a change in pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#discussion_r571740473



##########
File path: api/internal/handler/ssl/ssl_test.go
##########
@@ -19,146 +19,859 @@ package ssl
 
 import (
 	"encoding/json"
+	"errors"
+	"fmt"
+	"io/ioutil"
+	"net/http"
 	"testing"
-	"time"
 
 	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/data"
 	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/mock"
 
-	"github.com/apisix/manager-api/internal/conf"
 	"github.com/apisix/manager-api/internal/core/entity"
-	"github.com/apisix/manager-api/internal/core/storage"
 	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils/consts"
 )
 
-func TestSSL(t *testing.T) {
-	// init
-	err := storage.InitETCDClient(conf.ETCDConfig)
+func getTestKeyCert(t *testing.T) (string, string) {
+	testCert, err := ioutil.ReadFile("../../../test/certs/test2.crt")
 	assert.Nil(t, err)
-	err = store.InitStores()
+	testKey, err := ioutil.ReadFile("../../../test/certs/test2.key")
 	assert.Nil(t, err)
+	return string(testCert), string(testKey)
+}
 
-	handler := &Handler{
-		sslStore: store.GetStore(store.HubKeySsl),
-	}
-	assert.NotNil(t, handler)
-
-	//create
-	ctx := droplet.NewContext()
-	ssl := &entity.SSL{}
-	reqBody := `{
-        "id":"1",
-        "key": "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDGO0J9xrOcmvgh\npkqHIYHCw35FTfIT5uXOSzdF49M2ZAKBQwFG0ovYT8bc0glNLB+hpDhJPL531qSP\nl1ZOe0W1ofP1u0T5Zzc9Rub/kn7RMPq0BsSC6J3rF+rQEwh1PM8qUuD8DxZ7jaOL\niMNL6SyuZIPsS1kPPBtsioukdo666tbjNMixhQbI9Wpg55abdXRFh3i7Zu/9siF1\njCGcsskjOaUOY4sYQ3i5WU/HIIRhA82XuIL+Sxd32P8bKi2UT1sqFXRjAVR7KRWo\nIVvkmSLoZb9ucV6MsccDrRYBf6rLbI1tFj9l2rY6GTFlT+6z7K/ZI60DGi/hsBfl\nDeEQ5WuxAgMBAAECggEAVHQQyucpxHGdfzCKlfGnh+Oj20Du/p2jkHUpEkSSypxn\nGM0EMTkoTTsHvTJath8zRrlhJYqUlxfCOk6+fWc1dsGN30Yuh5b6yMd5SK8QCm20\nkZhEhoU2Kl+hMY66TsBefmia46hF6tOYNq1IjwHDgHTgY35ibgQsptyLy8Ca5HTC\nrnoocP2AcKtM+qwOMGiNHpeh+/zfB91C9AszvS8H2ao5nq4u0/JavPO4A4WmVYol\n7Qv9ACY/8uaKC79syahutbkMjwGsQgYsq9G0QpcLSCuOb4vBbOb130mptSM9NzKg\nTjSxF2D8ob//roZMc1ueTpqAY6WedKV3y3BIBDKuAQKBgQDgGyEsxwR9QtA5EH/h\nJ4GiTQn0aep8G2LSlAtHGndL3sxaGGLt2pk3lNIeRAbOS3APmYskBN418JIF/Ren\nE0CYSrTax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uOQhmq3MEKqneUC3pjVZ8TiBlRvADxxR5krvujQswms0D\nFGpRMtGpPGMWTuptSIMwNcar/luVig7wGIBeV5ZaOlSOx3911le9mlS7+2lLqf5H\n5dsMkP30Sjv/jfrIL+SE1qeK3kjL0iIwA/PPARvhctExs9y2llT9+drbJofZUi+I\nZdYfAfyJT4htbcl7jHN8oY7vzwgTyxCcBxkbqKfBqabneutj0jfX39zP0G696tiZ\ndQFXCS4wkvw0CG0=\n-----END CERTIFICATE-----",
-        "labels":{
-            "build":"16",
-            "env":"production",
-            "version":"v2"
-        }
-	}`
-	err = json.Unmarshal([]byte(reqBody), ssl)
-	assert.Nil(t, err)
-	ctx.SetInput(ssl)
-	ret, err := handler.Create(ctx)
-	assert.Nil(t, err)
-	objRet, ok := ret.(*entity.SSL)
-	assert.True(t, ok)
-	assert.Equal(t, "1", objRet.ID)
-
-	//sleep
-	time.Sleep(time.Duration(100) * time.Millisecond)
-
-	//get
-	input := &GetInput{}
-	input.ID = "1"
-	ctx.SetInput(input)
-	ret, err = handler.Get(ctx)
-	stored := ret.(*entity.SSL)
-	assert.Nil(t, err)
-	assert.Equal(t, stored.ID, ssl.ID)
-	assert.Equal(t, stored.Labels["build"], "16")
-	assert.Equal(t, stored.Labels["env"], "production")
-	assert.Equal(t, stored.Labels["version"], "v2")
-
-	//update
-	ssl2 := &UpdateInput{}
-	ssl2.ID = "1"
-	reqBody = `{
-        "id":"1",
-        "key": "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDGO0J9xrOcmvgh\npkqHIYHCw35FTfIT5uXOSzdF49M2ZAKBQwFG0ovYT8bc0glNLB+hpDhJPL531qSP\nl1ZOe0W1ofP1u0T5Zzc9Rub/kn7RMPq0BsSC6J3rF+rQEwh1PM8qUuD8DxZ7jaOL\niMNL6SyuZIPsS1kPPBtsioukdo666tbjNMixhQbI9Wpg55abdXRFh3i7Zu/9siF1\njCGcsskjOaUOY4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C/ksXd9j/GyotlE9bKhV0YwFUeykV\nqCFb5Jki6GW/bnFejLHHA60WAX+qy2yNbRY/Zdq2OhkxZU/us+yv2SOtAxov4bAX\n5Q3hEOVrsQIDAQABo3kwdzAOBgNVHQ8BAf8EBAMCBaAwEwYDVR0lBAwwCgYIKwYB\nBQUHAwEwDAYDVR0TAQH/BAIwADAfBgNVHSMEGDAWgBRU+EbJj+Hp62gCrNvb3yQk\nYnPHXDAhBgNVHREEGjAYgglyb3V
 0ZS5jb22CCyoucm91dGUuY29tMA0GCSqGSIb3\nDQEBCwUAA4IBgQAvKN2GEorAlx5sfUU2uiL49iFmQSMDLZQminQl1RIHTI/h+jz8\nNluZSdxDFmNq8am6B2ofD3VLl6StC/G+G6YuekPz+QrUNK4UB+8ftRmY4YRFGTQ6\nRnFli1wOq2ES9vPjKlIj77cznr8uwVHPHq8JxGbn/rx3oVDVPndXFCkJJ1DDjRT+\n22atHNzHt5bc9ut8Fq5NW61P+nnMMFShKJaPBkmm9Pf2pEOd8Y7OU8Iy1Kj65fsE\nUshGF5+RWoxdv6/9f6/uOQhmq3MEKqneUC3pjVZ8TiBlRvADxxR5krvujQswms0D\nFGpRMtGpPGMWTuptSIMwNcar/luVig7wGIBeV5ZaOlSOx3911le9mlS7+2lLqf5H\n5dsMkP30Sjv/jfrIL+SE1qeK3kjL0iIwA/PPARvhctExs9y2llT9+drbJofZUi+I\nZdYfAfyJT4htbcl7jHN8oY7vzwgTyxCcBxkbqKfBqabneutj0jfX39zP0G696tiZ\ndQFXCS4wkvw0CG0=\n-----END CERTIFICATE-----",
-        "labels":{
-            "build":"18",
-            "env":"dev",
-            "version":"v3"
-        }
-	}`
-	err = json.Unmarshal([]byte(reqBody), ssl2)
-	assert.Nil(t, err)
-	ctx.SetInput(ssl2)
-	ret, err = handler.Update(ctx)
-	assert.Nil(t, err)
-	// check the returned value
-	objRet, ok = ret.(*entity.SSL)
-	assert.True(t, ok)
-	assert.Equal(t, "1", objRet.ID)
-	assert.Equal(t, ssl2.Key, objRet.Key)
-	assert.Equal(t, ssl2.Cert, objRet.Cert)
-
-	//sleep
-	time.Sleep(time.Duration(100) * time.Millisecond)
-
-	// get and check
-	input = &GetInput{}
-	input.ID = "1"
-	ctx.SetInput(input)
-	ret, err = handler.Get(ctx)
-	stored = ret.(*entity.SSL)
-	assert.Nil(t, err)
-	assert.Equal(t, stored.ID, ssl.ID)
-	assert.Equal(t, stored.Labels["build"], "18")
-	assert.Equal(t, stored.Labels["env"], "dev")
-	assert.Equal(t, stored.Labels["version"], "v3")
-
-	//list
-	listInput := &ListInput{}
-	reqBody = `{"page_size": 1, "page": 1}`
-	err = json.Unmarshal([]byte(reqBody), listInput)
-	assert.Nil(t, err)
-	ctx.SetInput(listInput)
-	retPage, err := handler.List(ctx)
-	assert.Nil(t, err)
-	dataPage := retPage.(*store.ListOutput)
-	assert.Equal(t, len(dataPage.Rows), 1)
+func TestSSL_Get(t *testing.T) {
+	_cert, _ := getTestKeyCert(t)
+	tests := []struct {
+		caseDesc   string
+		giveInput  *GetInput
+		giveRet    *entity.SSL
+		giveErr    error
+		wantErr    error
+		wantGetKey string
+		wantRet    interface{}
+	}{
+		{
+			caseDesc:   "normal",
+			giveInput:  &GetInput{ID: "ssl1"},
+			wantGetKey: "ssl1",
+			giveRet: &entity.SSL{
+				BaseInfo: entity.BaseInfo{
+					ID: "ssl1",
+				},
+				Key:  "",

Review comment:
       Yes, I missed it, fixed. Thks.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] Jaycean commented on a change in pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
Jaycean commented on a change in pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#discussion_r571738713



##########
File path: api/internal/handler/ssl/ssl_test.go
##########
@@ -19,146 +19,859 @@ package ssl
 
 import (
 	"encoding/json"
+	"errors"
+	"fmt"
+	"io/ioutil"
+	"net/http"
 	"testing"
-	"time"
 
 	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/data"
 	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/mock"
 
-	"github.com/apisix/manager-api/internal/conf"
 	"github.com/apisix/manager-api/internal/core/entity"
-	"github.com/apisix/manager-api/internal/core/storage"
 	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils/consts"
 )
 
-func TestSSL(t *testing.T) {
-	// init
-	err := storage.InitETCDClient(conf.ETCDConfig)
+func getTestKeyCert(t *testing.T) (string, string) {
+	testCert, err := ioutil.ReadFile("../../../test/certs/test2.crt")
 	assert.Nil(t, err)
-	err = store.InitStores()
+	testKey, err := ioutil.ReadFile("../../../test/certs/test2.key")

Review comment:
       These two files are also used by E2E test. In order not to create data repeatedly, I directly use the key and cert files.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] imjoey commented on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
imjoey commented on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-774386608


   > Yep, once that resource is created, users couldn't fetch it anymore for security.
   
   @juzhiyuan yep, got it. This is a security issue. We need to fix it. With in this PR or in another PR? What's your opinion?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] imjoey commented on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
imjoey commented on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-774385946


   ping @nic-chen @starsz @juzhiyuan 
   I noticed that in code
   https://github.com/apache/apisix-dashboard/blob/8796fa1b00617f83b495798cc7b86418d1456533/api/internal/handler/ssl/ssl.go#L97-L98 , the `Key` and `Keys` properties are both set to empty value. This seems to hide private key from users, right? If so, I guess we should also hide them in Create/Update/Patch methods,  also needing to update the `giveRet` for unit tests here. Looking forward to your feedbacks. Thanks.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] codecov-io edited a comment on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-773958991


   # [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=h1) Report
   > Merging [#1436](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=desc) (38bf4df) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/9bd3a54a489faa87a34fcba5488dd1579a80d54e?el=desc) (9bd3a54) will **increase** coverage by `0.75%`.
   > The diff coverage is `76.00%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #1436      +/-   ##
   ==========================================
   + Coverage   68.08%   68.83%   +0.75%     
   ==========================================
     Files          48       48              
     Lines        3042     3058      +16     
   ==========================================
   + Hits         2071     2105      +34     
   + Misses        728      707      -21     
   - Partials      243      246       +3     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [api/internal/handler/ssl/ssl.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvc3NsL3NzbC5nbw==) | `67.31% <76.00%> (+19.16%)` | :arrow_up: |
   | [api/internal/core/storage/etcd.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmFnZS9ldGNkLmdv) | `45.45% <0.00%> (-5.46%)` | :arrow_down: |
   | [api/internal/core/store/storehub.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc3RvcmVodWIuZ28=) | `70.40% <0.00%> (-4.09%)` | :arrow_down: |
   | [api/internal/core/store/store.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc3RvcmUuZ28=) | `86.14% <0.00%> (-1.81%)` | :arrow_down: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=footer). Last update [9bd3a54...e3304ac](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] imjoey commented on a change in pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
imjoey commented on a change in pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#discussion_r571338706



##########
File path: api/internal/handler/ssl/ssl_test.go
##########
@@ -18,147 +18,737 @@
 package ssl
 
 import (
-	"encoding/json"
+	"errors"
+	"fmt"
+	"net/http"
 	"testing"
-	"time"
 
 	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/data"
 	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/mock"
 
-	"github.com/apisix/manager-api/internal/conf"
 	"github.com/apisix/manager-api/internal/core/entity"
-	"github.com/apisix/manager-api/internal/core/storage"
 	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils/consts"
 )
 
-func TestSSL(t *testing.T) {
-	// init
-	err := storage.InitETCDClient(conf.ETCDConfig)
-	assert.Nil(t, err)
-	err = store.InitStores()
-	assert.Nil(t, err)
-
-	handler := &Handler{
-		sslStore: store.GetStore(store.HubKeySsl),
-	}
-	assert.NotNil(t, handler)
-
-	//create
-	ctx := droplet.NewContext()
-	ssl := &entity.SSL{}
-	reqBody := `{
-        "id":"1",
-        "key": "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDGO0J9xrOcmvgh\npkqHIYHCw35FTfIT5uXOSzdF49M2ZAKBQwFG0ovYT8bc0glNLB+hpDhJPL531qSP\nl1ZOe0W1ofP1u0T5Zzc9Rub/kn7RMPq0BsSC6J3rF+rQEwh1PM8qUuD8DxZ7jaOL\niMNL6SyuZIPsS1kPPBtsioukdo666tbjNMixhQbI9Wpg55abdXRFh3i7Zu/9siF1\njCGcsskjOaUOY4sYQ3i5WU/HIIRhA82XuIL+Sxd32P8bKi2UT1sqFXRjAVR7KRWo\nIVvkmSLoZb9ucV6MsccDrRYBf6rLbI1tFj9l2rY6GTFlT+6z7K/ZI60DGi/hsBfl\nDeEQ5WuxAgMBAAECggEAVHQQyucpxHGdfzCKlfGnh+Oj20Du/p2jkHUpEkSSypxn\nGM0EMTkoTTsHvTJath8zRrlhJYqUlxfCOk6+fWc1dsGN30Yuh5b6yMd5SK8QCm20\nkZhEhoU2Kl+hMY66TsBefmia46hF6tOYNq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A0GCSqGSIb3\nDQEBCwUAA4IBgQAvKN2GEorAlx5sfUU2uiL49iFmQSMDLZQminQl1RIHTI/h+jz8\nNluZSdxDFmNq8am6B2ofD3VLl6StC/G+G6YuekPz+QrUNK4UB+8ftRmY4YRFGTQ6\nRnFli1wOq2ES9vPjKlIj77cznr8uwVHPHq8JxGbn/rx3oVDVPndXFCkJJ1DDjRT+\n22atHNzHt5bc9ut8Fq5NW61P+nnMMFShKJaPBkmm9Pf2pEOd8Y7OU8Iy1Kj65fsE\nUshGF5+RWoxdv6/9f6/uOQhmq3MEKqneUC3pjVZ8TiBlRvADxxR5krvujQswms0D\nFGpRMtGpPGMWTuptSIMwNcar/luVig7wGIBeV5ZaOlSOx3911le9mlS7+2lLqf5H\n5dsMkP30Sjv/jfrIL+SE1qeK3kjL0iIwA/PPARvhctExs9y2llT9+drbJofZUi+I\nZdYfAfyJT4htbcl7jHN8oY7vzwgTyxCcBxkbqKfBqabneutj0jfX39zP0G696tiZ\ndQFXCS4wkvw0CG0=\n-----END CERTIFICATE-----",
-        "labels":{
-            "build":"16",
-            "env":"production",
-            "version":"v2"
-        }
-	}`
-	err = json.Unmarshal([]byte(reqBody), ssl)
-	assert.Nil(t, err)
-	ctx.SetInput(ssl)
-	ret, err := handler.Create(ctx)
-	assert.Nil(t, err)
-	objRet, ok := ret.(*entity.SSL)
-	assert.True(t, ok)
-	assert.Equal(t, "1", objRet.ID)
-
-	//sleep
-	time.Sleep(time.Duration(100) * time.Millisecond)
-
-	//get
-	input := &GetInput{}
-	input.ID = "1"
-	ctx.SetInput(input)
-	ret, err = handler.Get(ctx)
-	stored := ret.(*entity.SSL)
-	assert.Nil(t, err)
-	assert.Equal(t, stored.ID, ssl.ID)
-	assert.Equal(t, stored.Labels["build"], "16")
-	assert.Equal(t, stored.Labels["env"], "production")
-	assert.Equal(t, stored.Labels["version"], "v2")
-
-	//update
-	ssl2 := &UpdateInput{}
-	ssl2.ID = "1"
-	reqBody = `{
-        "id":"1",
-        "key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8oY7vzwgTyxCcBxkbqKfBqabneutj0jfX39zP0G696tiZ\ndQFXCS4wkvw0CG0=\n-----END CERTIFICATE-----",
-        "labels":{
-            "build":"18",
-            "env":"dev",
-            "version":"v3"
-        }
-	}`
-	err = json.Unmarshal([]byte(reqBody), ssl2)
-	assert.Nil(t, err)
-	ctx.SetInput(ssl2)
-	ret, err = handler.Update(ctx)
-	assert.Nil(t, err)
-	// check the returned value
-	objRet, ok = ret.(*entity.SSL)
-	assert.True(t, ok)
-	assert.Equal(t, "1", objRet.ID)
-	assert.Equal(t, ssl2.Key, objRet.Key)
-	assert.Equal(t, ssl2.Cert, objRet.Cert)
-
-	//sleep
-	time.Sleep(time.Duration(100) * time.Millisecond)
-
-	// get and check
-	input = &GetInput{}
-	input.ID = "1"
-	ctx.SetInput(input)
-	ret, err = handler.Get(ctx)
-	stored = ret.(*entity.SSL)
-	assert.Nil(t, err)
-	assert.Equal(t, stored.ID, ssl.ID)
-	assert.Equal(t, stored.Labels["build"], "18")
-	assert.Equal(t, stored.Labels["env"], "dev")
-	assert.Equal(t, stored.Labels["version"], "v3")
-
-	//list
-	listInput := &ListInput{}
-	reqBody = `{"page_size": 1, "page": 1}`
-	err = json.Unmarshal([]byte(reqBody), listInput)
-	assert.Nil(t, err)
-	ctx.SetInput(listInput)
-	retPage, err := handler.List(ctx)
-	assert.Nil(t, err)
-	dataPage := retPage.(*store.ListOutput)
-	assert.Equal(t, len(dataPage.Rows), 1)
-
-	//list search match
-	listInput2 := &ListInput{}
-	reqBody = `{"page_size": 1, "page": 1, "sni": "route"}`
-	err = json.Unmarshal([]byte(reqBody), listInput2)
-	assert.Nil(t, err)
-	ctx.SetInput(listInput2)
-	retPage, err = handler.List(ctx)
-	assert.Nil(t, err)
-	dataPage = retPage.(*store.ListOutput)
-	assert.Equal(t, len(dataPage.Rows), 1)
-
-	//list search not match
-	listInput3 := &ListInput{}
-	reqBody = `{"page_size": 1, "page": 1, "sni": "not-exists"}`
-	err = json.Unmarshal([]byte(reqBody), listInput3)
-	assert.Nil(t, err)
-	ctx.SetInput(listInput3)
-	retPage, err = handler.List(ctx)
-	assert.Nil(t, err)
-	dataPage = retPage.(*store.ListOutput)
-	assert.Equal(t, len(dataPage.Rows), 0)
-
-	//delete test data
-	inputDel := &BatchDelete{}
-	reqBody = `{"ids": "1"}`
-	err = json.Unmarshal([]byte(reqBody), inputDel)
-	assert.Nil(t, err)
-	ctx.SetInput(inputDel)
-	_, err = handler.BatchDelete(ctx)
-	assert.Nil(t, err)
+var (
+	_key  string = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDGO0J9xrOcmvgh\npkqHIYHCw35FTfIT5uXOSzdF49M2ZAKBQwFG0ovYT8bc0glNLB+hpDhJPL531qSP\nl1ZOe0W1ofP1u0T5Zzc9Rub/kn7RMPq0BsSC6J3rF+rQEwh1PM8qUuD8DxZ7jaOL\niMNL6SyuZIPsS1kPPBtsioukdo666tbjNMixhQbI9Wpg55abdXRFh3i7Zu/9siF1\njCGcsskjOaUOY4sYQ3i5WU/HIIRhA82XuIL+Sxd32P8bKi2UT1sqFXRjAVR7KRWo\nIVvkmSLoZb9ucV6MsccDrRYBf6rLbI1tFj9l2rY6GTFlT+6z7K/ZI60DGi/hsBfl\nDeEQ5WuxAgMBAAECggEAVHQQyucpxHGdfzCKlfGnh+Oj20Du/p2jkHUpEkSSypxn\nGM0EMTkoTTsHvTJath8zRrlhJYqUlxfCOk6+fWc1dsGN30Yuh5b6yMd5SK8QCm20\nkZhEhoU2Kl+hMY66TsBefmia46hF6tOYNq1IjwHDgHTgY35ibgQsptyLy8Ca5HTC\nrnoocP2AcKtM+qwOMGiNHpeh+/zfB91C9AszvS8H2ao5nq4u0/JavPO4A4WmVYol\n7Qv9ACY/8uaKC79syahutbkMjwGsQgYsq9G0QpcLSCuOb4vBbOb130mptSM9NzKg\nTjSxF2D8ob//roZMc1ueTpqAY6WedKV3y3BIBDKuAQKBgQDgGyEsxwR9QtA5EH/h\nJ4GiTQn0aep8G2LSlAtHGndL3sxaGGLt2pk3lNIeRAbOS3APmYskBN418JIF/Ren\nE0CYSrTaxpTs9UXXkgKNJ63Z6r+btswTAVVXG5Zoi/5JRSHRquEVmKccM4zg3v6R\ny/nVhwXigUaRuLx+wCtoaGsaUQK
 BgQDicXFZ0TvN8tohqc8dbmOu2A25+ifFKHUA\nn3yxZIJtbTC9bJeuwtkqIFol1DXHLqYvdD5jQT3c4z6HekcmI9sEy1YzO4a3WUTI\nP//ogjDLXj402k+WCx1Us2HASxwU5cRvOpMhfnppYPSDXqBoH196UCDmOQuS1+Q8\njyPsNQmDYQKBgQDcm5hCvf87V4QmSIm6GOvR20iLY6BCX6seZEHd0r3Q4BgGMK9i\nOahOQJ++z3Rrq3M6yAligbBFJPZ6ErUv8RHLWO9D1exQfvorxT3huke3lxDbtkya\nANwDjdK4Q+ckNXufLDm6yrTmXBC4ZIvw9fyQKASw/lV7qYFUvNN+Shv0oQKBgQC+\nraw3Z7smV0NbaXRgYh5KkuAsJPvsR38OwT3s2qgBoRqTx6eKn8Tidk+y3xlR2nRS\nLV6DkeKX6Ds1NcBH25WIWfkCNzPfnKoQveOuVELmXTugody2ijFuq4a6uASzjC93\nQim24JwPtHbxUHNeelyZ0HODqbGXO3iTji0/sAGMwQKBgQC8yDwapXgrCWK34qpN\nSdO9uA4VstI3Ovb+o3Evfp1CvJnfk56ypO2DaqbuvMJsInuWRFU40UWp7Vxyl/hP\nXvGgEI3dbBy9KWFjAKfI2Wv3i+zvJ1mAHM3u1jcX3zxOxSAN4LJVBudgkGpop1ps\nW5tWveXiXwxCUE/r9ax4mfJvXQ==\n-----END PRIVATE KEY-----"

Review comment:
       @Jaycean  As recommended by @nic-chen in https://github.com/apache/apisix-dashboard/pull/1423#discussion_r569931288 , we would better to put the key and cert data into files for clean code. What's your idea?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] codecov-io edited a comment on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-773958991


   # [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=h1) Report
   > Merging [#1436](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=desc) (089597a) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/8796fa1b00617f83b495798cc7b86418d1456533?el=desc) (8796fa1) will **decrease** coverage by `9.27%`.
   > The diff coverage is `100.00%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #1436      +/-   ##
   ==========================================
   - Coverage   67.61%   58.34%   -9.28%     
   ==========================================
     Files          48       48              
     Lines        3042     3049       +7     
   ==========================================
   - Hits         2057     1779     -278     
   - Misses        741     1025     +284     
   - Partials      244      245       +1     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [api/internal/handler/ssl/ssl.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvc3NsL3NzbC5nbw==) | `68.87% <100.00%> (+20.72%)` | :arrow_up: |
   | [api/internal/core/entity/entity.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvZW50aXR5L2VudGl0eS5nbw==) | `18.75% <0.00%> (-81.25%)` | :arrow_down: |
   | [...l/handler/route\_online\_debug/route\_online\_debug.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvcm91dGVfb25saW5lX2RlYnVnL3JvdXRlX29ubGluZV9kZWJ1Zy5nbw==) | `7.14% <0.00%> (-66.67%)` | :arrow_down: |
   | [api/internal/handler/upstream/upstream.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvdXBzdHJlYW0vdXBzdHJlYW0uZ28=) | `47.45% <0.00%> (-35.60%)` | :arrow_down: |
   | [api/internal/handler/data\_loader/route\_import.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvZGF0YV9sb2FkZXIvcm91dGVfaW1wb3J0Lmdv) | `30.24% <0.00%> (-34.68%)` | :arrow_down: |
   | [api/internal/log/log.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2xvZy9sb2cuZ28=) | `30.00% <0.00%> (-30.00%)` | :arrow_down: |
   | [api/internal/utils/consts/api\_error.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL3V0aWxzL2NvbnN0cy9hcGlfZXJyb3IuZ28=) | `25.00% <0.00%> (-25.00%)` | :arrow_down: |
   | [api/internal/core/store/storehub.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc3RvcmVodWIuZ28=) | `45.91% <0.00%> (-24.49%)` | :arrow_down: |
   | [api/internal/utils/json\_patch.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL3V0aWxzL2pzb25fcGF0Y2guZ28=) | `34.48% <0.00%> (-24.14%)` | :arrow_down: |
   | [api/internal/filter/schema.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2ZpbHRlci9zY2hlbWEuZ28=) | `31.93% <0.00%> (-23.53%)` | :arrow_down: |
   | ... and [13 more](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=footer). Last update [8796fa1...089597a](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] Jaycean commented on a change in pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
Jaycean commented on a change in pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#discussion_r571430191



##########
File path: api/internal/handler/ssl/ssl_test.go
##########
@@ -18,147 +18,737 @@
 package ssl
 
 import (
-	"encoding/json"
+	"errors"
+	"fmt"
+	"net/http"
 	"testing"
-	"time"
 
 	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/data"
 	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/mock"
 
-	"github.com/apisix/manager-api/internal/conf"
 	"github.com/apisix/manager-api/internal/core/entity"
-	"github.com/apisix/manager-api/internal/core/storage"
 	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils/consts"
 )
 
-func TestSSL(t *testing.T) {
-	// init
-	err := storage.InitETCDClient(conf.ETCDConfig)
-	assert.Nil(t, err)
-	err = store.InitStores()
-	assert.Nil(t, err)
-
-	handler := &Handler{
-		sslStore: store.GetStore(store.HubKeySsl),
-	}
-	assert.NotNil(t, handler)
-
-	//create
-	ctx := droplet.NewContext()
-	ssl := &entity.SSL{}
-	reqBody := `{
-        "id":"1",
-        "key": "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDGO0J9xrOcmvgh\npkqHIYHCw35FTfIT5uXOSzdF49M2ZAKBQwFG0ovYT8bc0glNLB+hpDhJPL531qSP\nl1ZOe0W1ofP1u0T5Zzc9Rub/kn7RMPq0BsSC6J3rF+rQEwh1PM8qUuD8DxZ7jaOL\niMNL6SyuZIPsS1kPPBtsioukdo666tbjNMixhQbI9Wpg55abdXRFh3i7Zu/9siF1\njCGcsskjOaUOY4sYQ3i5WU/HIIRhA82XuIL+Sxd32P8bKi2UT1sqFXRjAVR7KRWo\nIVvkmSLoZb9ucV6MsccDrRYBf6rLbI1tFj9l2rY6GTFlT+6z7K/ZI60DGi/hsBfl\nDeEQ5WuxAgMBAAECggEAVHQQyucpxHGdfzCKlfGnh+Oj20Du/p2jkHUpEkSSypxn\nGM0EMTkoTTsHvTJath8zRrlhJYqUlxfCOk6+fWc1dsGN30Yuh5b6yMd5SK8QCm20\nkZhEhoU2Kl+hMY66TsBefmia46hF6tOYNq1IjwHDgHTgY35ibgQsptyLy8Ca5HTC\nrnoocP2AcKtM+qwOMGiNHpeh+/zfB91C9AszvS8H2ao5nq4u0/JavPO4A4WmVYol\n7Qv9ACY/8uaKC79syahutbkMjwGsQgYsq9G0QpcLSCuOb4vBbOb130mptSM9NzKg\nTjSxF2D8ob//roZMc1ueTpqAY6WedKV3y3BIBDKuAQKBgQDgGyEsxwR9QtA5EH/h\nJ4GiTQn0aep8G2LSlAtHGndL3sxaGGLt2pk3lNIeRAbOS3APmYskBN418JIF/Ren\nE0CYSrTaxpT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Qhmq3MEKqneUC3pjVZ8TiBlRvADxxR5krvujQswms0D\nFGpRMtGpPGMWTuptSIMwNcar/luVig7wGIBeV5ZaOlSOx3911le9mlS7+2lLqf5H\n5dsMkP30Sjv/jfrIL+SE1qeK3kjL0iIwA/PPARvhctExs9y2llT9+drbJofZUi+I\nZdYfAfyJT4htbcl7jHN8oY7vzwgTyxCcBxkbqKfBqabneutj0jfX39zP0G696tiZ\ndQFXCS4wkvw0CG0=\n-----END CERTIFICATE-----",
-        "labels":{
-            "build":"16",
-            "env":"production",
-            "version":"v2"
-        }
-	}`
-	err = json.Unmarshal([]byte(reqBody), ssl)
-	assert.Nil(t, err)
-	ctx.SetInput(ssl)
-	ret, err := handler.Create(ctx)
-	assert.Nil(t, err)
-	objRet, ok := ret.(*entity.SSL)
-	assert.True(t, ok)
-	assert.Equal(t, "1", objRet.ID)
-
-	//sleep
-	time.Sleep(time.Duration(100) * time.Millisecond)
-
-	//get
-	input := &GetInput{}
-	input.ID = "1"
-	ctx.SetInput(input)
-	ret, err = handler.Get(ctx)
-	stored := ret.(*entity.SSL)
-	assert.Nil(t, err)
-	assert.Equal(t, stored.ID, ssl.ID)
-	assert.Equal(t, stored.Labels["build"], "16")
-	assert.Equal(t, stored.Labels["env"], "production")
-	assert.Equal(t, stored.Labels["version"], "v2")
-
-	//update
-	ssl2 := &UpdateInput{}
-	ssl2.ID = "1"
-	reqBody = `{
-        "id":"1",
-        "key": "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDGO0J9xrOcmvgh\npkqHIYHCw35FTfIT5uXOSzdF49M2ZAKBQwFG0ovYT8bc0glNLB+hpDhJPL531qSP\nl1ZOe0W1ofP1u0T5Zzc9Rub/kn7RMPq0BsSC6J3rF+rQEwh1PM8qUuD8DxZ7jaOL\niMNL6SyuZIPsS1kPPBtsioukdo666tbjNMixhQbI9Wpg55abdXRFh3i7Zu/9siF1\njCGcsskjOaUOY4sY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ksXd9j/GyotlE9bKhV0YwFUeykV\nqCFb5Jki6GW/bnFejLHHA60WAX+qy2yNbRY/Zdq2OhkxZU/us+yv2SOtAxov4bAX\n5Q3hEOVrsQIDAQABo3kwdzAOBgNVHQ8BAf8EBAMCBaAwEwYDVR0lBAwwCgYIKwYB\nBQUHAwEwDAYDVR0TAQH/BAIwADAfBgNVHSMEGDAWgBRU+EbJj+Hp62gCrNvb3yQk\nYnPHXDAhBgNVHREEGjAYgglyb3V
 0ZS5jb22CCyoucm91dGUuY29tMA0GCSqGSIb3\nDQEBCwUAA4IBgQAvKN2GEorAlx5sfUU2uiL49iFmQSMDLZQminQl1RIHTI/h+jz8\nNluZSdxDFmNq8am6B2ofD3VLl6StC/G+G6YuekPz+QrUNK4UB+8ftRmY4YRFGTQ6\nRnFli1wOq2ES9vPjKlIj77cznr8uwVHPHq8JxGbn/rx3oVDVPndXFCkJJ1DDjRT+\n22atHNzHt5bc9ut8Fq5NW61P+nnMMFShKJaPBkmm9Pf2pEOd8Y7OU8Iy1Kj65fsE\nUshGF5+RWoxdv6/9f6/uOQhmq3MEKqneUC3pjVZ8TiBlRvADxxR5krvujQswms0D\nFGpRMtGpPGMWTuptSIMwNcar/luVig7wGIBeV5ZaOlSOx3911le9mlS7+2lLqf5H\n5dsMkP30Sjv/jfrIL+SE1qeK3kjL0iIwA/PPARvhctExs9y2llT9+drbJofZUi+I\nZdYfAfyJT4htbcl7jHN8oY7vzwgTyxCcBxkbqKfBqabneutj0jfX39zP0G696tiZ\ndQFXCS4wkvw0CG0=\n-----END CERTIFICATE-----",
-        "labels":{
-            "build":"18",
-            "env":"dev",
-            "version":"v3"
-        }
-	}`
-	err = json.Unmarshal([]byte(reqBody), ssl2)
-	assert.Nil(t, err)
-	ctx.SetInput(ssl2)
-	ret, err = handler.Update(ctx)
-	assert.Nil(t, err)
-	// check the returned value
-	objRet, ok = ret.(*entity.SSL)
-	assert.True(t, ok)
-	assert.Equal(t, "1", objRet.ID)
-	assert.Equal(t, ssl2.Key, objRet.Key)
-	assert.Equal(t, ssl2.Cert, objRet.Cert)
-
-	//sleep
-	time.Sleep(time.Duration(100) * time.Millisecond)
-
-	// get and check
-	input = &GetInput{}
-	input.ID = "1"
-	ctx.SetInput(input)
-	ret, err = handler.Get(ctx)
-	stored = ret.(*entity.SSL)
-	assert.Nil(t, err)
-	assert.Equal(t, stored.ID, ssl.ID)
-	assert.Equal(t, stored.Labels["build"], "18")
-	assert.Equal(t, stored.Labels["env"], "dev")
-	assert.Equal(t, stored.Labels["version"], "v3")
-
-	//list
-	listInput := &ListInput{}
-	reqBody = `{"page_size": 1, "page": 1}`
-	err = json.Unmarshal([]byte(reqBody), listInput)
-	assert.Nil(t, err)
-	ctx.SetInput(listInput)
-	retPage, err := handler.List(ctx)
-	assert.Nil(t, err)
-	dataPage := retPage.(*store.ListOutput)
-	assert.Equal(t, len(dataPage.Rows), 1)
-
-	//list search match
-	listInput2 := &ListInput{}
-	reqBody = `{"page_size": 1, "page": 1, "sni": "route"}`
-	err = json.Unmarshal([]byte(reqBody), listInput2)
-	assert.Nil(t, err)
-	ctx.SetInput(listInput2)
-	retPage, err = handler.List(ctx)
-	assert.Nil(t, err)
-	dataPage = retPage.(*store.ListOutput)
-	assert.Equal(t, len(dataPage.Rows), 1)
-
-	//list search not match
-	listInput3 := &ListInput{}
-	reqBody = `{"page_size": 1, "page": 1, "sni": "not-exists"}`
-	err = json.Unmarshal([]byte(reqBody), listInput3)
-	assert.Nil(t, err)
-	ctx.SetInput(listInput3)
-	retPage, err = handler.List(ctx)
-	assert.Nil(t, err)
-	dataPage = retPage.(*store.ListOutput)
-	assert.Equal(t, len(dataPage.Rows), 0)
-
-	//delete test data
-	inputDel := &BatchDelete{}
-	reqBody = `{"ids": "1"}`
-	err = json.Unmarshal([]byte(reqBody), inputDel)
-	assert.Nil(t, err)
-	ctx.SetInput(inputDel)
-	_, err = handler.BatchDelete(ctx)
-	assert.Nil(t, err)
+var (
+	_key  string = "-----BEGIN PRI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j402k+WCx1Us2HASxwU5cRvOpMhfnppYPSDXqBoH196UCDmOQuS1+Q8\njyPsNQmDYQKBgQDcm5hCvf87V4QmSIm6GOvR20iLY6BCX6seZEHd0r3Q4BgGMK9i\nOahOQJ++z3Rrq3M6yAligbBFJPZ6ErUv8RHLWO9D1exQfvorxT3huke3lxDbtkya\nANwDjdK4Q+ckNXufLDm6yrTmXBC4ZIvw9fyQKASw/lV7qYFUvNN+Shv0oQKBgQC+\nraw3Z7smV0NbaXRgYh5KkuAsJPvsR38OwT3s2qgBoRqTx6eKn8Tidk+y3xlR2nRS\nLV6DkeKX6Ds1NcBH25WIWfkCNzPfnKoQveOuVELmXTugody2ijFuq4a6uASzjC93\nQim24JwPtHbxUHNeelyZ0HODqbGXO3iTji0/sAGMwQKBgQC8yDwapXgrCWK34qpN\nSdO9uA4VstI3Ovb+o3Evfp1CvJnfk56ypO2DaqbuvMJsInuWRFU40UWp7Vxyl/hP\nXvGgEI3dbBy9KWFjAKfI2Wv3i+zvJ1mAHM3u1jcX3zxOxSAN4LJVBudgkGpop1ps\nW5tWveXiXwxCUE/r9ax4mfJvXQ==\n-----END PRIVATE KEY-----"

Review comment:
       > @Jaycean As recommended by @nic-chen in [#1423 (comment)](https://github.com/apache/apisix-dashboard/pull/1423#discussion_r569931288) , we would better to put the key and cert data into files for clean code. What's your idea?
   
   Yes, it can make the code cleaner.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] Jaycean commented on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
Jaycean commented on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-774576285


   @nic-chen @starsz @imjoey 
   May I ask you some questions?
   SSL has more unit test cases than before.
   Why does the coverage rate decrease instead?
   Is unit test unable to detect mock methods?
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] codecov-io edited a comment on pull request #1436: feat: refactor ssl unit test

Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #1436:
URL: https://github.com/apache/apisix-dashboard/pull/1436#issuecomment-773958991


   # [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=h1) Report
   > Merging [#1436](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=desc) (089597a) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/8796fa1b00617f83b495798cc7b86418d1456533?el=desc) (8796fa1) will **decrease** coverage by `17.61%`.
   > The diff coverage is `100.00%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=tree)
   
   ```diff
   @@             Coverage Diff             @@
   ##           master    #1436       +/-   ##
   ===========================================
   - Coverage   67.61%   50.00%   -17.62%     
   ===========================================
     Files          48       39        -9     
     Lines        3042     2608      -434     
   ===========================================
   - Hits         2057     1304      -753     
   - Misses        741     1126      +385     
   + Partials      244      178       -66     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [api/internal/handler/ssl/ssl.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvc3NsL3NzbC5nbw==) | `57.14% <100.00%> (+8.99%)` | :arrow_up: |
   | [api/internal/utils/version.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL3V0aWxzL3ZlcnNpb24uZ28=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [api/internal/filter/request\_id.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2ZpbHRlci9yZXF1ZXN0X2lkLmdv) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [api/internal/core/entity/entity.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvZW50aXR5L2VudGl0eS5nbw==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [api/internal/core/store/storehub.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc3RvcmVodWIuZ28=) | `0.00% <0.00%> (-70.41%)` | :arrow_down: |
   | [api/internal/filter/cors.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2ZpbHRlci9jb3JzLmdv) | `0.00% <0.00%> (-66.67%)` | :arrow_down: |
   | [api/internal/filter/schema.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2ZpbHRlci9zY2hlbWEuZ28=) | `0.00% <0.00%> (-55.47%)` | :arrow_down: |
   | [api/internal/handler/upstream/upstream.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvdXBzdHJlYW0vdXBzdHJlYW0uZ28=) | `28.81% <0.00%> (-54.24%)` | :arrow_down: |
   | [api/internal/utils/consts/api\_error.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL3V0aWxzL2NvbnN0cy9hcGlfZXJyb3IuZ28=) | `0.00% <0.00%> (-50.00%)` | :arrow_down: |
   | [api/internal/handler/data\_loader/route\_import.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvZGF0YV9sb2FkZXIvcm91dGVfaW1wb3J0Lmdv) | `27.41% <0.00%> (-37.50%)` | :arrow_down: |
   | ... and [33 more](https://codecov.io/gh/apache/apisix-dashboard/pull/1436/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=footer). Last update [8796fa1...089597a](https://codecov.io/gh/apache/apisix-dashboard/pull/1436?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org