Files
Packer-Cn/builder/oracle/bmcs/client/instance_test.go
T
Andrew Pryde 9728f890cf Implemented and documented oracle-bmcs builder
Implements a new Packer builder (oracle-bmcs) which adds support for
building custom images for Oracle Bare Metal Cloud Services (BMCS)
https://cloud.oracle.com/en_US/bare-metal.

Additionally includes documentation for the oracle-bmcs builder.
2017-08-02 09:53:48 +01:00

103 lines
2.7 KiB
Go

// Copyright (c) 2017 Oracle America, Inc.
// The contents of this file are subject to the Mozilla Public License Version
// 2.0 (the "License"); you may not use this file except in compliance with the
// License. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/
package bmcs
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestGetInstance(t *testing.T) {
setup()
defer teardown()
id := "ocid1.instance.oc1.phx.a"
path := fmt.Sprintf("/instances/%s", id)
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `{"id":"%s"}`, id)
})
instance, err := client.Compute.Instances.Get(&GetInstanceParams{ID: id})
if err != nil {
t.Errorf("Client.Compute.Instances.Get() returned error: %v", err)
}
want := Instance{ID: id}
if !reflect.DeepEqual(instance, want) {
t.Errorf("Client.Compute.Instances.Get() returned %+v, want %+v", instance, want)
}
}
func TestLaunchInstance(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/instances/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{"displayName": "go-bmcs test"}`)
})
params := &LaunchInstanceParams{
AvailabilityDomain: "aaaa:PHX-AD-1",
CompartmentID: "ocid1.compartment.oc1..a",
DisplayName: "go-bmcs test",
ImageID: "ocid1.image.oc1.phx.a",
Shape: "VM.Standard1.1",
SubnetID: "ocid1.subnet.oc1.phx.a",
}
instance, err := client.Compute.Instances.Launch(params)
if err != nil {
t.Errorf("Client.Compute.Instances.Launch() returned error: %v", err)
}
want := Instance{DisplayName: "go-bmcs test"}
if !reflect.DeepEqual(instance, want) {
t.Errorf("Client.Compute.Instances.Launch() returned %+v, want %+v", instance, want)
}
}
func TestTerminateInstance(t *testing.T) {
setup()
defer teardown()
id := "ocid1.instance.oc1.phx.a"
path := fmt.Sprintf("/instances/%s", id)
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
})
err := client.Compute.Instances.Terminate(&TerminateInstanceParams{ID: id})
if err != nil {
t.Errorf("Client.Compute.Instances.Terminate() returned error: %v", err)
}
}
func TestInstanceGetResourceState(t *testing.T) {
setup()
defer teardown()
id := "ocid1.instance.oc1.phx.a"
path := fmt.Sprintf("/instances/%s", id)
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{"LifecycleState": "RUNNING"}`)
})
state, err := client.Compute.Instances.GetResourceState(id)
if err != nil {
t.Errorf("Client.Compute.Instances.GetResourceState() returned error: %v", err)
}
want := "RUNNING"
if state != want {
t.Errorf("Client.Compute.Instances.GetResourceState() returned %+v, want %+v", state, want)
}
}