internal/gomote: add swarming remove files
This commit adds the RemoveFiles endpoint to the swarming
implementation of the gomote server.
Fixes golang/go#63789
Change-Id: Ibd037a026f8ed2c46f2b4bb595706f2b38263d22
Reviewed-on: https://go-review.googlesource.com/c/build/+/538278
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Carlos Amedee <carlos@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/internal/gomote/swarming_test.go b/internal/gomote/swarming_test.go
index e904a15..d8025cc 100644
--- a/internal/gomote/swarming_test.go
+++ b/internal/gomote/swarming_test.go
@@ -653,6 +653,86 @@
}
}
+func TestSwarmingRemoveFiles(t *testing.T) {
+ ctx := access.FakeContextWithOutgoingIAPAuth(context.Background(), fakeIAP())
+ client := setupGomoteSwarmingTest(t, context.Background(), mockSwarmClientSimple())
+ gomoteID := mustCreateSwarmingInstance(t, client, fakeIAP())
+ if _, err := client.RemoveFiles(ctx, &protos.RemoveFilesRequest{
+ GomoteId: gomoteID,
+ Paths: []string{"temp_file.log"},
+ }); err != nil {
+ t.Fatalf("client.RemoveFiles(ctx, req) = response, %s; want no error", err)
+ }
+}
+
+func TestSwarmingRemoveFilesError(t *testing.T) {
+ // This test will create a gomote instance and attempt to call RemoveFiles.
+ // If overrideID is set to true, the test will use a different gomoteID than
+ // the one created for the test.
+ testCases := []struct {
+ desc string
+ ctx context.Context
+ overrideID bool
+ gomoteID string // Used iff overrideID is true.
+ paths []string
+ wantCode codes.Code
+ }{
+ {
+ desc: "unauthenticated request",
+ ctx: context.Background(),
+ wantCode: codes.Unauthenticated,
+ },
+ {
+ desc: "missing gomote id",
+ ctx: access.FakeContextWithOutgoingIAPAuth(context.Background(), fakeIAP()),
+ overrideID: true,
+ gomoteID: "",
+ wantCode: codes.InvalidArgument,
+ },
+ {
+ desc: "missing paths",
+ ctx: access.FakeContextWithOutgoingIAPAuth(context.Background(), fakeIAP()),
+ paths: []string{},
+ wantCode: codes.InvalidArgument,
+ },
+ {
+ desc: "gomote does not exist",
+ ctx: access.FakeContextWithOutgoingIAPAuth(context.Background(), fakeIAPWithUser("foo", "bar")),
+ overrideID: true,
+ gomoteID: "chucky",
+ paths: []string{"file.a"},
+ wantCode: codes.NotFound,
+ },
+ {
+ desc: "wrong gomote id",
+ ctx: access.FakeContextWithOutgoingIAPAuth(context.Background(), fakeIAPWithUser("foo", "bar")),
+ overrideID: false,
+ paths: []string{"file.a"},
+ wantCode: codes.PermissionDenied,
+ },
+ }
+ for _, tc := range testCases {
+ t.Run(tc.desc, func(t *testing.T) {
+ client := setupGomoteSwarmingTest(t, context.Background(), mockSwarmClientSimple())
+ gomoteID := mustCreateSwarmingInstance(t, client, fakeIAP())
+ if tc.overrideID {
+ gomoteID = tc.gomoteID
+ }
+ req := &protos.RemoveFilesRequest{
+ GomoteId: gomoteID,
+ Paths: tc.paths,
+ }
+ got, err := client.RemoveFiles(tc.ctx, req)
+ if err != nil && status.Code(err) != tc.wantCode {
+ t.Fatalf("unexpected error: %s; want %s", err, tc.wantCode)
+ }
+ if err == nil {
+ t.Fatalf("client.RemoveFiles(ctx, %v) = %v, nil; want error", req, got)
+ }
+ })
+ }
+}
+
func TestStartNewSwarmingTask(t *testing.T) {
log.SetOutput(io.Discard)
defer log.SetOutput(os.Stdout)