Skip to content

Commit

Permalink
test: reduce ut (#736)
Browse files Browse the repository at this point in the history
  • Loading branch information
baerwang authored Aug 14, 2023
1 parent 3ea47a2 commit d06a73e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 3 deletions.
3 changes: 1 addition & 2 deletions cmd/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
79 changes: 79 additions & 0 deletions pkg/reduce/reduce_test.go
Original file line number Diff line number Diff line change
@@ -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])
}
}
}

0 comments on commit d06a73e

Please sign in to comment.