go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/swarming/server/monitor/main_test.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 main 16 17 import ( 18 "strconv" 19 "testing" 20 21 "github.com/google/go-cmp/cmp" 22 ) 23 24 func TestPoolFromDimensions(t *testing.T) { 25 t.Parallel() 26 27 cases := []struct { 28 input []string 29 want string 30 }{ 31 {input: []string{}, want: ""}, 32 { 33 input: []string{ 34 "bot_config:bot_config.py", 35 "bot_size:e2-small", 36 "cores:2", 37 "cpu:x86", 38 "cpu:x86-64", 39 "cpu:x86-64-Broadwell_GCE", 40 "cpu:x86-64-avx2", 41 "gce:1", 42 "gcp:chromeos-bot", 43 "gpu:none", 44 "os:Linux", 45 "os:Ubuntu", 46 "os:Ubuntu-22", 47 "os:Ubuntu-22.04", 48 "os:Ubuntu-22.04.1", 49 "python:3", 50 "python:3.8", 51 "python:3.8.10+chromium.23", 52 }, 53 want: "bot_config:bot_config.py|bot_size:e2-small|cores:2|cpu:x86-64-Broadwell_GCE|cpu:x86-64-avx2|gce:1|gcp:chromeos-bot|gpu:none|os:Linux|os:Ubuntu-22.04.1|python:3.8.10+chromium.23", 54 }, 55 { 56 input: []string{ 57 "bot_config:bot_config.py", 58 "builder:android-angle-chromium-try", 59 "caches:builder_5c1553edd9cb669432705d2201ae2e09effac3bb5a66c8316e03b0a828f6fca1_v2", 60 "caches:git", 61 "caches:goma_v2", 62 "caches:vpython", 63 "cores:8", 64 "cpu:x86", 65 "cpu:x86-64", 66 "cpu:x86-64-Broadwell_GCE", 67 "cpu:x86-64-avx2", 68 "gce:1", 69 "gcp:google.com:chromecompute", 70 "gpu:none", 71 "id:android-angle-chromium-try-0-ldw1", 72 "image:chrome-jammy-23081300-d896075b897", 73 "inside_docker:0", 74 "kernel:6.2.0-26-generic", 75 "kvm:1", 76 "locale:en_US.UTF-8", 77 "machine_type:n1-standard-8", 78 "os:Linux", 79 "os:Ubuntu", 80 "os:Ubuntu-22", 81 "os:Ubuntu-22.04", 82 "os:Ubuntu-22.04.1", 83 "pool:luci.chromium.try", 84 "python:3", 85 "python:3.8", 86 "python:3.8.10+chromium.23", 87 "server_version:7321-94edb82", 88 "ssd:0", 89 "zone:us", 90 "zone:us-central", 91 "zone:us-central1", 92 "zone:us-central1-c", 93 }, 94 want: "bot_config:bot_config.py|builder:android-angle-chromium-try|cores:8|cpu:x86-64-Broadwell_GCE|cpu:x86-64-avx2|gce:1|gcp:google.com:chromecompute|gpu:none|image:chrome-jammy-23081300-d896075b897|inside_docker:0|kernel:6.2.0-26-generic|kvm:1|locale:en_US.UTF-8|machine_type:n1-standard-8|os:Linux|os:Ubuntu-22.04.1|pool:luci.chromium.try|python:3.8.10+chromium.23|ssd:0|zone:us-central1-c", 95 }, 96 } 97 for i, c := range cases { 98 i := i 99 c := c 100 t.Run(strconv.Itoa(i), func(t *testing.T) { 101 t.Parallel() 102 got := poolFromDimensions(c.input) 103 if diff := cmp.Diff(c.want, got); diff != "" { 104 t.Errorf("mismatch (-want +got):\n%s", diff) 105 } 106 }) 107 } 108 }