Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add golangci lint to github action workflow #1068

Merged
merged 15 commits into from
Aug 31, 2023
Prev Previous commit
Next Next commit
update based on githubci lint
  • Loading branch information
suchen-sci committed Aug 28, 2023
commit 15983e2bd2f4812d0ad56f1b0b3384952194c0a9
2 changes: 1 addition & 1 deletion pkg/object/meshcontroller/api/api_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (a *API) getServiceDeployment(w http.ResponseWriter, r *http.Request) {
}
}

statefulsets, err := a.k8sClient.AppsV1().StatefulSets("").List(context.Background(), metav1.ListOptions{})
statefulsets, _ := a.k8sClient.AppsV1().StatefulSets("").List(context.Background(), metav1.ListOptions{})
for _, statefulset := range statefulsets.Items {
if statefulset.Annotations[annotationServiceNameKey] == serviceName {
serviceDeployment.App = statefulset
Expand Down
3 changes: 2 additions & 1 deletion pkg/util/sem/semaphore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ func runCase(s *Semaphore, maxCount int64, t *testing.T) {
wg.Wait()

// step 2: try to acquire one more, should timeout
ctx, _ := context.WithTimeout(context.Background(), 100*time.Millisecond)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not call cancel.

ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel()
err := s.AcquireWithContext(ctx)
if err == nil {
t.Fatalf("sema count exceeds the maxCount: %d", maxCount)
Expand Down
12 changes: 6 additions & 6 deletions pkg/util/urlclusteranalyzer/urlclusteranalyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ const (

// URLClusterAnalyzer is url cluster analyzer.
type URLClusterAnalyzer struct {
slots []*field `json:"slots"`
slots []*field
mutex *sync.Mutex
cache *lru.Cache
}

type field struct {
constant string `json:"constant"`
subFields []*field `json:"subFields"`
variableField *field `json:"variableField"`
isVariableField bool `json:"isVariableField"`
pattern string `json:"pattern"`
constant string
subFields []*field
variableField *field
isVariableField bool
pattern string
}

func newField(name string) *field {
Expand Down
54 changes: 17 additions & 37 deletions pkg/util/urlclusteranalyzer/urlclusteranalyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,56 +22,42 @@ import (
"sync"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

var wg sync.WaitGroup

func TestURLClusterAnalyzer(t *testing.T) {
assert := assert.New(t)

urlClusterAnalyzer := New()

p := urlClusterAnalyzer.GetPattern("")
fmt.Println(p)
if p != "" {
t.Fatal("")
}
assert.Equal("", p)

p = urlClusterAnalyzer.GetPattern("city/address/1/order/3")
fmt.Println(p)
if p != "/city/address/1/order/3" {
t.Fatal("")
}
assert.Equal("/city/address/1/order/3", p)

for i := 0; i < maxValues; i++ {
p = urlClusterAnalyzer.GetPattern(fmt.Sprintf("/%d", i))
}
fmt.Println(p)
if p != fmt.Sprintf("/%d", maxValues-1) {
t.Fatal("")
}
assert.Equal(fmt.Sprintf("/%d", maxValues-1), p)

for i := 0; i < maxValues+1; i++ {
p = urlClusterAnalyzer.GetPattern(fmt.Sprintf("/%d", i))
}
fmt.Println(p)
if p != "/*" {
t.Fatal("")
}
assert.Equal("/*", p)

for i := 0; i < maxValues+10; i++ {
p = urlClusterAnalyzer.GetPattern(fmt.Sprintf("/orders/%d", i))
}
fmt.Println(p)
if p != "/orders/*" {
t.Fatal("")
}
assert.Equal("/orders/*", p)

for i := 0; i < maxValues+10; i++ {
p = urlClusterAnalyzer.GetPattern(fmt.Sprintf("/com/megaease/users/%d/orders/%d/details", 1, i))
}
fmt.Println(p)
if p != "/com/megaease/users/1/orders/*/details" {
t.Fatal("")
}
assert.Equal("/com/megaease/users/1/orders/*/details", p)

begin := time.Now()
for i := 0; i < 2; i++ {
Expand All @@ -80,26 +66,20 @@ func TestURLClusterAnalyzer(t *testing.T) {
defer wg.Done()
pat := ""
for i := 0; i < 10000; i++ {
pat = urlClusterAnalyzer.GetPattern(fmt.Sprintf("/com%d/abc/users/%d/orders/%d/details", i%10, i, i))
pat = urlClusterAnalyzer.GetPattern(fmt.Sprintf("/abc/com%d/merchant/%d/sail2/%d/details", i%10, i, i))
pat = urlClusterAnalyzer.GetPattern(fmt.Sprintf("/abc/com/merchant%d/%d/sail3/%d/details", i%10, i, i))
pat = urlClusterAnalyzer.GetPattern(fmt.Sprintf("/abc/com/users/%d/orders/%d/details%d", i, i, i%10))
pat = urlClusterAnalyzer.GetPattern(fmt.Sprintf("/abc/com/merchant/%d/sail/50/details", i))
urlClusterAnalyzer.GetPattern(fmt.Sprintf("/com%d/abc/users/%d/orders/%d/details", i%10, i, i))
urlClusterAnalyzer.GetPattern(fmt.Sprintf("/abc/com%d/merchant/%d/sail2/%d/details", i%10, i, i))
urlClusterAnalyzer.GetPattern(fmt.Sprintf("/abc/com/merchant%d/%d/sail3/%d/details", i%10, i, i))
urlClusterAnalyzer.GetPattern(fmt.Sprintf("/abc/com/users/%d/orders/%d/details%d", i, i, i%10))
urlClusterAnalyzer.GetPattern(fmt.Sprintf("/abc/com/merchant/%d/sail/50/details", i))
pat = urlClusterAnalyzer.GetPattern(fmt.Sprintf("prefix%d/abc/com/merchant/%d/sail15/%d/details", i%10, i, i))
}
fmt.Println(pat)
if pat != "/prefix9/abc/com/merchant/*/sail15/*/details" {
t.Fatal("")
}
assert.Equal("/prefix9/abc/com/merchant/*/sail15/*/details", pat)
}()
}
wg.Wait()
duration := time.Since(begin)
fmt.Println(duration)

p = urlClusterAnalyzer.GetPattern(fmt.Sprintf("/abc/com/merchant/other/other/%d/details", 30))
fmt.Println(p)
if p != "/abc/com/merchant/*/other/30/details" {
t.Fatal("")
}
assert.Equal("/abc/com/merchant/*/other/30/details", p)
}