Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Add update test
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Jun 1, 2022
1 parent 66c4269 commit 0027f5d
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 0 deletions.
226 changes: 226 additions & 0 deletions integration/client/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/acorn-io/acorn/pkg/client"
kclient "github.com/acorn-io/acorn/pkg/k8sclient"
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/api/resource"
)

func TestAppStartStop(t *testing.T) {
Expand Down Expand Up @@ -93,6 +94,231 @@ func TestAppDelete(t *testing.T) {
assert.Nil(t, newApp)
}

func TestAppUpdate(t *testing.T) {
helper.EnsureCRDs(t)
restConfig := helper.StartAPI(t)

ctx := helper.GetCTX(t)
kclient := helper.MustReturn(kclient.Default)
ns := helper.TempNamespace(t, kclient)

imageID := newImage(t, ns.Name)
imageID2 := newImage2(t, ns.Name)

c, err := client.New(restConfig, ns.Name)
if err != nil {
t.Fatal(err)
}

app, err := c.AppRun(ctx, imageID, &client.AppRunOptions{
Annotations: map[string]string{
"anno1": "val1",
"anno2": "val2",
},
Labels: map[string]string{
"label1": "val1",
"label2": "val2",
},
Endpoints: []v1.EndpointBinding{
{
Target: "ep-target1",
Hostname: "hostname1",
},
{
Target: "ep-target2",
Hostname: "hostname2",
},
},
Volumes: []v1.VolumeBinding{
{
Volume: "vol1",
VolumeRequest: "volreq1",
},
{
Volume: "vol2",
VolumeRequest: "volreq2",
},
},
Secrets: []v1.SecretBinding{
{
Secret: "sec1",
SecretRequest: "secreq1",
},
{
Secret: "sec2",
SecretRequest: "secreq2",
},
},
Services: []v1.ServiceBinding{
{
Target: "svc-target1",
Service: "other-service1",
},
{
Target: "svc-target2",
Service: "other-service2",
},
},
DeployParams: map[string]interface{}{
"param1": "val1",
"param2": "val2",
},
})
if err != nil {
t.Fatal(err)
}

newApp, err := c.AppUpdate(ctx, app.Name, &client.AppUpdateOptions{
Image: imageID2,
Annotations: map[string]string{
"anno2": "val3",
"anno3": "val3",
},
Labels: map[string]string{
"label2": "val3",
"label3": "val3",
},
Endpoints: []v1.EndpointBinding{
{
Target: "ep-target2",
Hostname: "hostname3",
},
{
Target: "ep-target3",
Hostname: "hostname3",
},
},
Volumes: []v1.VolumeBinding{
{
Volume: "vol3",
VolumeRequest: "volreq2",
},
{
Volume: "vol3",
VolumeRequest: "volreq3",
},
},
Secrets: []v1.SecretBinding{
{
Secret: "sec3",
SecretRequest: "secreq2",
},
{
Secret: "sec3",
SecretRequest: "secreq3",
},
},
Services: []v1.ServiceBinding{
{
Target: "svc-target2",
Service: "other-service3",
},
{
Target: "svc-target3",
Service: "other-service3",
},
},
DeployParams: map[string]interface{}{
"param2": "val3",
"param3": "val3",
},
})
if err != nil {
t.Fatal(err)
}

thirdApp, err := c.AppGet(ctx, app.Name)
if err != nil {
t.Fatal(err)
}

assert.Equal(t, newApp, thirdApp)

assert.Equal(t, map[string]string{
"anno1": "val1",
"anno2": "val3",
"anno3": "val3",
}, thirdApp.Annotations)

assert.Equal(t, map[string]string{
"label1": "val1",
"label2": "val3",
"label3": "val3",
}, thirdApp.Labels)

assert.Equal(t, []v1.EndpointBinding{
{
Target: "ep-target1",
Hostname: "hostname1",
},
{
Target: "ep-target2",
Hostname: "hostname3",
},
{
Target: "ep-target3",
Hostname: "hostname3",
},
}, thirdApp.Spec.Endpoints)

zero, _ := resource.ParseQuantity("0")
assert.Equal(t, []v1.VolumeBinding{
{
Volume: "vol1",
VolumeRequest: "volreq1",
Capacity: zero,
},
{
Volume: "vol3",
VolumeRequest: "volreq2",
Capacity: zero,
},
{
Volume: "vol3",
VolumeRequest: "volreq3",
Capacity: zero,
},
}, thirdApp.Spec.Volumes)

assert.Equal(t, []v1.SecretBinding{
{
Secret: "sec1",
SecretRequest: "secreq1",
},
{
Secret: "sec3",
SecretRequest: "secreq2",
},
{
Secret: "sec3",
SecretRequest: "secreq3",
},
}, thirdApp.Spec.Secrets)

assert.Equal(t, []v1.ServiceBinding{
{
Target: "svc-target1",
Service: "other-service1",
},
{
Target: "svc-target2",
Service: "other-service3",
},
{
Target: "svc-target3",
Service: "other-service3",
},
}, thirdApp.Spec.Services)

assert.Equal(t, v1.GenericMap{
"param1": "val1",
"param2": "val3",
"param3": "val3",
}, thirdApp.Spec.DeployParams)

assert.Equal(t, imageID2, thirdApp.Spec.Image)
}

func TestAppGet(t *testing.T) {
helper.EnsureCRDs(t)
restConfig := helper.StartAPI(t)
Expand Down
11 changes: 11 additions & 0 deletions integration/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func newImage2(t *testing.T, namespace string) string {
image, err := build.Build(helper.GetCTX(t), "./testdata/nginx2/acorn.cue", &build.Options{
Cwd: "./testdata/nginx2",
Namespace: namespace,
})
if err != nil {
t.Fatal(err)
}
return image.ID
}

func newImage(t *testing.T, namespace string) string {
image, err := build.Build(helper.GetCTX(t), "./testdata/nginx/acorn.cue", &build.Options{
Cwd: "./testdata/nginx",
Expand Down
1 change: 1 addition & 0 deletions pkg/server/registry/apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func (s *Storage) Create(ctx context.Context, obj runtime.Object, createValidati
DeployParams: params.Spec.DeployParams,
Volumes: params.Spec.Volumes,
Secrets: params.Spec.Secrets,
Services: params.Spec.Services,
}
)

Expand Down

0 comments on commit 0027f5d

Please sign in to comment.