Skip to content

Commit

Permalink
ci: linter check submodules (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
seeflood authored May 26, 2022
1 parent 7a2eefd commit 32d5cd6
Show file tree
Hide file tree
Showing 58 changed files with 458 additions and 534 deletions.
29 changes: 22 additions & 7 deletions .github/workflows/layotto-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,34 @@ jobs:
- name: Format Go
run: |
make check.style
resolve-modules:
name: "🌈️ Resolve Go Modules"
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout Sources
uses: actions/checkout@v2
- id: set-matrix
run: sh ./etc/script/resolve-modules.sh
golangci-lint:
name: "👀 Go CI Linter"
needs: [style-check]
needs: [style-check,resolve-modules]
runs-on: ubuntu-20.04
strategy:
matrix: ${{ fromJson(needs.resolve-modules.outputs.matrix) }}
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.1
go-version: 1.14.15
- name: Go Lint Test
run: make check.lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.46.2
working-directory: ${{ matrix.workdir }}
args: "--out-${NO_FUTURE}format colored-line-number"

go-unit-test:
name: "👀 Go Unit Test"
Expand All @@ -66,7 +81,7 @@ jobs:
- name: Check out code
uses: actions/checkout@v2
- name: Test Coverage
run: make style.coverage
run: make style.coverage
- name: Post Coverage
run: bash <(curl -s https://codecov.io/bash)

Expand Down Expand Up @@ -247,7 +262,7 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
Expand All @@ -271,7 +286,7 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
Expand Down
35 changes: 25 additions & 10 deletions .github/workflows/layotto-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,35 @@ jobs:
- name: Format Go
run: |
make check.style
resolve-modules:
name: "👀 Resolve Go Modules"
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout Sources
uses: actions/checkout@v2
- id: set-matrix
run: sh ./etc/script/resolve-modules.sh
golangci-lint:
name: "👀 Go CI Linter"
needs: [style-check]
needs: [ style-check,resolve-modules ]
runs-on: ubuntu-20.04
strategy:
matrix: ${{ fromJson(needs.resolve-modules.outputs.matrix) }}
steps:
- uses: actions/checkout@v3
- name: Set up Go
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: actions/setup-go@v3
with:
go-version: 1.18.1
- name: Go Lint Test
run: make check.lint
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.14.15
- name: Go Lint Test
uses: golangci/golangci-lint-action@v3
with:
version: v1.46.2
working-directory: ${{ matrix.workdir }}
args: "--out-${NO_FUTURE}format colored-line-number"

go-unit-test:
name: "👀 Go Unit Test"
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ run :
- pkg/mock
skip-files :
- .pb.go
- rpc/invoker/mosn/transport_protocol/bolt.go


linters :
Expand Down
27 changes: 21 additions & 6 deletions components/configstores/apollo/configstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ var (
livenessIndicator *actuators.HealthIndicator
)

const componentName = "apollo"
const (
defaultGroup = "application"
componentName = "apollo"
)

func init() {
readinessIndicator = actuators.NewHealthIndicator()
Expand All @@ -58,8 +61,8 @@ type ConfigStore struct {
listener *changeListener
kvRepo Repository
tagsRepo Repository
kvConfig *RepoConfig
tagsConfig *RepoConfig
kvConfig *repoConfig
tagsConfig *repoConfig
openAPIClient httpClient
}
type httpClient interface {
Expand All @@ -75,7 +78,7 @@ func (c *httpClientImpl) Do(req *http.Request) (*http.Response, error) {
}

func (c *ConfigStore) GetDefaultGroup() string {
return "application"
return defaultGroup
}

func (c *ConfigStore) GetDefaultLabel() string {
Expand Down Expand Up @@ -167,7 +170,7 @@ func (c *ConfigStore) doInit(config *configstores.StoreConfig) error {
}
// TODO make 'env' configurable
// 2. SetConfig client
kvRepoConfig := &RepoConfig{
kvRepoConfig := &repoConfig{
addr: addr,
appId: appId,
env: c.env,
Expand Down Expand Up @@ -472,6 +475,9 @@ func (c *ConfigStore) setItem(appId string, item *configstores.ConfigurationItem
return err
}
req, err := http.NewRequest("PUT", setUrl, strings.NewReader(string(reqBodyJson)))
if err != nil {
return err
}
// add params
q := req.URL.Query()
q.Add("createIfNotExists", "true")
Expand Down Expand Up @@ -535,6 +541,9 @@ func (c *ConfigStore) commit(env string, appId string, cluster string, namespace
return err
}
req, err := http.NewRequest("POST", commitUrl, strings.NewReader(string(reqBodyJson)))
if err != nil {
return err
}
// add headers
c.addHeaderForOpenAPI(req)
// do request
Expand All @@ -553,6 +562,9 @@ func (c *ConfigStore) deleteItem(env string, appId string, cluster string, group
keyWithLabel := c.concatenateKey(key, label)
deleteUrl := fmt.Sprintf(deleteUrlTpl, c.openAPIAddress, env, appId, cluster, group, keyWithLabel)
req, err := http.NewRequest("DELETE", deleteUrl, nil)
if err != nil {
return err
}
// add params
q := req.URL.Query()
q.Add("key", keyWithLabel)
Expand All @@ -571,7 +583,7 @@ func (c *ConfigStore) deleteItem(env string, appId string, cluster string, group
return err
}

func (c *ConfigStore) initTagsClient(tagCfg *RepoConfig) error {
func (c *ConfigStore) initTagsClient(tagCfg *repoConfig) error {
// 1. create if not exist
err := c.createNamespace(c.env, tagCfg.appId, tagCfg.cluster, c.tagsNamespace)
if err != nil {
Expand Down Expand Up @@ -599,6 +611,9 @@ func (c *ConfigStore) createNamespace(env string, appId string, cluster string,
return err
}
req, err := http.NewRequest("POST", url, strings.NewReader(string(reqBodyJson)))
if err != nil {
return err
}
// add headers
c.addHeaderForOpenAPI(req)
log.DefaultLogger.Debugf("createNamespace url: %v, request body: %s, request: %+v", url, reqBodyJson, req)
Expand Down
54 changes: 35 additions & 19 deletions components/configstores/apollo/configstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/zouyx/agollo/v4"
"mosn.io/mosn/pkg/log"

"mosn.io/layotto/components/configstores"
)

const (
prod = "prod"
)

// MockRepository implements Repository interface
type MockRepository struct {
client *agollo.Client
cfg *RepoConfig
cfg *repoConfig
invoked []string
cache map[string]map[string]string
}
Expand All @@ -46,14 +48,10 @@ func (a *MockRepository) Connect() error {
return err
}

func (a *MockRepository) SetConfig(r *RepoConfig) {
func (a *MockRepository) SetConfig(r *repoConfig) {
a.cfg = r
}

func (a *MockRepository) GetConfig() *RepoConfig {
return a.cfg
}

func newMockRepository() *MockRepository {
return &MockRepository{
invoked: make([]string, 0, 2),
Expand All @@ -70,7 +68,7 @@ func (a *MockRepository) Get(namespace string, key string) (interface{}, error)
if _, ok := a.cache[namespace]; !ok {
a.cache[namespace] = make(map[string]string)
}
v, _ := a.cache[namespace][key]
v := a.cache[namespace][key]
return v, nil
}

Expand Down Expand Up @@ -130,8 +128,8 @@ func TestConfigStore_read(t *testing.T) {
// get key
var req configstores.GetRequest
req.AppId = appId
req.Group = "application"
req.Label = "prod"
req.Group = defaultGroup
req.Label = prod
req.Keys = []string{"sofa"}
resp, err := store.Get(context.Background(), &req)
if err != nil || len(resp) == 0 || resp[0].Content != "sofa@$prod" {
Expand Down Expand Up @@ -171,14 +169,14 @@ func TestConfigStore_read(t *testing.T) {
var subReq configstores.SubscribeReq
ch := make(chan *configstores.SubscribeResp)
subReq.AppId = "testApplication_yang"
subReq.Group = "application"
subReq.Label = "prod"
subReq.Group = defaultGroup
subReq.Label = prod
subReq.Keys = []string{"sofa"}
err = store.Subscribe(&subReq, ch)
if err != nil {
t.Error(err)
}
subReq.Group = "application"
subReq.Group = defaultGroup
subReq.Label = ""
subReq.Keys = []string{}
err = store.Subscribe(&subReq, ch)
Expand Down Expand Up @@ -209,6 +207,24 @@ func TestConfigStore_Init(t *testing.T) {
err := store.Init(cfg)
assert.NotNil(t, err)
})
t.Run("when open_api_token blank then error", func(t *testing.T) {
// 1. set up
// inject the MockRepository into a ConfigStore
store, cfg := setup(t)
cfg.Metadata["open_api_token"] = ""
store.openAPIClient = newMockHttpClient(http.StatusBadRequest)
kvRepo := store.kvRepo.(*MockRepository)
kvRepo.Set("application", "sofa@$prod", "sofa@$prod")
kvRepo.Set("application", "apollo@$prod", "apollo@$prod")
kvRepo.Set("dubbo", "dubbo", "dubbo")

// 2. test the ConfigStore,which has a MockRepository in it
// init
log.DefaultLogger.SetLogLevel(log.DEBUG)
err := store.Init(cfg)
assert.Error(t, err)
})

t.Run("when namespace exist then succeed with debug information", func(t *testing.T) {
// 1. set up
// inject the MockRepository into a ConfigStore
Expand Down Expand Up @@ -299,8 +315,8 @@ func TestConfigStore_write(t *testing.T) {
req.AppId = appId
item.Key = "sofa"
item.Content = "v1"
item.Group = "application"
item.Label = "prod"
item.Group = defaultGroup
item.Label = prod
req.StoreName = "apollo"
req.Items = append(req.Items, &item)

Expand Down Expand Up @@ -352,8 +368,8 @@ func TestConfigStore_write(t *testing.T) {
var delReq configstores.DeleteRequest
delReq.AppId = appId
delReq.Keys = []string{"sofa"}
delReq.Group = "application"
delReq.Label = "prod"
delReq.Group = defaultGroup
delReq.Label = prod
err = store.Delete(context.Background(), &delReq)
if err != nil {
t.Error(err)
Expand All @@ -375,7 +391,7 @@ func TestConfigStore_Init_fail(t *testing.T) {
err := store.Init(cfg)
assert.Nil(t, err)
// no config
store, cfg = setup(t)
store, _ = setup(t)
err = store.Init(nil)
if notNil := assert.NotNil(t, err); notNil {
assert.True(t, err.Error() != "")
Expand Down
Loading

0 comments on commit 32d5cd6

Please sign in to comment.