Exemple #1
0
// TestDeleteDomain subcommand
func TestDeleteDomain(t *testing.T) {

	assert := assert.New(t)

	domainsTest, err := GetDomainData()
	assert.Nil(err, "Couldn't load domain test data")

	// only valid domains
	var domainsIn []api.Domain
	for _, domainTest := range domainsTest {
		if domainTest.Valid {
			domainsIn = append(domainsIn, domainTest.Domain)
		}
	}

	// wire up
	cs := &utils.MockConcertoService{}
	ds, err := api.NewDomainService(cs)
	assert.Nil(err, "Couldn't load domain service")
	assert.NotNil(ds, "Domain service not instanced")

	for _, domainIn := range domainsIn {
		// to json
		dIn, err := json.Marshal(domainIn)
		assert.Nil(err, "Domain test data corrupted")

		// call service
		cs.On("Delete", fmt.Sprintf("/v1/dns/domains/%s", domainIn.ID)).Return(dIn, 200, nil)
		err = ds.DeleteDomain(domainIn.ID)
		assert.Nil(err, "Error getting domain list")
	}
}
Exemple #2
0
// TestDomainUpdate subcommand
func TestDomainUpdate(t *testing.T) {

	assert := assert.New(t)

	domainsTest, err := GetDomainData()
	assert.Nil(err, "Couldn't load domain test data")

	// only valid domains
	var domainsIn []api.Domain
	for _, domainTest := range domainsTest {
		if domainTest.Valid {
			domainsIn = append(domainsIn, domainTest.Domain)
		}
	}

	// wire up
	cs := &utils.MockConcertoService{}
	ds, err := api.NewDomainService(cs)
	assert.Nil(err, "Couldn't load domain service")
	assert.NotNil(ds, "Domain service not instanced")

	for _, domainIn := range domainsIn {

		// convertMap
		mapIn, err := itemConvertParams(domainIn)
		assert.Nil(err, "Domain test data corrupted")

		// to json
		dOut, err := json.Marshal(domainIn)
		assert.Nil(err, "Domain test data corrupted")

		// call service
		cs.On("Put", fmt.Sprintf("/v1/dns/domains/%s", domainIn.ID), mapIn).Return(dOut, 200, nil)
		domainOut, err := ds.UpdateDomain(mapIn, domainIn.ID)
		assert.Nil(err, "Error creating domain list")
		assert.Equal(domainIn, *domainOut, "GetDomainList returned different domains")

		// TODO iterate all formatters
		// write output
		var b bytes.Buffer
		mockOut := bufio.NewWriter(&b)
		f := format.NewJSONFormatter(mockOut)
		assert.NotNil(f, "Formatter")
		err = f.PrintList(domainOut)
		assert.Nil(err, "JSON Formatter Printlinst error")
		mockOut.Flush()

		// TODO add more accurate parsing
		assert.Regexp("\\{\\\"id\\\":.*\\}", b.String(), "JSON Output didn't match regular expression")

	}

}
Exemple #3
0
// WireUpDomain prepares common resources to send request to Concerto API
func WireUpDomain(c *cli.Context) (ds *api.DomainService, f format.Formatter) {

	f = format.GetFormatter()

	config, err := utils.GetConcertoConfig()
	if err != nil {
		f.PrintFatal("Couldn't wire up config", err)
	}
	hcs, err := utils.NewHTTPConcertoService(config)
	if err != nil {
		f.PrintFatal("Couldn't wire up concerto service", err)
	}
	ds, err = api.NewDomainService(hcs)
	if err != nil {
		f.PrintFatal("Couldn't wire up domain service", err)
	}

	return ds, f
}