github.com/gravitational/teleport/api@v0.0.0-20240507183017-3110591cbafc/utils/gcp/endpoint_test.go (about) 1 // Copyright 2022 Gravitational, Inc 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 gcp 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/require" 21 ) 22 23 func TestIsGCPEndpoint(t *testing.T) { 24 tests := []struct { 25 name string 26 hostname string 27 want bool 28 }{ 29 { 30 name: "compute googleapis", 31 hostname: "compute.googleapis.com", 32 want: true, 33 }, 34 { 35 name: "top level googleapis", 36 hostname: "googleapis.com", 37 want: false, 38 }, 39 { 40 name: "localhost", 41 hostname: "localhost", 42 want: false, 43 }, 44 { 45 name: "fake googleapis", 46 hostname: "compute.googleapis.com.fake.com", 47 want: false, 48 }, 49 { 50 name: "top level-like fake googleapis", 51 hostname: "googleapis.com.fake.com", 52 want: false, 53 }, 54 } 55 for _, tt := range tests { 56 t.Run(tt.name, func(t *testing.T) { 57 require.Equal(t, tt.want, IsGCPEndpoint(tt.hostname)) 58 }) 59 } 60 }