Skip to content

Commit

Permalink
test(ut): add controller trigger ut (vanus-labs#52)
Browse files Browse the repository at this point in the history
* test(ut): add controller trigger ut

* test: add .codecov.yml

Co-authored-by: wenfeng <[email protected]>
  • Loading branch information
xdlbdy and wenfengwang authored May 20, 2022
1 parent f2604a5 commit 152e8a5
Show file tree
Hide file tree
Showing 25 changed files with 1,247 additions and 101 deletions.
25 changes: 25 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
codecov:
require_ci_to_pass: yes

coverage:
precision: 2
round: down
range: "70...100"

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no

ignore:
- "**/mock*.go"
- "**/fake*.go"
- "**/fake.go"

comment:
layout: "reach,diff,flags,files,footer"
behavior: default
require_changes: no
4 changes: 2 additions & 2 deletions internal/controller/trigger/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (
)

type TriggerWorkerInfo struct {
Id string `json:"-"`
ID string `json:"-"`
Addr string `json:"addr"`
Phase TriggerWorkerPhase `json:"phase"`
AssignSubIds map[vanus.ID]time.Time `json:"-"`
Expand All @@ -43,7 +43,7 @@ type TriggerWorkerInfo struct {
func NewTriggerWorkerInfo(addr string) *TriggerWorkerInfo {
twInfo := &TriggerWorkerInfo{
Addr: addr,
Id: util.GetIdByAddr(addr),
ID: util.GetIdByAddr(addr),
Phase: TriggerWorkerPhasePending,
}
twInfo.Init()
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/trigger/storage/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (f *fake) DeleteOffset(ctx context.Context, subId vanus.ID) error {
}

func (f *fake) SaveTriggerWorker(ctx context.Context, info info.TriggerWorkerInfo) error {
f.tWorkers[info.Id] = &info
f.tWorkers[info.ID] = &info
return nil
}
func (f *fake) GetTriggerWorker(ctx context.Context, id string) (*info.TriggerWorkerInfo, error) {
Expand Down
94 changes: 94 additions & 0 deletions internal/controller/trigger/storage/mock_offset.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions internal/controller/trigger/storage/mock_storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2022 Linkall Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package storage

import "github.com/golang/mock/gomock"

type MockStorage struct {
*MockOffsetStorage
*MockSubscriptionStorage
*MockTriggerWorkerStorage
}

// NewMockStorage creates a new mock instance.
func NewMockStorage(ctrl *gomock.Controller) *MockStorage {
mock := &MockStorage{
MockOffsetStorage: NewMockOffsetStorage(ctrl),
MockSubscriptionStorage: NewMockSubscriptionStorage(ctrl),
MockTriggerWorkerStorage: NewMockTriggerWorkerStorage(ctrl),
}
return mock
}

func (m *MockStorage) Close() {
}
109 changes: 109 additions & 0 deletions internal/controller/trigger/storage/mock_subscription.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 94 additions & 0 deletions internal/controller/trigger/storage/mock_trigger_worker.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/controller/trigger/storage/offset.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:generate mockgen -source=offset.go -destination=mock_offset.go -package=storage
package storage

import (
Expand Down
Loading

0 comments on commit 152e8a5

Please sign in to comment.