package config_test

import (
	"strings"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/rackhd/rackhd-cpi/bosh"
	"github.com/rackhd/rackhd-cpi/config"
)

var _ = Describe("Creating a config", func() {
	var request bosh.CpiRequest

	BeforeEach(func() {
		request = bosh.CpiRequest{}
	})

	It("checks that the API server URI is set", func() {
		jsonReader := strings.NewReader(`{}`)
		_, err := config.New(jsonReader, request)
		Expect(err).To(MatchError("ApiServer IP is not set"))
	})

	It("checks that the agent configuration has an mbus setting", func() {
		jsonReader := strings.NewReader(`{"apiserver":"localhost:8080", "agent":{"blobstore": {"some": "options"}}}`)
		_, err := config.New(jsonReader, request)
		Expect(err).To(MatchError(`Agent config invalid {map[some:options]  []}`))
	})

	It("checks that the agent configuration includes a blobstore section", func() {
	"sync"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/ghttp"
	"github.com/rackhd/rackhd-cpi/bosh"
	"github.com/rackhd/rackhd-cpi/config"
	"github.com/rackhd/rackhd-cpi/helpers"
	"github.com/rackhd/rackhd-cpi/rackhdapi"
)

var _ = Describe("The VM Creation Workflow", func() {
	var server *ghttp.Server
	var jsonReader *strings.Reader
	var cpiConfig config.Cpi
	var request bosh.CpiRequest
	var allowFilter Filter

	BeforeEach(func() {
		server, jsonReader, cpiConfig, request = helpers.SetUp(bosh.CREATE_VM)

		allowFilter = Filter{
			data:   nil,
			method: AllowAnyNodeMethod,
		}
	})

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