API for environments

Environments for functions. For now this is just the image URL for the
function run container. In the future, Environments will also have
build container image URLs, and perhaps parameters to those
containers.

Create/read/update/delete/list. Versioning will be added later. For
now, only the latest update is stored.
This commit is contained in:
Soam Vasani
2016-09-21 22:29:51 -07:00
parent 80e73f7f09
commit 6b67bc0a61
6 changed files with 324 additions and 27 deletions
+46
View File
@@ -152,6 +152,51 @@ func TestHTTPTriggerApi(t *testing.T) {
assert(len(ts) == 2, "created two triggers, but didn't find them")
}
func TestEnvironmentApi(t *testing.T) {
testEnv := &fission.Environment{
Metadata: fission.Metadata{
Name: "xxx",
Uid: "yyy",
},
RunContainerImageUrl: "gcr.io/xyz",
}
uid, err := g.client.EnvironmentCreate(testEnv)
panicIf(err)
m := &fission.Metadata{
Name: testEnv.Metadata.Name,
Uid: uid,
}
defer g.client.EnvironmentDelete(m)
tr, err := g.client.EnvironmentGet(m)
panicIf(err)
testEnv.Metadata.Uid = m.Uid
assert(*testEnv == *tr, "env should match after reading")
testEnv.RunContainerImageUrl = "/hi"
uid2, err := g.client.EnvironmentUpdate(testEnv)
panicIf(err)
m.Uid = uid2
tr, err = g.client.EnvironmentGet(m)
panicIf(err)
testEnv.Metadata.Uid = m.Uid
assert(*testEnv == *tr, "env should match after reading")
testEnv.Metadata.Name = "yyy"
uid, err = g.client.EnvironmentCreate(testEnv)
panicIf(err)
m = &fission.Metadata{
Name: testEnv.Metadata.Name,
Uid: uid,
}
defer g.client.EnvironmentDelete(m)
ts, err := g.client.EnvironmentList()
panicIf(err)
assert(len(ts) == 2, "created two envs, but didn't find them")
}
func TestMain(m *testing.M) {
flag.Parse()
@@ -167,6 +212,7 @@ func TestMain(m *testing.M) {
ks.Delete(context.Background(), "Function", &etcdClient.DeleteOptions{Recursive: true})
ks.Delete(context.Background(), "HTTPTrigger", &etcdClient.DeleteOptions{Recursive: true})
ks.Delete(context.Background(), "Environment", &etcdClient.DeleteOptions{Recursive: true})
go api.serve(8888)
time.Sleep(500 * time.Millisecond)