This can be used in tests to get access to a controller that behaves just like a dev controller but doesn't require the normal Command bits (UI, etc). This can be enhanced over time as needed; for now it's pretty simple but it's good enough to be used for API tests. A simple project create/read API test is added as well, which serves to show the programmatic model (as well as test those functions at the API level).
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package scopes
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/watchtower/api"
|
|
"github.com/hashicorp/watchtower/internal/servers/controller"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestProjects_Crud(t *testing.T) {
|
|
tc := controller.NewTestController(t, nil)
|
|
defer tc.Shutdown()
|
|
|
|
client := tc.Client()
|
|
org := &Organization{
|
|
Client: client,
|
|
}
|
|
|
|
name := "foo"
|
|
|
|
checkProject := func(step string, p *Project, apiErr *api.Error, err error) {
|
|
assert := assert.New(t)
|
|
assert.NoError(err, step)
|
|
assert.Nil(apiErr, step)
|
|
assert.NotNil(p, "returned project", step)
|
|
assert.NotNil(p, "returned project name", step)
|
|
assert.Equal(name, *p.Name, step)
|
|
}
|
|
|
|
p, apiErr, err := org.CreateProject(tc.Context(), &Project{Name: api.String(name)})
|
|
checkProject("create", p, apiErr, err)
|
|
|
|
p, apiErr, err = org.ReadProject(tc.Context(), &Project{Id: p.Id})
|
|
checkProject("read", p, apiErr, err)
|
|
|
|
// TODO: Update and Delete
|
|
|
|
// TODO: Error conditions once the proper errors are being returned.
|
|
// Probably as parallel subtests against the same DB.
|
|
}
|