...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/pkg/util/repo/repo_test.go

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/pkg/util/repo

     1  // Copyright 2022 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 repo_test
    16  
    17  import (
    18  	"fmt"
    19  	"go/build"
    20  	"os"
    21  	"path/filepath"
    22  	"testing"
    23  
    24  	"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/util/repo"
    25  )
    26  
    27  func TestGetRepoRoot(t *testing.T) {
    28  	repoRoot, err := repo.GetRoot()
    29  	if err != nil {
    30  		t.Errorf("error getting root: %v", err)
    31  	}
    32  	expectedPath := fmt.Sprintf("%v%v%v", build.Default.GOPATH, string(filepath.Separator), "src/github.com/GoogleCloudPlatform/k8s-config-connector")
    33  	if repoRoot != expectedPath {
    34  		t.Errorf("unexpected value for repoRoot: got '%v', want '%v'", repoRoot, expectedPath)
    35  	}
    36  }
    37  
    38  func TestGetCallerPackagePath(t *testing.T) {
    39  	path, err := repo.GetCallerPackagePath()
    40  	if err != nil {
    41  		t.Errorf("error getting package path: %v", err)
    42  	}
    43  	expectedPath, err := os.Getwd()
    44  	if err != nil {
    45  		t.Fatalf("error getting working directory: %v", err)
    46  	}
    47  	if path != expectedPath {
    48  		t.Errorf("unexpected value for path: got '%v', want '%v'", path, expectedPath)
    49  	}
    50  }
    51  

View as plain text