...

Source file src/cloud.google.com/go/auth/credentials/internal/externalaccount/info_test.go

Documentation: cloud.google.com/go/auth/credentials/internal/externalaccount

     1  // Copyright 2023 Google LLC
     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 externalaccount
    16  
    17  import (
    18  	"runtime"
    19  	"testing"
    20  
    21  	"github.com/google/go-cmp/cmp"
    22  )
    23  
    24  func TestGoVersion(t *testing.T) {
    25  	testVersion := func(v string) func() string {
    26  		return func() string {
    27  			return v
    28  		}
    29  	}
    30  	for _, tst := range []struct {
    31  		v    func() string
    32  		want string
    33  	}{
    34  		{
    35  			testVersion("go1.19"),
    36  			"1.19.0",
    37  		},
    38  		{
    39  			testVersion("go1.21-20230317-RC01"),
    40  			"1.21.0-20230317-RC01",
    41  		},
    42  		{
    43  			testVersion("devel +abc1234"),
    44  			"abc1234",
    45  		},
    46  		{
    47  			testVersion("this should be unknown"),
    48  			versionUnknown,
    49  		},
    50  	} {
    51  		version = tst.v
    52  		got := goVersion()
    53  		if diff := cmp.Diff(got, tst.want); diff != "" {
    54  			t.Errorf("got(-),want(+):\n%s", diff)
    55  		}
    56  	}
    57  	version = runtime.Version
    58  }
    59  

View as plain text