aboutsummaryrefslogtreecommitdiffstats
path: root/syz-cluster/pkg/controller/testutil.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2025-02-13 13:59:19 +0100
committerAleksandr Nogikh <nogikh@google.com>2025-02-14 13:40:12 +0000
commiteaf86f3f4dc8a7190abf09fe840e20bcf83709d8 (patch)
treec28d030a8923833ffc39005b1a57946cd48fea62 /syz-cluster/pkg/controller/testutil.go
parent59c86b9e1c7a0f91fbb1b680676f33b4cc7bf137 (diff)
syz-cluster/controller: move the API server to pkg/controller
This will facilitate its reuse in tests.
Diffstat (limited to 'syz-cluster/pkg/controller/testutil.go')
-rw-r--r--syz-cluster/pkg/controller/testutil.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/syz-cluster/pkg/controller/testutil.go b/syz-cluster/pkg/controller/testutil.go
new file mode 100644
index 000000000..0c33df139
--- /dev/null
+++ b/syz-cluster/pkg/controller/testutil.go
@@ -0,0 +1,43 @@
+// Copyright 2025 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+package controller
+
+import (
+ "context"
+ "net/http/httptest"
+ "testing"
+
+ "github.com/google/syzkaller/syz-cluster/pkg/api"
+ "github.com/google/syzkaller/syz-cluster/pkg/app"
+ "github.com/stretchr/testify/assert"
+)
+
+// UploadTestSeries returns a (session ID, series ID) tuple.
+func UploadTestSeries(t *testing.T, ctx context.Context,
+ client *api.Client, series *api.Series) (string, string) {
+ retSeries, err := client.UploadSeries(ctx, series)
+ assert.NoError(t, err)
+ retSession, err := client.UploadSession(ctx, &api.NewSession{
+ ExtID: series.ExtID,
+ })
+ assert.NoError(t, err)
+ return retSeries.ID, retSession.ID
+}
+
+func UploadTestBuild(t *testing.T, ctx context.Context, client *api.Client,
+ build *api.Build) *api.UploadBuildResp {
+ ret, err := client.UploadBuild(ctx, &api.UploadBuildReq{
+ Build: *build,
+ })
+ assert.NoError(t, err)
+ assert.NotEmpty(t, ret.ID)
+ return ret
+}
+
+func TestServer(t *testing.T, env *app.AppEnvironment) *api.Client {
+ apiServer := NewAPIServer(env)
+ server := httptest.NewServer(apiServer.Mux())
+ t.Cleanup(server.Close)
+ return api.NewClient(server.URL)
+}