This repository has been archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e8825c
commit e90f652
Showing
25 changed files
with
508 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package client | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/acorn-io/acorn/integration/helper" | ||
"github.com/acorn-io/acorn/pkg/build" | ||
) | ||
|
||
func NewImage2(t *testing.T, namespace string) string { | ||
image, err := build.Build(helper.GetCTX(t), "../testdata/nginx2/acorn.cue", &build.Options{ | ||
Client: helper.BuilderClient(t, namespace), | ||
Cwd: "../testdata/nginx2", | ||
}) | ||
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{ | ||
Client: helper.BuilderClient(t, namespace), | ||
Cwd: "../testdata/nginx", | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return image.ID | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
integration/client/credentials_test.go → ...on/client/credentials/credentials_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package client | ||
package credentials | ||
|
||
import ( | ||
"sort" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/acorn-io/acorn/integration/helper" | ||
v1 "github.com/acorn-io/acorn/pkg/apis/api.acorn.io/v1" | ||
"github.com/acorn-io/acorn/pkg/build" | ||
"github.com/acorn-io/acorn/pkg/client" | ||
"github.com/acorn-io/acorn/pkg/k8sclient" | ||
"github.com/acorn-io/acorn/pkg/labels" | ||
"github.com/stretchr/testify/assert" | ||
"golang.org/x/sync/errgroup" | ||
appsv1 "k8s.io/api/apps/v1" | ||
batchv1 "k8s.io/api/batch/v1" | ||
kclient "sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func depImage(t *testing.T, c client.Client) string { | ||
image, err := build.Build(helper.GetCTX(t), "./testdata/dependson/acorn.cue", &build.Options{ | ||
Client: c, | ||
Cwd: "./testdata/dependson", | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return image.ID | ||
} | ||
|
||
func toRevision(t *testing.T, obj kclient.Object) int { | ||
i, err := strconv.Atoi(obj.GetResourceVersion()) | ||
if err != nil { | ||
t.Fatalf("Invalid resource version %s on %s/%s", obj.GetResourceVersion(), obj.GetNamespace(), obj.GetName()) | ||
} | ||
return i | ||
} | ||
|
||
func TestDependsOn(t *testing.T) { | ||
ctx := context.Background() | ||
c, _ := helper.ClientAndNamespace(t) | ||
k8sclient := helper.MustReturn(k8sclient.Default) | ||
image := depImage(t, c) | ||
|
||
app, err := c.AppRun(ctx, image, nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
jobs := map[string]int{} | ||
deployments := map[string]int{} | ||
|
||
app = helper.WaitForObject(t, c.GetClient().Watch, &v1.AppList{}, app, func(app *v1.App) bool { | ||
return app.Status.Namespace != "" | ||
}) | ||
|
||
eg := errgroup.Group{} | ||
|
||
eg.Go(func() error { | ||
helper.Wait(t, k8sclient.Watch, &batchv1.JobList{}, func(job *batchv1.Job) bool { | ||
if job.Namespace != app.Status.Namespace { | ||
return false | ||
} | ||
name := job.Labels[labels.AcornJobName] | ||
if _, ok := jobs[name]; !ok { | ||
jobs[name] = toRevision(t, job) | ||
if len(jobs) == 2 { | ||
return true | ||
} | ||
} | ||
return false | ||
}) | ||
return nil | ||
}) | ||
|
||
eg.Go(func() error { | ||
helper.Wait(t, k8sclient.Watch, &appsv1.DeploymentList{}, func(dep *appsv1.Deployment) bool { | ||
if dep.Namespace != app.Status.Namespace { | ||
return false | ||
} | ||
name := dep.Labels[labels.AcornContainerName] | ||
if _, ok := deployments[name]; !ok { | ||
deployments[name] = toRevision(t, dep) | ||
if len(deployments) == 3 { | ||
return true | ||
} | ||
} | ||
return false | ||
}) | ||
return nil | ||
}) | ||
|
||
_ = eg.Wait() | ||
|
||
assert.Less(t, jobs["job2"], jobs["job1"]) | ||
assert.Less(t, jobs["job1"], deployments["one"]) | ||
assert.Less(t, jobs["job2"], deployments["one"]) | ||
assert.Less(t, deployments["one"], deployments["two"]) | ||
assert.Less(t, deployments["two"], deployments["three"]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
integration/client/secrets_test.go → integration/client/secrets/secrets_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package client | ||
package secrets | ||
|
||
import ( | ||
"testing" | ||
|
Oops, something went wrong.