...

Source file src/github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/util/cloudsqlutil_test.go

Documentation: github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/util

     1  // Copyright 2015 Google Inc. All Rights Reserved.
     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 util
    16  
    17  import "testing"
    18  
    19  func TestSplitName(t *testing.T) {
    20  	table := []struct{ in, wantProj, wantRegion, wantInstance string }{
    21  		{"proj:region:my-db", "proj", "region", "my-db"},
    22  		{"google.com:project:region:instance", "google.com:project", "region", "instance"},
    23  		{"google.com:missing:part", "google.com:missing", "", "part"},
    24  	}
    25  
    26  	for _, test := range table {
    27  		gotProj, gotRegion, gotInstance := SplitName(test.in)
    28  		if gotProj != test.wantProj {
    29  			t.Errorf("splitName(%q): got %v for project, want %v", test.in, gotProj, test.wantProj)
    30  		}
    31  		if gotRegion != test.wantRegion {
    32  			t.Errorf("splitName(%q): got %v for region, want %v", test.in, gotRegion, test.wantRegion)
    33  		}
    34  		if gotInstance != test.wantInstance {
    35  			t.Errorf("splitName(%q): got %v for instance, want %v", test.in, gotInstance, test.wantInstance)
    36  		}
    37  	}
    38  }
    39  

View as plain text