diff --git a/cmd/admin/admin.go b/cmd/admin/admin.go index 2cd4863a..1b341783 100644 --- a/cmd/admin/admin.go +++ b/cmd/admin/admin.go @@ -78,8 +78,7 @@ func Run(bootstrapPath string, addr string) error { return err } discovery := boot.NewDiscovery(bootstrapPath) - - if err := boot.Boot(context.Background(), discovery); err != nil { + if err = boot.Boot(context.Background(), discovery); err != nil { log.Fatal("start failed: %v", err) return err } diff --git a/cmd/start/start.go b/cmd/start/start.go index c2ee4302..475ada47 100644 --- a/cmd/start/start.go +++ b/cmd/start/start.go @@ -102,7 +102,7 @@ func Run(bootstrapConfigPath string) { return } - if err := registry.DoRegistry(context.Background(), serviceRegistry, "service", listenersConf); err != nil { + if err = registry.DoRegistry(context.Background(), serviceRegistry, "service", listenersConf); err != nil { log.Errorf("do service register failed: %v", err) return } diff --git a/pkg/reduce/reduce_test.go b/pkg/reduce/reduce_test.go new file mode 100644 index 00000000..da850c25 --- /dev/null +++ b/pkg/reduce/reduce_test.go @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 reduce + +import ( + "testing" + "time" +) + +import ( + "github.com/shopspring/decimal" + "github.com/stretchr/testify/assert" +) + +func TestReduce(t *testing.T) { + + now := time.Now() + + reduces := map[Reducer][]any{ + Min(): {int64(1), float64(1), decimal.New(1, 0), now}, + Max(): {int64(2), float64(2), decimal.New(2, 0), now.Add(5 * time.Second)}, + Sum(): {int64(3), float64(3), decimal.New(3, 0), nil}, + } + + for r, v := range reduces { + i, err := r.Int64(1, 2) + assert.NoError(t, err) + assert.Equal(t, i, v[0]) + + float, err := r.Float64(1, 2) + assert.NoError(t, err) + assert.Equal(t, float, v[1]) + + d, err := r.Decimal(decimal.New(1, 0), decimal.New(2, 0)) + assert.NoError(t, err) + assert.Equal(t, d, v[2]) + + times, err := r.Time(now, now.Add(5*time.Second)) + if v[3] != nil { + assert.NoError(t, err) + assert.Equal(t, times, v[3]) + } + } + + for r, v := range reduces { + i, err := r.Int64(2, 1) + assert.NoError(t, err) + assert.Equal(t, i, v[0]) + + float, err := r.Float64(2, 1) + assert.NoError(t, err) + assert.Equal(t, float, v[1]) + + d, err := r.Decimal(decimal.New(2, 0), decimal.New(1, 0)) + assert.NoError(t, err) + assert.Equal(t, d, v[2]) + + times, err := r.Time(now.Add(5*time.Second), now) + if v[3] != nil { + assert.NoError(t, err) + assert.Equal(t, times, v[3]) + } + } +}