github.com/jrperritt/terraform@v0.1.1-0.20170525065507-96f391dafc38/builtin/providers/ovh/provider_test.go (about) 1 package ovh 2 3 import ( 4 "fmt" 5 "log" 6 "os" 7 "testing" 8 9 "github.com/hashicorp/terraform/helper/schema" 10 "github.com/hashicorp/terraform/terraform" 11 12 "github.com/ovh/go-ovh/ovh" 13 ) 14 15 var testAccProviders map[string]terraform.ResourceProvider 16 var testAccProvider *schema.Provider 17 var testAccOVHClient *ovh.Client 18 19 func init() { 20 log.SetOutput(os.Stdout) 21 testAccProvider = Provider().(*schema.Provider) 22 testAccProviders = map[string]terraform.ResourceProvider{ 23 "ovh": testAccProvider, 24 } 25 } 26 27 func TestProvider(t *testing.T) { 28 if err := Provider().(*schema.Provider).InternalValidate(); err != nil { 29 t.Fatalf("err: %s", err) 30 } 31 } 32 33 func TestProvider_impl(t *testing.T) { 34 var _ terraform.ResourceProvider = Provider() 35 } 36 37 func testAccPreCheck(t *testing.T) { 38 v := os.Getenv("OVH_ENDPOINT") 39 if v == "" { 40 t.Fatal("OVH_ENDPOINT must be set for acceptance tests") 41 } 42 43 v = os.Getenv("OVH_APPLICATION_KEY") 44 if v == "" { 45 t.Fatal("OVH_APPLICATION_KEY must be set for acceptance tests") 46 } 47 48 v = os.Getenv("OVH_APPLICATION_SECRET") 49 if v == "" { 50 t.Fatal("OVH_APPLICATION_SECRET must be set for acceptance tests") 51 } 52 53 v = os.Getenv("OVH_CONSUMER_KEY") 54 if v == "" { 55 t.Fatal("OVH_CONSUMER_KEY must be set for acceptance tests") 56 } 57 58 v = os.Getenv("OVH_VRACK") 59 if v == "" { 60 t.Fatal("OVH_VRACK must be set for acceptance tests") 61 } 62 63 v = os.Getenv("OVH_PUBLIC_CLOUD") 64 if v == "" { 65 t.Fatal("OVH_PUBLIC_CLOUD must be set for acceptance tests") 66 } 67 68 if testAccOVHClient == nil { 69 config := Config{ 70 Endpoint: os.Getenv("OVH_ENDPOINT"), 71 ApplicationKey: os.Getenv("OVH_APPLICATION_KEY"), 72 ApplicationSecret: os.Getenv("OVH_APPLICATION_SECRET"), 73 ConsumerKey: os.Getenv("OVH_CONSUMER_KEY"), 74 } 75 76 if err := config.loadAndValidate(); err != nil { 77 t.Fatalf("couln't load OVH Client: %s", err) 78 } else { 79 testAccOVHClient = config.OVHClient 80 } 81 } 82 } 83 84 func testAccCheckVRackExists(t *testing.T) { 85 type vrackResponse struct { 86 Name string `json:"name"` 87 Description string `json:"description"` 88 } 89 90 r := vrackResponse{} 91 92 endpoint := fmt.Sprintf("/vrack/%s", os.Getenv("OVH_VRACK")) 93 94 err := testAccOVHClient.Get(endpoint, &r) 95 if err != nil { 96 t.Fatalf("Error: %q\n", err) 97 } 98 t.Logf("Read VRack %s -> name:'%s', desc:'%s' ", endpoint, r.Name, r.Description) 99 100 } 101 102 func testAccCheckPublicCloudExists(t *testing.T) { 103 type cloudProjectResponse struct { 104 ID string `json:"project_id"` 105 Status string `json:"status"` 106 Description string `json:"description"` 107 } 108 109 r := cloudProjectResponse{} 110 111 endpoint := fmt.Sprintf("/cloud/project/%s", os.Getenv("OVH_PUBLIC_CLOUD")) 112 113 err := testAccOVHClient.Get(endpoint, &r) 114 if err != nil { 115 t.Fatalf("Error: %q\n", err) 116 } 117 t.Logf("Read Cloud Project %s -> status: '%s', desc: '%s'", endpoint, r.Status, r.Description) 118 119 }