當前位置: 首頁>>代碼示例>>Golang>>正文


Golang assert.Equal函數代碼示例

本文整理匯總了Golang中github.com/moul/advanced-ssh-config/vendor/github.com/stretchr/testify/assert.Equal函數的典型用法代碼示例。如果您正苦於以下問題:Golang Equal函數的具體用法?Golang Equal怎麽用?Golang Equal使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Equal函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestConfig

func TestConfig(t *testing.T) {
	config := dummyConfig()

	assert.Equal(t, len(config.Hosts), 2)
	assert.Equal(t, config.Hosts["toto"].Host, "1.2.3.4")
	assert.Equal(t, config.Defaults.Port, uint(22))
}
開發者ID:moul,項目名稱:advanced-ssh-config-go,代碼行數:7,代碼來源:config_test.go

示例2: TestWithFieldsShouldAllowAssignments

func TestWithFieldsShouldAllowAssignments(t *testing.T) {
	var buffer bytes.Buffer
	var fields Fields

	logger := New()
	logger.Out = &buffer
	logger.Formatter = new(JSONFormatter)

	localLog := logger.WithFields(Fields{
		"key1": "value1",
	})

	localLog.WithField("key2", "value2").Info("test")
	err := json.Unmarshal(buffer.Bytes(), &fields)
	assert.Nil(t, err)

	assert.Equal(t, "value2", fields["key2"])
	assert.Equal(t, "value1", fields["key1"])

	buffer = bytes.Buffer{}
	fields = Fields{}
	localLog.Info("test")
	err = json.Unmarshal(buffer.Bytes(), &fields)
	assert.Nil(t, err)

	_, ok := fields["key2"]
	assert.Equal(t, false, ok)
	assert.Equal(t, "value1", fields["key1"])
}
開發者ID:Trozz,項目名稱:advanced-ssh-config,代碼行數:29,代碼來源:logrus_test.go

示例3: TestUserSuppliedMsgFieldHasPrefix

func TestUserSuppliedMsgFieldHasPrefix(t *testing.T) {
	LogAndAssertJSON(t, func(log *Logger) {
		log.WithField("msg", "hello").Info("test")
	}, func(fields Fields) {
		assert.Equal(t, fields["msg"], "test")
		assert.Equal(t, fields["fields.msg"], "hello")
	})
}
開發者ID:Trozz,項目名稱:advanced-ssh-config,代碼行數:8,代碼來源:logrus_test.go

示例4: TestUserSuppliedLevelFieldHasPrefix

func TestUserSuppliedLevelFieldHasPrefix(t *testing.T) {
	LogAndAssertJSON(t, func(log *Logger) {
		log.WithField("level", 1).Info("test")
	}, func(fields Fields) {
		assert.Equal(t, fields["level"], "info")
		assert.Equal(t, fields["fields.level"], 1.0) // JSON has floats only
	})
}
開發者ID:Trozz,項目名稱:advanced-ssh-config,代碼行數:8,代碼來源:logrus_test.go

示例5: TestInfo

func TestInfo(t *testing.T) {
	LogAndAssertJSON(t, func(log *Logger) {
		log.Info("test")
	}, func(fields Fields) {
		assert.Equal(t, fields["msg"], "test")
		assert.Equal(t, fields["level"], "info")
	})
}
開發者ID:Trozz,項目名稱:advanced-ssh-config,代碼行數:8,代碼來源:logrus_test.go

示例6: TestWarn

func TestWarn(t *testing.T) {
	LogAndAssertJSON(t, func(log *Logger) {
		log.Warn("test")
	}, func(fields Fields) {
		assert.Equal(t, fields["msg"], "test")
		assert.Equal(t, fields["level"], "warning")
	})
}
開發者ID:Trozz,項目名稱:advanced-ssh-config,代碼行數:8,代碼來源:logrus_test.go

示例7: TestNew

func TestNew(t *testing.T) {
	config := New()

	assert.Equal(t, len(config.Hosts), 0)
	assert.Equal(t, config.Defaults.Port, uint(0))
	assert.Equal(t, config.Defaults.Host, "")
	assert.Equal(t, config.Defaults.User, "")
}
開發者ID:moul,項目名稱:advanced-ssh-config-go,代碼行數:8,代碼來源:config_test.go

示例8: TestHookFires

func TestHookFires(t *testing.T) {
	hook := new(TestHook)

	LogAndAssertJSON(t, func(log *Logger) {
		log.Hooks.Add(hook)
		assert.Equal(t, hook.Fired, false)

		log.Print("test")
	}, func(fields Fields) {
		assert.Equal(t, hook.Fired, true)
	})
}
開發者ID:Trozz,項目名稱:advanced-ssh-config,代碼行數:12,代碼來源:hook_test.go

示例9: TestCanFireMultipleHooks

func TestCanFireMultipleHooks(t *testing.T) {
	hook1 := new(ModifyHook)
	hook2 := new(TestHook)

	LogAndAssertJSON(t, func(log *Logger) {
		log.Hooks.Add(hook1)
		log.Hooks.Add(hook2)

		log.WithField("wow", "elephant").Print("test")
	}, func(fields Fields) {
		assert.Equal(t, fields["wow"], "whale")
		assert.Equal(t, hook2.Fired, true)
	})
}
開發者ID:Trozz,項目名稱:advanced-ssh-config,代碼行數:14,代碼來源:hook_test.go

示例10: TestParseLevel

func TestParseLevel(t *testing.T) {
	l, err := ParseLevel("panic")
	assert.Nil(t, err)
	assert.Equal(t, PanicLevel, l)

	l, err = ParseLevel("fatal")
	assert.Nil(t, err)
	assert.Equal(t, FatalLevel, l)

	l, err = ParseLevel("error")
	assert.Nil(t, err)
	assert.Equal(t, ErrorLevel, l)

	l, err = ParseLevel("warn")
	assert.Nil(t, err)
	assert.Equal(t, WarnLevel, l)

	l, err = ParseLevel("warning")
	assert.Nil(t, err)
	assert.Equal(t, WarnLevel, l)

	l, err = ParseLevel("info")
	assert.Nil(t, err)
	assert.Equal(t, InfoLevel, l)

	l, err = ParseLevel("debug")
	assert.Nil(t, err)
	assert.Equal(t, DebugLevel, l)

	l, err = ParseLevel("invalid")
	assert.Equal(t, "not a valid logrus Level: \"invalid\"", err.Error())
}
開發者ID:Trozz,項目名稱:advanced-ssh-config,代碼行數:32,代碼來源:logrus_test.go

示例11: TestInfoShouldAddSpacesBetweenTwoNonStrings

func TestInfoShouldAddSpacesBetweenTwoNonStrings(t *testing.T) {
	LogAndAssertJSON(t, func(log *Logger) {
		log.Infoln(10, 10)
	}, func(fields Fields) {
		assert.Equal(t, fields["msg"], "10 10")
	})
}
開發者ID:Trozz,項目名稱:advanced-ssh-config,代碼行數:7,代碼來源:logrus_test.go

示例12: TestInfolnShouldAddSpacesBetweenStringAndNonstring

func TestInfolnShouldAddSpacesBetweenStringAndNonstring(t *testing.T) {
	LogAndAssertJSON(t, func(log *Logger) {
		log.Infoln("test", 10)
	}, func(fields Fields) {
		assert.Equal(t, fields["msg"], "test 10")
	})
}
開發者ID:Trozz,項目名稱:advanced-ssh-config,代碼行數:7,代碼來源:logrus_test.go

示例13: TestInfoShouldNotAddSpacesBetweenStrings

func TestInfoShouldNotAddSpacesBetweenStrings(t *testing.T) {
	LogAndAssertJSON(t, func(log *Logger) {
		log.Info("test", "test")
	}, func(fields Fields) {
		assert.Equal(t, fields["msg"], "testtest")
	})
}
開發者ID:Trozz,項目名稱:advanced-ssh-config,代碼行數:7,代碼來源:logrus_test.go

示例14: TestUserSuppliedFieldDoesNotOverwriteDefaults

func TestUserSuppliedFieldDoesNotOverwriteDefaults(t *testing.T) {
	LogAndAssertJSON(t, func(log *Logger) {
		log.WithField("msg", "hello").Info("test")
	}, func(fields Fields) {
		assert.Equal(t, fields["msg"], "test")
	})
}
開發者ID:Trozz,項目名稱:advanced-ssh-config,代碼行數:7,代碼來源:logrus_test.go

示例15: TestHostApplyDefaults_empty

func TestHostApplyDefaults_empty(t *testing.T) {
	host := &Host{}
	defaults := &Host{}
	host.ApplyDefaults(defaults)
	assert.Equal(t, host.Port, uint(22))
	assert.Equal(t, host.Name, "")
	assert.Equal(t, host.Host, "")
	assert.Equal(t, host.User, "")
	assert.Equal(t, len(host.Gateways), 0)
	assert.Equal(t, host.ProxyCommand, "")
	assert.Equal(t, len(host.ResolveNameservers), 0)
	assert.Equal(t, host.ResolveCommand, "")
	assert.Equal(t, host.ControlPath, "")
}
開發者ID:moul,項目名稱:advanced-ssh-config-go,代碼行數:14,代碼來源:host_test.go


注:本文中的github.com/moul/advanced-ssh-config/vendor/github.com/stretchr/testify/assert.Equal函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。