...

Source file src/github.com/googleapis/enterprise-certificate-proxy/client/util/util_test.go

Documentation: github.com/googleapis/enterprise-certificate-proxy/client/util

     1  // Copyright 2022 Google LLC.
     2  // Licensed under the Apache License, Version 2.0 (the "License");
     3  // you may not use this file except in compliance with the License.
     4  // You may obtain a copy of the License at
     5  //
     6  //     https://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package util
    15  
    16  import (
    17  	"os"
    18  	"testing"
    19  )
    20  
    21  func TestLoadSignerBinaryPath(t *testing.T) {
    22  	path, err := LoadSignerBinaryPath("./test_data/certificate_config.json")
    23  	if err != nil {
    24  		t.Errorf("LoadSignerBinaryPath error: %q", err)
    25  	}
    26  	want := "C:/Program Files (x86)/Google/Endpoint Verification/signer.exe"
    27  	if path != want {
    28  		t.Errorf("Expected path is %q, got: %q", want, path)
    29  	}
    30  }
    31  
    32  func TestLoadSignerBinaryPathHome(t *testing.T) {
    33  	path, err := LoadSignerBinaryPath("./test_data/certificate_config_home_expansion.json")
    34  	if err != nil {
    35  		t.Errorf("LoadSignerBinaryPath error: %q", err)
    36  	}
    37  	want := guessHomeDir() + "/ecp/signer"
    38  	if path != want {
    39  		t.Errorf("Expected path is %q, got: %q", want, path)
    40  	}
    41  }
    42  
    43  func TestLoadSignerBinaryPathTilde(t *testing.T) {
    44  	path, err := LoadSignerBinaryPath("./test_data/certificate_config_tilde_expansion.json")
    45  	if err != nil {
    46  		t.Errorf("LoadSignerBinaryPath error: %q", err)
    47  	}
    48  	want := guessHomeDir() + "/ecp/signer"
    49  	if path != want {
    50  		t.Errorf("Expected path is %q, got: %q", want, path)
    51  	}
    52  }
    53  
    54  func TestGetConfigFilePathFromEnv(t *testing.T) {
    55  	want := "/testpath"
    56  	os.Setenv("GOOGLE_API_CERTIFICATE_CONFIG", want)
    57  	path := GetConfigFilePathFromEnv()
    58  	if path != want {
    59  		t.Errorf("Expected path is %q, got: %q", want, path)
    60  	}
    61  }
    62  

View as plain text