chore: add test for MetadataFiles option
Signed-off-by: Pratyush singhal <psinghal20@gmail.com>
This commit is contained in:
parent
99a3e9cf0a
commit
4a369b4ef1
@ -431,7 +431,8 @@ func testConfig(t *testing.T) (config map[string]interface{}, tempAccountFile st
|
||||
"image_licenses": []string{
|
||||
"test-license",
|
||||
},
|
||||
"zone": "us-east1-a",
|
||||
"metadata_files": map[string]string{},
|
||||
"zone": "us-east1-a",
|
||||
}
|
||||
|
||||
return config, tempAccountFile
|
||||
@ -484,6 +485,21 @@ func testAccountFile(t *testing.T) string {
|
||||
return tf.Name()
|
||||
}
|
||||
|
||||
const testMetadataFileContent = `testMetadata`
|
||||
|
||||
func testMetadataFile(t *testing.T) string {
|
||||
tf, err := ioutil.TempFile("", "packer")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
defer tf.Close()
|
||||
if _, err := tf.Write([]byte(testMetadataFileContent)); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
return tf.Name()
|
||||
}
|
||||
|
||||
// This is just some dummy data that doesn't actually work (it was revoked
|
||||
// a long time ago).
|
||||
const testAccountContent = `{}`
|
||||
|
@ -325,3 +325,20 @@ func TestCreateInstanceMetadata_noPublicKey(t *testing.T) {
|
||||
// ensure the ssh metadata hasn't changed
|
||||
assert.Equal(t, metadata["sshKeys"], sshKeys, "Instance metadata should not have been modified")
|
||||
}
|
||||
|
||||
func TestCreateInstanceMetadata_metadataFile(t *testing.T) {
|
||||
state := testState(t)
|
||||
c := state.Get("config").(*Config)
|
||||
image := StubImage("test-image", "test-project", []string{}, 100)
|
||||
content := testMetadataFileContent
|
||||
fileName := testMetadataFile(t)
|
||||
c.MetadataFiles["user-data"] = fileName
|
||||
|
||||
// create our metadata
|
||||
metadata, err := c.createInstanceMetadata(image, "", state)
|
||||
|
||||
assert.True(t, err == nil, "Metadata creation should have succeeded.")
|
||||
|
||||
// ensure the user-data key in metadata is updated with file content
|
||||
assert.Equal(t, metadata["user-data"], content, "user-data field of the instance metadata should have been updated.")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user