本文整理匯總了Golang中bosh/assert.MatchesJsonMap函數的典型用法代碼示例。如果您正苦於以下問題:Golang MatchesJsonMap函數的具體用法?Golang MatchesJsonMap怎麽用?Golang MatchesJsonMap使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了MatchesJsonMap函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestGetStateRunWithFullFormatOption
func TestGetStateRunWithFullFormatOption(t *testing.T) {
settings := &fakesettings.FakeSettingsService{}
settings.AgentId = "my-agent-id"
settings.Vm.Name = "vm-abc-def"
specService, jobSupervisor, fakeVitals, action := buildGetStateAction(settings)
jobSupervisor.StatusStatus = "running"
specService.Spec = boshas.V1ApplySpec{
Deployment: "fake-deployment",
}
expectedVitals := boshvitals.Vitals{
Load: []string{"foo", "bar", "baz"},
}
fakeVitals.GetVitals = expectedVitals
expectedVm := map[string]interface{}{"name": "vm-abc-def"}
state, err := action.Run("full")
assert.NoError(t, err)
boshassert.MatchesJsonString(t, state.AgentId, `"my-agent-id"`)
boshassert.MatchesJsonString(t, state.JobState, `"running"`)
boshassert.MatchesJsonString(t, state.Deployment, `"fake-deployment"`)
assert.Equal(t, *state.Vitals, expectedVitals)
boshassert.MatchesJsonMap(t, state.Vm, expectedVm)
}
示例2: TestCompilePackageCompilesThePackageAbdReturnsBlobId
func TestCompilePackageCompilesThePackageAbdReturnsBlobId(t *testing.T) {
compiler, action := buildCompilePackageAction()
compiler.CompileBlobId = "my-blob-id"
compiler.CompileSha1 = "some sha1"
blobId, sha1, name, version, deps := getCompileActionArguments()
expectedPkg := boshcomp.Package{
BlobstoreId: blobId,
Sha1: sha1,
Name: name,
Version: version,
}
expectedJson := map[string]interface{}{
"result": map[string]string{
"blobstore_id": "my-blob-id",
"sha1": "some sha1",
},
}
val, err := action.Run(blobId, sha1, name, version, deps)
assert.NoError(t, err)
assert.Equal(t, expectedPkg, compiler.CompilePkg)
assert.Equal(t, deps, compiler.CompileDeps)
boshassert.MatchesJsonMap(t, val, expectedJson)
}
示例3: TestGetStateRunWithoutCurrentSpec
func TestGetStateRunWithoutCurrentSpec(t *testing.T) {
settings := &fakesettings.FakeSettingsService{}
settings.AgentId = "my-agent-id"
settings.Vm.Name = "vm-abc-def"
specService, jobSupervisor, _, action := buildGetStateAction(settings)
jobSupervisor.StatusStatus = "running"
specService.GetErr = errors.New("some error")
specService.Spec = boshas.V1ApplySpec{
Deployment: "fake-deployment",
}
expectedSpec := getStateV1ApplySpec{
AgentId: "my-agent-id",
JobState: "running",
BoshProtocol: "1",
Vm: boshsettings.Vm{Name: "vm-abc-def"},
Ntp: boshntp.NTPInfo{
Offset: "0.34958",
Timestamp: "12 Oct 17:37:58",
},
}
state, err := action.Run()
assert.NoError(t, err)
boshassert.MatchesJsonMap(t, expectedSpec.Ntp, map[string]interface{}{
"offset": "0.34958",
"timestamp": "12 Oct 17:37:58",
})
assert.Equal(t, state, expectedSpec)
}
示例4: testSshSetupWithGivenPassword
func testSshSetupWithGivenPassword(t assert.TestingT, expectedPwd string) {
settings := &fakesettings.FakeSettingsService{}
settings.DefaultIp = "ww.xx.yy.zz"
platform, action := buildSshAction(settings)
expectedUser := "some-user"
expectedKey := "some public key content"
params := SshParams{
User: expectedUser,
PublicKey: expectedKey,
Password: expectedPwd,
}
response, err := action.Run("setup", params)
assert.NoError(t, err)
assert.Equal(t, expectedUser, platform.CreateUserUsername)
assert.Equal(t, expectedPwd, platform.CreateUserPassword)
assert.Equal(t, "/foo/bosh_ssh", platform.CreateUserBasePath)
assert.Equal(t, []string{boshsettings.VCAP_USERNAME, boshsettings.ADMIN_GROUP}, platform.AddUserToGroupsGroups[expectedUser])
assert.Equal(t, expectedKey, platform.SetupSshPublicKeys[expectedUser])
expectedJson := map[string]interface{}{
"command": "setup",
"status": "success",
"ip": "ww.xx.yy.zz",
}
boshassert.MatchesJsonMap(t, response, expectedJson)
}
示例5: init
func init() {
Describe("Testing with Ginkgo", func() {
It("ssh should be synchronous", func() {
settings := &fakesettings.FakeSettingsService{}
_, action := buildSshAction(settings)
Expect(action.IsAsynchronous()).To(BeFalse())
})
It("is not persistent", func() {
settings := &fakesettings.FakeSettingsService{}
_, action := buildSshAction(settings)
Expect(action.IsPersistent()).To(BeFalse())
})
It("ssh setup without default ip", func() {
settings := &fakesettings.FakeSettingsService{}
_, action := buildSshAction(settings)
params := SshParams{
User: "some-user",
Password: "some-pwd",
PublicKey: "some-key",
}
_, err := action.Run("setup", params)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("No default ip"))
})
It("ssh setup with username and password", func() {
testSshSetupWithGivenPassword(GinkgoT(), "some-password")
})
It("ssh setup without password", func() {
testSshSetupWithGivenPassword(GinkgoT(), "")
})
It("ssh run cleanup deletes ephemeral user", func() {
settings := &fakesettings.FakeSettingsService{}
platform, action := buildSshAction(settings)
params := SshParams{UserRegex: "^foobar.*"}
response, err := action.Run("cleanup", params)
Expect(err).ToNot(HaveOccurred())
Expect("^foobar.*").To(Equal(platform.DeleteEphemeralUsersMatchingRegex))
boshassert.MatchesJsonMap(GinkgoT(), response, map[string]interface{}{
"command": "cleanup",
"status": "success",
})
})
})
}
示例6: TestSshRunCleanupDeletesEphemeralUser
func TestSshRunCleanupDeletesEphemeralUser(t *testing.T) {
platform, action := buildSshActionCleanup()
payload := `{"arguments":["cleanup",{"user_regex":"^foobar.*"}]}`
response, err := action.Run([]byte(payload))
assert.NoError(t, err)
assert.Equal(t, "^foobar.*", platform.DeleteEphemeralUsersMatchingRegex)
boshassert.MatchesJsonMap(t, response, map[string]interface{}{
"command": "cleanup",
"status": "success",
})
}
示例7: TestSshRunCleanupDeletesEphemeralUser
func TestSshRunCleanupDeletesEphemeralUser(t *testing.T) {
settings := &fakesettings.FakeSettingsService{}
platform, action := buildSshAction(settings)
params := sshParams{UserRegex: "^foobar.*"}
response, err := action.Run("cleanup", params)
assert.NoError(t, err)
assert.Equal(t, "^foobar.*", platform.DeleteEphemeralUsersMatchingRegex)
boshassert.MatchesJsonMap(t, response, map[string]interface{}{
"command": "cleanup",
"status": "success",
})
}
示例8: testSshSetupWithGivenPassword
func testSshSetupWithGivenPassword(t *testing.T, expectedPwd string) {
settings, platform, blobstore, taskService := getFakeFactoryDependencies()
settings.Networks = map[string]boshsettings.NetworkSettings{
"default": {Ip: "ww.xx.yy.zz"},
}
factory := NewFactory(settings, platform, blobstore, taskService)
sshAction := factory.Create("ssh")
expectedUser := "some-user"
expectedKey := "some public key content"
payload := fmt.Sprintf(
`{"arguments":["setup",{"user":"%s","password":"%s","public_key":"%s"}]}`,
expectedUser, expectedPwd, expectedKey,
)
if expectedPwd == "" {
payload = fmt.Sprintf(
`{"arguments":["setup",{"user":"%s","public_key":"%s"}]}`,
expectedUser, expectedKey,
)
}
boshSshPath := "/var/vcap/bosh_ssh"
response, err := sshAction.Run([]byte(payload))
assert.NoError(t, err)
// assert on user and ssh setup
assert.Equal(t, expectedUser, platform.CreateUserUsername)
assert.Equal(t, expectedPwd, platform.CreateUserPassword)
assert.Equal(t, boshSshPath, platform.CreateUserBasePath)
assert.Equal(t, []string{boshsettings.VCAP_USERNAME, boshsettings.ADMIN_GROUP}, platform.AddUserToGroupsGroups[expectedUser])
assert.Equal(t, expectedKey, platform.SetupSshPublicKeys[expectedUser])
expectedJson := map[string]interface{}{
"command": "setup",
"status": "success",
"ip": "ww.xx.yy.zz",
}
boshassert.MatchesJsonMap(t, response, expectedJson)
}
示例9: testSshSetupWithGivenPassword
func testSshSetupWithGivenPassword(t *testing.T, expectedPwd string) {
settings := &fakesettings.FakeSettingsService{}
settings.DefaultIp = "ww.xx.yy.zz"
platform, action := buildSshActionSetup(settings)
expectedUser := "some-user"
expectedKey := "some public key content"
payload := fmt.Sprintf(
`{"arguments":["setup",{"user":"%s","password":"%s","public_key":"%s"}]}`,
expectedUser, expectedPwd, expectedKey,
)
if expectedPwd == "" {
payload = fmt.Sprintf(
`{"arguments":["setup",{"user":"%s","public_key":"%s"}]}`,
expectedUser, expectedKey,
)
}
boshSshPath := "/var/vcap/bosh_ssh"
response, err := action.Run([]byte(payload))
assert.NoError(t, err)
// assert on user and ssh setup
assert.Equal(t, expectedUser, platform.CreateUserUsername)
assert.Equal(t, expectedPwd, platform.CreateUserPassword)
assert.Equal(t, boshSshPath, platform.CreateUserBasePath)
assert.Equal(t, []string{boshsettings.VCAP_USERNAME, boshsettings.ADMIN_GROUP}, platform.AddUserToGroupsGroups[expectedUser])
assert.Equal(t, expectedKey, platform.SetupSshPublicKeys[expectedUser])
expectedJson := map[string]interface{}{
"command": "setup",
"status": "success",
"ip": "ww.xx.yy.zz",
}
boshassert.MatchesJsonMap(t, response, expectedJson)
}
示例10: TestGetStateRun
func TestGetStateRun(t *testing.T) {
settings := &fakesettings.FakeSettingsService{}
settings.AgentId = "my-agent-id"
settings.Vm.Name = "vm-abc-def"
fs, action := buildGetStateAction(settings)
fs.WriteToFile(boshsettings.VCAP_BASE_DIR+"/bosh/spec.json", `{"key":"value"}`)
expectedJson := map[string]interface{}{
"agent_id": "my-agent-id",
"job_state": "unknown",
"bosh_protocol": "1",
"key": "value",
"vm": map[string]string{"name": "vm-abc-def"},
}
state, err := action.Run([]byte(`{"arguments":[]}`))
assert.NoError(t, err)
boshassert.MatchesJsonMap(t, state, expectedJson)
}
示例11: TestSshCleanup
func TestSshCleanup(t *testing.T) {
settings, fs, platform, taskService := getFakeFactoryDependencies()
factory := NewFactory(settings, fs, platform, taskService)
sshAction := factory.Create("ssh")
payload := `{"arguments":["cleanup",{"user_regex":"^foobar.*"}]}`
response, err := sshAction.Run([]byte(payload))
assert.NoError(t, err)
// assert on platform interaction
assert.Equal(t, "^foobar.*", platform.DeleteEphemeralUsersMatchingRegex)
// assert on the response
expectedJson := map[string]interface{}{
"command": "cleanup",
"status": "success",
}
boshassert.MatchesJsonMap(t, response, expectedJson)
}
示例12: TestVitalsConstruction
func TestVitalsConstruction(t *testing.T) {
_, service := buildVitalsService()
vitals, err := service.Get()
expectedVitals := map[string]interface{}{
"cpu": map[string]string{
"sys": "10.0",
"user": "56.0",
"wait": "1.0",
},
"disk": map[string]interface{}{
"system": map[string]string{
"percent": "50",
"inode_percent": "10",
},
"ephemeral": map[string]string{
"percent": "75",
"inode_percent": "20",
},
"persistent": map[string]string{
"percent": "100",
"inode_percent": "75",
},
},
"load": []string{"0.20", "4.55", "1.12"},
"mem": map[string]string{
"kb": "700",
"percent": "70",
},
"swap": map[string]string{
"kb": "600",
"percent": "60",
},
}
assert.NoError(t, err)
boshassert.MatchesJsonMap(t, vitals, expectedVitals)
}
示例13: TestGetState
func TestGetState(t *testing.T) {
settings, platform, blobstore, taskService := getFakeFactoryDependencies()
platform.Fs.WriteToFile(boshsettings.VCAP_BASE_DIR+"/bosh/spec.json", `{"key":"value"}`)
settings.AgentId = "my-agent-id"
settings.Vm.Name = "vm-abc-def"
factory := NewFactory(settings, platform, blobstore, taskService)
getStateAction := factory.Create("get_state")
state, err := getStateAction.Run([]byte(`{"arguments":[]}`))
assert.NoError(t, err)
expectedJson := map[string]interface{}{
"agent_id": "my-agent-id",
"job_state": "unknown",
"bosh_protocol": "1",
"key": "value",
"vm": map[string]string{"name": "vm-abc-def"},
}
boshassert.MatchesJsonMap(t, state, expectedJson)
}
示例14: init
func init() {
Describe("Testing with Ginkgo", func() {
It("get state should be synchronous", func() {
settings := &fakesettings.FakeSettingsService{}
_, _, _, action := buildGetStateAction(settings)
assert.False(GinkgoT(), action.IsAsynchronous())
})
It("get state run", func() {
settings := &fakesettings.FakeSettingsService{}
settings.AgentId = "my-agent-id"
settings.Vm.Name = "vm-abc-def"
specService, jobSupervisor, _, action := buildGetStateAction(settings)
jobSupervisor.StatusStatus = "running"
specService.Spec = boshas.V1ApplySpec{
Deployment: "fake-deployment",
}
expectedSpec := GetStateV1ApplySpec{
AgentId: "my-agent-id",
JobState: "running",
BoshProtocol: "1",
Vm: boshsettings.Vm{Name: "vm-abc-def"},
Ntp: boshntp.NTPInfo{
Offset: "0.34958",
Timestamp: "12 Oct 17:37:58",
},
}
expectedSpec.Deployment = "fake-deployment"
state, err := action.Run()
assert.NoError(GinkgoT(), err)
assert.Equal(GinkgoT(), state.AgentId, expectedSpec.AgentId)
assert.Equal(GinkgoT(), state.JobState, expectedSpec.JobState)
assert.Equal(GinkgoT(), state.Deployment, expectedSpec.Deployment)
boshassert.LacksJsonKey(GinkgoT(), state, "vitals")
assert.Equal(GinkgoT(), state, expectedSpec)
})
It("get state run without current spec", func() {
settings := &fakesettings.FakeSettingsService{}
settings.AgentId = "my-agent-id"
settings.Vm.Name = "vm-abc-def"
specService, jobSupervisor, _, action := buildGetStateAction(settings)
jobSupervisor.StatusStatus = "running"
specService.GetErr = errors.New("some error")
specService.Spec = boshas.V1ApplySpec{
Deployment: "fake-deployment",
}
expectedSpec := GetStateV1ApplySpec{
AgentId: "my-agent-id",
JobState: "running",
BoshProtocol: "1",
Vm: boshsettings.Vm{Name: "vm-abc-def"},
Ntp: boshntp.NTPInfo{
Offset: "0.34958",
Timestamp: "12 Oct 17:37:58",
},
}
state, err := action.Run()
assert.NoError(GinkgoT(), err)
boshassert.MatchesJsonMap(GinkgoT(), expectedSpec.Ntp, map[string]interface{}{
"offset": "0.34958",
"timestamp": "12 Oct 17:37:58",
})
assert.Equal(GinkgoT(), state, expectedSpec)
})
It("get state run with full format option", func() {
settings := &fakesettings.FakeSettingsService{}
settings.AgentId = "my-agent-id"
settings.Vm.Name = "vm-abc-def"
specService, jobSupervisor, fakeVitals, action := buildGetStateAction(settings)
jobSupervisor.StatusStatus = "running"
specService.Spec = boshas.V1ApplySpec{
Deployment: "fake-deployment",
}
expectedVitals := boshvitals.Vitals{
Load: []string{"foo", "bar", "baz"},
}
fakeVitals.GetVitals = expectedVitals
expectedVm := map[string]interface{}{"name": "vm-abc-def"}
state, err := action.Run("full")
assert.NoError(GinkgoT(), err)
boshassert.MatchesJsonString(GinkgoT(), state.AgentId, `"my-agent-id"`)
boshassert.MatchesJsonString(GinkgoT(), state.JobState, `"running"`)
boshassert.MatchesJsonString(GinkgoT(), state.Deployment, `"fake-deployment"`)
//.........這裏部分代碼省略.........
示例15: init
func init() {
Describe("Testing with Ginkgo", func() {
It("compile package should be asynchronous", func() {
_, action := buildCompilePackageAction()
Expect(action.IsAsynchronous()).To(BeTrue())
})
It("is not persistent", func() {
_, action := buildCompilePackageAction()
Expect(action.IsPersistent()).To(BeFalse())
})
It("compile package compiles the package abd returns blob id", func() {
compiler, action := buildCompilePackageAction()
compiler.CompileBlobId = "my-blob-id"
compiler.CompileSha1 = "some sha1"
blobId, sha1, name, version, deps := getCompileActionArguments()
expectedPkg := boshcomp.Package{
BlobstoreId: blobId,
Sha1: sha1,
Name: name,
Version: version,
}
expectedJson := map[string]interface{}{
"result": map[string]string{
"blobstore_id": "my-blob-id",
"sha1": "some sha1",
},
}
expectedDeps := []boshmodels.Package{
{
Name: "first_dep",
Version: "first_dep_version",
Source: boshmodels.Source{
Sha1: "first_dep_sha1",
BlobstoreId: "first_dep_blobstore_id",
},
},
{
Name: "sec_dep",
Version: "sec_dep_version",
Source: boshmodels.Source{
Sha1: "sec_dep_sha1",
BlobstoreId: "sec_dep_blobstore_id",
},
},
}
val, err := action.Run(blobId, sha1, name, version, deps)
Expect(err).ToNot(HaveOccurred())
Expect(expectedPkg).To(Equal(compiler.CompilePkg))
Expect(expectedDeps).To(Equal(compiler.CompileDeps))
boshassert.MatchesJsonMap(GinkgoT(), val, expectedJson)
})
It("compile package errs when compile fails", func() {
compiler, action := buildCompilePackageAction()
compiler.CompileErr = errors.New("Oops")
blobId, sha1, name, version, deps := getCompileActionArguments()
_, err := action.Run(blobId, sha1, name, version, deps)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring(compiler.CompileErr.Error()))
})
})
}