Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
qiangxue committed Oct 29, 2020
1 parent c0d3bb3 commit 34bd547
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions each_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ func TestEach(t *testing.T) {

func TestEachWithContext(t *testing.T) {
rule := Each(WithContext(func(ctx context.Context, value interface{}) error {
if !strings.Contains(value.(string), ctx.Value("contains").(string)) {
if !strings.Contains(value.(string), ctx.Value(contains).(string)) {
return errors.New("unexpected value")
}
return nil
}))
ctx1 := context.WithValue(context.Background(), "contains", "abc")
ctx2 := context.WithValue(context.Background(), "contains", "xyz")
ctx1 := context.WithValue(context.Background(), contains, "abc")
ctx2 := context.WithValue(context.Background(), contains, "xyz")

tests := []struct {
tag string
Expand Down
6 changes: 2 additions & 4 deletions when.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ func (r WhenRule) ValidateWithContext(ctx context.Context, value interface{}) er
if r.condition {
if ctx == nil {
return Validate(value, r.rules...)
} else {
return ValidateWithContext(ctx, value, r.rules...)
}
return ValidateWithContext(ctx, value, r.rules...)
}

if ctx == nil {
return Validate(value, r.elseRules...)
} else {
return ValidateWithContext(ctx, value, r.elseRules...)
}
return ValidateWithContext(ctx, value, r.elseRules...)
}

// Else returns a validation rule that executes the given list of rules when the condition is false.
Expand Down
12 changes: 9 additions & 3 deletions when_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,21 @@ func TestWhen(t *testing.T) {
}
}

type ctxKey int

const (
contains ctxKey = iota
)

func TestWhenWithContext(t *testing.T) {
rule := WithContext(func(ctx context.Context, value interface{}) error {
if !strings.Contains(value.(string), ctx.Value("contains").(string)) {
if !strings.Contains(value.(string), ctx.Value(contains).(string)) {
return errors.New("unexpected value")
}
return nil
})
ctx1 := context.WithValue(context.Background(), "contains", "abc")
ctx2 := context.WithValue(context.Background(), "contains", "xyz")
ctx1 := context.WithValue(context.Background(), contains, "abc")
ctx2 := context.WithValue(context.Background(), contains, "xyz")

tests := []struct {
tag string
Expand Down

0 comments on commit 34bd547

Please sign in to comment.