File: datastores_test.go

package info (click to toggle)
golang-github-vmware-photon-controller-go-sdk 0.0~PROMOTED-738%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 556 kB
  • sloc: sh: 33; makefile: 4
file content (75 lines) | stat: -rw-r--r-- 2,121 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2017 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache License, Version 2.0 (the "License").
// You may not use this product except in compliance with the License.
//
// This product may include a number of subcomponents with separate copyright notices and
// license terms. Your use of these subcomponents is subject to the terms and conditions
// of the subcomponent's license, as noted in the LICENSE file.

package photon

import (
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/vmware/photon-controller-go-sdk/photon/internal/mocks"
)

var _ = Describe("Datastores", func() {
	var (
		server        *mocks.Server
		client        *Client
		datastoreSpec *Datastore
	)

	BeforeEach(func() {
		server, client = testSetup()

		datastoreId := "1234"
		datastoreSpec = &Datastore{
			Kind:     "datastore",
			Type:     "LOCAL_VMFS",
			ID:       datastoreId,
			SelfLink: "https://192.0.0.2" + rootUrl + "/infrastructure/datastores/" + datastoreId,
		}
	})

	AfterEach(func() {
		server.Close()
	})

	Describe("Get", func() {
		It("Get a single datastore successfully", func() {

			server.SetResponseJson(200, datastoreSpec)

			datastore, err := client.Datastores.Get(datastoreSpec.ID)
			GinkgoT().Log(err)

			Expect(err).Should(BeNil())
			Expect(datastore).ShouldNot(BeNil())
			Expect(datastore.Kind).Should(Equal(datastoreSpec.Kind))
			Expect(datastore.Type).Should(Equal(datastoreSpec.Type))
			Expect(datastore.ID).Should(Equal(datastoreSpec.ID))

		})
	})
	Describe("GetAll", func() {
		It("Get all datastores successfully", func() {
			datastoresExpected := Datastores{
				Items: []Datastore{*datastoreSpec},
			}

			server.SetResponseJson(200, datastoresExpected)

			datastores, err := client.Datastores.GetAll()
			GinkgoT().Log(err)

			Expect(err).Should(BeNil())
			Expect(datastores).ShouldNot(BeNil())
			Expect(datastores.Items[0].Kind).Should(Equal(datastoreSpec.Kind))
			Expect(datastores.Items[0].Type).Should(Equal(datastoreSpec.Type))
			Expect(datastores.Items[0].ID).Should(Equal(datastoreSpec.ID))
		})
	})
})