github.com/actions-on-google/gactions@v3.2.0+incompatible/api/testutils.go (about)

     1  // Copyright 2020 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  //     https://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 testutils
    16  
    17  import (
    18  	"io/ioutil"
    19  	"log"
    20  	"os"
    21  	"runtime"
    22  )
    23  
    24  const (
    25  	TestTmpDir = "/tmp"
    26  )
    27  
    28  func TestTmpRoot() string {
    29  	if runtime.GOOS == "windows" {
    30  		return "C:\\"
    31  	}
    32  	return ""
    33  }
    34  
    35  // ReadFileOrDie is a version of ReadFile that is fatal if not successful.
    36  func ReadFileOrDie(path string) []byte {
    37  	cwd, err := os.Getwd()
    38  	r, err := os.Open(path)
    39  	if err != nil {
    40  		log.Fatalf("Cannot open file %v%v%v", cwd, os.PathSeparator, path)
    41  	}
    42  	defer r.Close()
    43  	b, err := ioutil.ReadAll(r)
    44  	if err != nil {
    45  		log.Fatalf("Cannot read file %v%v%v", cwd, os.PathSeparator, path)
    46  	}
    47  	return b
    48  }