本文整理汇总了Golang中github.com/smartystreets/assertions.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestNilReferencesForwardToStandardBehavior
func TestNilReferencesForwardToStandardBehavior(t *testing.T) {
t.Parallel()
thing := new(ThingUnderTest)
now := time.Now().UTC()
now2 := thing.CurrentTime()
thing.Sleep(time.Millisecond * 100)
now3 := thing.CurrentTime()
assertions.New(t).So(now, should.HappenWithin, time.Millisecond, now2)
assertions.New(t).So(now3, should.HappenOnOrAfter, now2.Add(time.Millisecond*100))
}
开发者ID:smartystreets,项目名称:clock,代码行数:11,代码来源:clock_test.go
示例2: TestActualSleeperInstanceIsUsefulForTesting
func TestActualSleeperInstanceIsUsefulForTesting(t *testing.T) {
t.Parallel()
thing := new(ThingUnderTest)
now := time.Now().UTC()
thing.sleeper = StayAwake()
thing.Sleep(time.Hour)
now2 := thing.CurrentTime()
assertions.New(t).So(now, should.HappenWithin, time.Millisecond, now2)
assertions.New(t).So(thing.sleeper.Naps, should.Resemble, []time.Duration{time.Hour})
}
开发者ID:smartystreets,项目名称:clock,代码行数:11,代码来源:clock_test.go
示例3: TestLoggingWithLoggerCapturesOutput
func TestLoggingWithLoggerCapturesOutput(t *testing.T) {
out := new(bytes.Buffer)
log.SetOutput(out)
log.SetFlags(0)
defer log.SetOutput(os.Stdout)
defer log.SetFlags(log.LstdFlags)
thing := new(ThingUnderTest)
thing.log = Capture()
thing.Action()
assertions.New(t).So(thing.log.Log.String(), should.Equal, "Hello, World!\n")
assertions.New(t).So(out.Len(), should.Equal, 0)
}
开发者ID:smartystreets,项目名称:logging,代码行数:14,代码来源:logging_test.go
示例4: TestLoggingWithDiscard
func TestLoggingWithDiscard(t *testing.T) {
out := new(bytes.Buffer)
log.SetOutput(out)
log.SetFlags(0)
defer log.SetOutput(os.Stdout)
defer log.SetFlags(log.LstdFlags)
thing := new(ThingUnderTest)
thing.log = Discard()
thing.Action()
assertions.New(t).So(thing.log.Log.Len(), should.Equal, 0)
assertions.New(t).So(out.Len(), should.Equal, 0)
}
开发者ID:smartystreets,项目名称:logging,代码行数:14,代码来源:logging_test.go
示例5: TestParseAuthServer
func TestParseAuthServer(t *testing.T) {
a := assertions.New(t)
{
srv, err := parseAuthServer("https://user:[email protected]/")
a.So(err, assertions.ShouldBeNil)
a.So(srv.url, assertions.ShouldEqual, "https://account.thethingsnetwork.org")
a.So(srv.username, assertions.ShouldEqual, "user")
a.So(srv.password, assertions.ShouldEqual, "pass")
}
{
srv, err := parseAuthServer("https://[email protected]/")
a.So(err, assertions.ShouldBeNil)
a.So(srv.url, assertions.ShouldEqual, "https://account.thethingsnetwork.org")
a.So(srv.username, assertions.ShouldEqual, "user")
}
{
srv, err := parseAuthServer("http://account.thethingsnetwork.org/")
a.So(err, assertions.ShouldBeNil)
a.So(srv.url, assertions.ShouldEqual, "http://account.thethingsnetwork.org")
}
{
srv, err := parseAuthServer("http://localhost:9090/")
a.So(err, assertions.ShouldBeNil)
a.So(srv.url, assertions.ShouldEqual, "http://localhost:9090")
}
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:26,代码来源:auth_test.go
示例6: TestBytes
func TestBytes(t *testing.T) {
a := assertions.New(t)
a.So(FormatBytes([]byte{0x12, 0x34, 0xcd, 0xef}), assertions.ShouldEqual, "1234CDEF")
i64, err := ParseBytes("1234CDEF")
a.So(err, assertions.ShouldBeNil)
a.So(i64, assertions.ShouldResemble, []byte{0x12, 0x34, 0xcd, 0xef})
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:7,代码来源:conversions_test.go
示例7: TestUint64
func TestUint64(t *testing.T) {
a := assertions.New(t)
a.So(FormatUint64(123456), assertions.ShouldEqual, "123456")
i64, err := ParseUint64("123456")
a.So(err, assertions.ShouldBeNil)
a.So(i64, assertions.ShouldEqual, 123456)
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:7,代码来源:conversions_test.go
示例8: TestInt64
func TestInt64(t *testing.T) {
a := assertions.New(t)
a.So(FormatInt64(-123456), assertions.ShouldEqual, "-123456")
i64, err := ParseInt64("-123456")
a.So(err, assertions.ShouldBeNil)
a.So(i64, assertions.ShouldEqual, -123456)
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:7,代码来源:conversions_test.go
示例9: TestFloat64
func TestFloat64(t *testing.T) {
a := assertions.New(t)
a.So(FormatFloat64(123.456), assertions.ShouldEqual, "123.456")
f64, err := ParseFloat64("123.456")
a.So(err, assertions.ShouldBeNil)
a.So(f64, assertions.ShouldEqual, 123.456)
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:7,代码来源:conversions_test.go
示例10: TestExchangeAppKeyForToken
func TestExchangeAppKeyForToken(t *testing.T) {
for _, env := range strings.Split("ACCOUNT_SERVER_PROTO ACCOUNT_SERVER_USERNAME ACCOUNT_SERVER_PASSWORD ACCOUNT_SERVER_URL APP_ID APP_TOKEN", " ") {
if os.Getenv(env) == "" {
t.Skipf("Skipping auth server test: %s configured", env)
}
}
a := assertions.New(t)
c := new(Component)
c.Config.KeyDir = os.TempDir()
c.Config.AuthServers = map[string]string{
"ttn-account-preview": fmt.Sprintf("%s://%s:%[email protected]%s",
os.Getenv("ACCOUNT_SERVER_PROTO"),
os.Getenv("ACCOUNT_SERVER_USERNAME"),
os.Getenv("ACCOUNT_SERVER_PASSWORD"),
os.Getenv("ACCOUNT_SERVER_URL"),
),
}
c.initAuthServers()
{
token, err := c.ExchangeAppKeyForToken(os.Getenv("APP_ID"), "ttn-account-preview."+os.Getenv("APP_TOKEN"))
a.So(err, assertions.ShouldBeNil)
a.So(token, assertions.ShouldNotBeEmpty)
}
{
token, err := c.ExchangeAppKeyForToken(os.Getenv("APP_ID"), os.Getenv("APP_TOKEN"))
a.So(err, assertions.ShouldBeNil)
a.So(token, assertions.ShouldNotBeEmpty)
}
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:32,代码来源:auth_test.go
示例11: TestLogCallsAreCounted
func TestLogCallsAreCounted(t *testing.T) {
thing := new(ThingUnderTest)
thing.log = Capture()
for x := 0; x < 10; x++ {
thing.Action()
}
assertions.New(t).So(thing.log.Calls, should.Equal, 10)
}
开发者ID:smartystreets,项目名称:logging,代码行数:8,代码来源:logging_test.go
示例12: TestActualClockInstanceIsUsefulForTesting
func TestActualClockInstanceIsUsefulForTesting(t *testing.T) {
t.Parallel()
thing := new(ThingUnderTest)
now := time.Now().UTC()
thing.clock = Freeze(now)
now2 := thing.CurrentTime()
assertions.New(t).So(now, should.Resemble, now2)
}
开发者ID:smartystreets,项目名称:clock,代码行数:9,代码来源:clock_test.go
示例13: TestBool
func TestBool(t *testing.T) {
a := assertions.New(t)
a.So(FormatBool(true), assertions.ShouldEqual, "true")
b, err := ParseBool("true")
a.So(err, assertions.ShouldBeNil)
a.So(b, assertions.ShouldEqual, true)
a.So(FormatBool(false), assertions.ShouldEqual, "false")
b, err = ParseBool("false")
a.So(err, assertions.ShouldBeNil)
a.So(b, assertions.ShouldEqual, false)
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:11,代码来源:conversions_test.go
示例14: TestSimple
func TestSimple(t *testing.T) {
a := assertions.New(t)
diff, equal := Diff("hey", "there")
a.So(equal, should.BeFalse)
a.So(FormatTest(diff), should.Equal, `string: got: "there", expected: "hey"`)
diff, equal = Diff("hey", "hey")
a.So(equal, should.BeTrue)
a.So(FormatTest(diff), should.Equal, ``)
}
开发者ID:kdar,项目名称:idiff,代码行数:11,代码来源:idiff_test.go
示例15: TestLoggingWithNilReferenceProducesTraditionalBehavior
func TestLoggingWithNilReferenceProducesTraditionalBehavior(t *testing.T) {
out := new(bytes.Buffer)
log.SetOutput(out)
log.SetFlags(0)
defer log.SetOutput(os.Stdout)
defer log.SetFlags(log.LstdFlags)
thing := new(ThingUnderTest)
thing.Action()
assertions.New(t).So(out.String(), should.Equal, "Hello, World!\n")
}
开发者ID:smartystreets,项目名称:logging,代码行数:12,代码来源:logging_test.go
示例16: TestCyclicNatureOfFrozenClock
func TestCyclicNatureOfFrozenClock(t *testing.T) {
t.Parallel()
thing := new(ThingUnderTest)
now1 := time.Now()
now2 := now1.Add(time.Second)
now3 := now2.Add(time.Second)
thing.clock = Freeze(now1, now2, now3)
now1a := thing.CurrentTime()
now2a := thing.CurrentTime()
now3a := thing.CurrentTime()
assertions.New(t).So(now1, should.Resemble, now1a)
assertions.New(t).So(now2, should.Resemble, now2a)
assertions.New(t).So(now3, should.Resemble, now3a)
now1b := thing.CurrentTime()
now2b := thing.CurrentTime()
now3b := thing.CurrentTime()
assertions.New(t).So(now1, should.Resemble, now1b)
assertions.New(t).So(now2, should.Resemble, now2b)
assertions.New(t).So(now3, should.Resemble, now3b)
}
开发者ID:smartystreets,项目名称:clock,代码行数:26,代码来源:clock_test.go
示例17: TestValidateTTNAuthContext
func TestValidateTTNAuthContext(t *testing.T) {
for _, env := range strings.Split("ACCOUNT_SERVER_PROTO ACCOUNT_SERVER_URL", " ") {
if os.Getenv(env) == "" {
t.Skipf("Skipping auth server test: %s configured", env)
}
}
accountServer := fmt.Sprintf("%s://%s",
os.Getenv("ACCOUNT_SERVER_PROTO"),
os.Getenv("ACCOUNT_SERVER_URL"),
)
a := assertions.New(t)
c := new(Component)
c.Config.KeyDir = os.TempDir()
c.Config.AuthServers = map[string]string{
"ttn-account-preview": accountServer,
}
err := c.initAuthServers()
a.So(err, assertions.ShouldBeNil)
{
ctx := context.Background()
_, err = c.ValidateTTNAuthContext(ctx)
a.So(err, assertions.ShouldNotBeNil)
}
{
md := metadata.Pairs()
ctx := metadata.NewContext(context.Background(), md)
_, err = c.ValidateTTNAuthContext(ctx)
a.So(err, assertions.ShouldNotBeNil)
}
{
md := metadata.Pairs(
"id", "dev",
)
ctx := metadata.NewContext(context.Background(), md)
_, err = c.ValidateTTNAuthContext(ctx)
a.So(err, assertions.ShouldNotBeNil)
}
{
md := metadata.Pairs(
"id", "dev",
"token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJ0dG4tYWNjb3VudC1wcmV2aWV3Iiwic3ViIjoiZGV2IiwidHlwZSI6InJvdXRlciIsImlhdCI6MTQ3NjQzOTQzOH0.Duz-E5aMYEPY_Nf5Pky7Qmjbs1dMp9PN9nMqbSzoU079b8TPL4DH2SKcRHrrMqieB3yhJb3YaQBfY6dKWfgVz8BmTeKlGXfFrqEj91y30J7r9_VsHRzgDMJedlqXryvf0S_yD27TsJ7TMbGYyE00T4tAX3Uf6wQZDhdyHNGtdf4jtoAjzOxVAodNtXZp26LR7fFk56UstBxOxztBMzyzmAdiTG4lSyEqq7zsuJcFjmHB9MfEoD4ZT-iTRL1ohFjGuj2HN49oPyYlZAVPP7QajLyNsLnv-nDqXE_QecOjAcEq4PLNJ3DpXtX-lo8I_F1eV9yQnDdQQi4EUvxmxZWeBA",
)
ctx := metadata.NewContext(context.Background(), md)
_, err = c.ValidateTTNAuthContext(ctx)
a.So(err, assertions.ShouldBeNil)
}
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:52,代码来源:auth_test.go
示例18: TestAccessKeysRights
func TestAccessKeysRights(t *testing.T) {
a := s.New(t)
c := AccessKey{
Name: "name",
Key: "123456",
Rights: []Right{
Right("right"),
},
}
a.So(c.HasRight(Right("right")), s.ShouldBeTrue)
a.So(c.HasRight(Right("foo")), s.ShouldBeFalse)
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:13,代码来源:access_keys_test.go
示例19: TestInitAuthServers
func TestInitAuthServers(t *testing.T) {
for _, env := range strings.Split("ACCOUNT_SERVER_PROTO ACCOUNT_SERVER_USERNAME ACCOUNT_SERVER_PASSWORD ACCOUNT_SERVER_URL", " ") {
if os.Getenv(env) == "" {
t.Skipf("Skipping auth server test: %s configured", env)
}
}
a := assertions.New(t)
c := new(Component)
c.Config.KeyDir = os.TempDir()
c.Ctx = GetLogger(t, "TestInitAuthServers")
c.Config.AuthServers = map[string]string{
"ttn": fmt.Sprintf("%s://%s",
os.Getenv("ACCOUNT_SERVER_PROTO"),
os.Getenv("ACCOUNT_SERVER_URL"),
),
"ttn-user": fmt.Sprintf("%s://%[email protected]%s",
os.Getenv("ACCOUNT_SERVER_PROTO"),
os.Getenv("ACCOUNT_SERVER_USERNAME"),
os.Getenv("ACCOUNT_SERVER_URL"),
),
"ttn-user-pass": fmt.Sprintf("%s://%s:%[email protected]%s",
os.Getenv("ACCOUNT_SERVER_PROTO"),
os.Getenv("ACCOUNT_SERVER_USERNAME"),
os.Getenv("ACCOUNT_SERVER_PASSWORD"),
os.Getenv("ACCOUNT_SERVER_URL"),
),
}
err := c.initAuthServers()
a.So(err, assertions.ShouldBeNil)
{
k, err := c.TokenKeyProvider.Get("ttn", true)
a.So(err, assertions.ShouldBeNil)
a.So(k.Algorithm, assertions.ShouldEqual, "RS256")
}
{
k, err := c.TokenKeyProvider.Get("ttn-user", true)
a.So(err, assertions.ShouldBeNil)
a.So(k.Algorithm, assertions.ShouldEqual, "RS256")
}
{
k, err := c.TokenKeyProvider.Get("ttn-user-pass", true)
a.So(err, assertions.ShouldBeNil)
a.So(k.Algorithm, assertions.ShouldEqual, "RS256")
}
a.So(c.UpdateTokenKey(), assertions.ShouldBeNil)
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:51,代码来源:auth_test.go
示例20: TestInit
func TestInit(t *testing.T) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
tmpDir := fmt.Sprintf("%s/%d", os.TempDir(), r.Int63())
os.Mkdir(tmpDir, 755)
defer os.Remove(tmpDir)
a := assertions.New(t)
c := new(Component)
c.Identity = new(discovery.Announcement)
c.Config.KeyDir = tmpDir
security.GenerateKeypair(tmpDir)
a.So(c.InitAuth(), assertions.ShouldBeNil)
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:15,代码来源:auth_test.go
注:本文中的github.com/smartystreets/assertions.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论