go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/swarming/server/testing/integrationmocks/server.go (about) 1 // Copyright 2023 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package integrationmocks exposes endpoints to simplify integration testing. 16 // 17 // Exposed endpoints fake some of Swarming Python server logic, which allows 18 // running some integration tests entirely within luci-go repo. 19 package integrationmocks 20 21 import ( 22 "context" 23 24 "google.golang.org/grpc/codes" 25 status "google.golang.org/grpc/status" 26 27 internalspb "go.chromium.org/luci/swarming/proto/internals" 28 "go.chromium.org/luci/swarming/server/hmactoken" 29 ) 30 31 // server implements IntegrationMocksServer. 32 type server struct { 33 UnimplementedIntegrationMocksServer 34 35 hmacSecret *hmactoken.Secret 36 } 37 38 // New constructs an IntegrationMocksServer implementation. 39 func New(ctx context.Context, hmacSecret *hmactoken.Secret) IntegrationMocksServer { 40 return &server{ 41 hmacSecret: hmacSecret, 42 } 43 } 44 45 func (s *server) GeneratePollToken(ctx context.Context, msg *internalspb.PollState) (*PollToken, error) { 46 tok, err := s.hmacSecret.GenerateToken(msg) 47 if err != nil { 48 return nil, status.Errorf(codes.Internal, "%s", err) 49 } 50 return &PollToken{PollToken: tok}, nil 51 }