golang.org/x/build@v0.0.0-20240506185731-218518f32b70/internal/coordinator/pool/pool_test.go (about)

     1  // Copyright 2020 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  //go:build linux || darwin
     6  
     7  package pool
     8  
     9  import (
    10  	"testing"
    11  	"time"
    12  
    13  	"golang.org/x/build/dashboard"
    14  )
    15  
    16  func TestPoolDetermineDeleteTimeout(t *testing.T) {
    17  	testCases := []struct {
    18  		desc        string
    19  		hostValue   time.Duration
    20  		wantTimeout time.Duration
    21  	}{
    22  		{
    23  			desc:        "default",
    24  			wantTimeout: 2 * time.Hour,
    25  		},
    26  		{
    27  			desc:        "from-host",
    28  			hostValue:   8 * time.Hour,
    29  			wantTimeout: 8 * time.Hour,
    30  		},
    31  	}
    32  	for _, tc := range testCases {
    33  		t.Run(tc.desc, func(t *testing.T) {
    34  			h := &dashboard.HostConfig{
    35  				CustomDeleteTimeout: tc.hostValue,
    36  			}
    37  			if got := determineDeleteTimeout(h); got != tc.wantTimeout {
    38  				t.Errorf("determineDeleteTimeout(%+v) = %s; want %s", h, got, tc.wantTimeout)
    39  			}
    40  		})
    41  	}
    42  }
    43  
    44  func TestPoolIsBuildlet(t *testing.T) {
    45  	testCases := []struct {
    46  		desc string
    47  		name string
    48  		want bool
    49  	}{
    50  		{"valid", "buildlet-gce-tinker", true},
    51  		{"invalid", "gce-tinker", false},
    52  	}
    53  	for _, tc := range testCases {
    54  		t.Run(tc.desc, func(t *testing.T) {
    55  			if got := isBuildlet(tc.name); got != tc.want {
    56  				t.Errorf("isBuildlet(%q) = %t; want %t", tc.name, got, tc.want)
    57  			}
    58  		})
    59  	}
    60  }