github.com/wangyougui/gf/v2@v2.6.5/util/gvalid/gvalid_z_unit_issue_test.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/wangyougui/gf.
     6  
     7  package gvalid_test
     8  
     9  import (
    10  	"context"
    11  	"testing"
    12  
    13  	"github.com/wangyougui/gf/v2/util/gvalid"
    14  )
    15  
    16  type Foo struct {
    17  	Bar *Bar `p:"bar" v:"required-without:Baz"`
    18  	Baz *Baz `p:"baz" v:"required-without:Bar"`
    19  }
    20  type Bar struct {
    21  	BarKey string `p:"bar_key" v:"required"`
    22  }
    23  type Baz struct {
    24  	BazKey string `p:"baz_key" v:"required"`
    25  }
    26  
    27  // https://github.com/wangyougui/gf/issues/2503
    28  func Test_Issue2503(t *testing.T) {
    29  	foo := &Foo{
    30  		Bar: &Bar{BarKey: "value"},
    31  	}
    32  	err := gvalid.New().Data(foo).Run(context.Background())
    33  	if err != nil {
    34  		t.Fatal(err)
    35  	}
    36  }