本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/platform/fakes.FakePlatform.SetGetFilesContentsFromDisk方法的典型用法代码示例。如果您正苦于以下问题:Golang FakePlatform.SetGetFilesContentsFromDisk方法的具体用法?Golang FakePlatform.SetGetFilesContentsFromDisk怎么用?Golang FakePlatform.SetGetFilesContentsFromDisk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry/bosh-agent/platform/fakes.FakePlatform
的用法示例。
在下文中一共展示了FakePlatform.SetGetFilesContentsFromDisk方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
platform *fakeplatform.FakePlatform
source *ConfigDriveSettingsSource
)
BeforeEach(func() {
diskPaths := []string{"/fake-disk-path-1", "/fake-disk-path-2"}
metadataPath := "fake-metadata-path"
settingsPath := "fake-settings-path"
platform = fakeplatform.NewFakePlatform()
logger := boshlog.NewLogger(boshlog.LevelNone)
source = NewConfigDriveSettingsSource(diskPaths, metadataPath, settingsPath, platform, logger)
})
BeforeEach(func() {
// Set up default settings and metadata
platform.SetGetFilesContentsFromDisk("/fake-disk-path-1/fake-metadata-path", []byte(`{}`), nil)
platform.SetGetFilesContentsFromDisk("/fake-disk-path-1/fake-settings-path", []byte(`{}`), nil)
})
Describe("PublicSSHKeyForUsername", func() {
Context("when metadata contains a public SSH key", func() {
metadata := MetadataContentsType{
PublicKeys: map[string]PublicKeyType{
"0": PublicKeyType{
"openssh-key": "fake-openssh-key",
},
},
}
It("returns public key from the config drive", func() {
metadataBytes, err := json.Marshal(metadata)
示例2: describeConfigDriveMetadataService
func describeConfigDriveMetadataService() {
var (
metadataService MetadataService
resolver *fakeinf.FakeDNSResolver
platform *fakeplatform.FakePlatform
logger boshlog.Logger
)
updateMetadata := func(metadataContents MetadataContentsType) {
metadataJSON, err := json.Marshal(metadataContents)
Expect(err).ToNot(HaveOccurred())
platform.SetGetFilesContentsFromDisk("/fake-disk-path-1/fake-metadata-path", metadataJSON, nil)
Expect(metadataService.IsAvailable()).To(BeTrue())
}
updateUserdata := func(userdataContents string) {
platform.SetGetFilesContentsFromDisk("/fake-disk-path-1/fake-userdata-path", []byte(userdataContents), nil)
Expect(metadataService.IsAvailable()).To(BeTrue())
}
BeforeEach(func() {
resolver = &fakeinf.FakeDNSResolver{}
platform = fakeplatform.NewFakePlatform()
logger = boshlog.NewLogger(boshlog.LevelNone)
diskPaths := []string{
"/fake-disk-path-1",
"/fake-disk-path-2",
}
metadataService = NewConfigDriveMetadataService(
resolver,
platform,
diskPaths,
"fake-metadata-path",
"fake-userdata-path",
logger,
)
userdataContents := fmt.Sprintf(`{"server":{"name":"fake-server-name"},"registry":{"endpoint":"fake-registry-endpoint"}}`)
platform.SetGetFilesContentsFromDisk("/fake-disk-path-1/fake-userdata-path", []byte(userdataContents), nil)
metadata := MetadataContentsType{
PublicKeys: map[string]PublicKeyType{
"0": PublicKeyType{
"openssh-key": "fake-openssh-key",
},
},
InstanceID: "fake-instance-id",
}
updateMetadata(metadata)
})
Describe("GetNetworks", func() {
It("returns the network settings", func() {
userdataContents := `
{
"networks": {
"network_1": {"type": "manual", "ip": "1.2.3.4", "netmask": "2.3.4.5", "gateway": "3.4.5.6", "default": ["dns"], "dns": ["8.8.8.8"], "mac": "fake-mac-address-1"},
"network_2": {"type": "dynamic", "default": ["dns"], "dns": ["8.8.8.8"], "mac": "fake-mac-address-2"}
}
}`
updateUserdata(userdataContents)
networks, err := metadataService.GetNetworks()
Expect(err).ToNot(HaveOccurred())
Expect(networks).To(Equal(boshsettings.Networks{
"network_1": boshsettings.Network{
Type: "manual",
IP: "1.2.3.4",
Netmask: "2.3.4.5",
Gateway: "3.4.5.6",
Default: []string{"dns"},
DNS: []string{"8.8.8.8"},
Mac: "fake-mac-address-1",
},
"network_2": boshsettings.Network{
Type: "dynamic",
Default: []string{"dns"},
DNS: []string{"8.8.8.8"},
Mac: "fake-mac-address-2",
},
}))
})
It("returns a nil Networks if the settings are missing (from an old CPI version)", func() {
userdataContents := `{}`
updateUserdata(userdataContents)
networks, err := metadataService.GetNetworks()
Expect(err).ToNot(HaveOccurred())
Expect(networks).To(BeNil())
})
})
Describe("IsAvailable", func() {
It("return true when it can load successfully", func() {
Expect(metadataService.IsAvailable()).To(BeTrue())
})
//.........这里部分代码省略.........