golang.org/x/build@v0.0.0-20240506185731-218518f32b70/internal/swarmclient/config_test.go (about) 1 // Copyright 2023 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package swarmclient 6 7 import ( 8 "context" 9 "os" 10 "testing" 11 12 "github.com/google/go-cmp/cmp" 13 ) 14 15 func TestListSwarmingBots(t *testing.T) { 16 contents, err := os.ReadFile("testdata/bb-sample.cfg") 17 if err != nil { 18 t.Fatalf("os.ReadFile() = nil, %s", err) 19 } 20 ctx := context.Background() 21 client := NewMemoryConfigClient(ctx, []*ConfigEntry{ 22 &ConfigEntry{"cr-buildbucket.cfg", contents}, 23 }) 24 bots, err := client.ListSwarmingBots(ctx) 25 if err != nil { 26 t.Fatalf("ListSwarmingBots() = nil, %s", err) 27 } 28 wantLen := 21 29 if len(bots) != wantLen { 30 t.Errorf("len(bots) = %d; want %d", len(bots), wantLen) 31 } 32 bot := bots[0] 33 if bot.BucketName != "ci" { 34 t.Errorf("bot.BucketName = %q, want %q", bot.BucketName, "ci") 35 } 36 wantDimensions := []string{"cpu:x86-64", "os:Linux", "pool:luci.golang.ci"} 37 if diff := cmp.Diff(bot.Dimensions, wantDimensions); diff != "" { 38 t.Errorf("bot.Dimensions mismatch (-want +got): \n%s", diff) 39 } 40 wantHost := "chromium-swarm.appspot.com" 41 if bot.Host != wantHost { 42 t.Errorf("bot.Host = %q, want %q", bot.Host, wantHost) 43 } 44 wantName := "go1.20-darwin-amd64" 45 if bot.Name != wantName { 46 t.Errorf("bot.Name = %q, want %q", bot.Name, wantName) 47 } 48 }