github.com/xmidt-org/webpa-common@v1.11.9/secure/key/setup_test.go (about)

     1  package key
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"net/http/httptest"
     7  	"os"
     8  	"testing"
     9  )
    10  
    11  const (
    12  	keyId = "testkey"
    13  )
    14  
    15  var (
    16  	httpServer *httptest.Server
    17  
    18  	publicKeyFilePath         string
    19  	publicKeyFilePathTemplate string
    20  
    21  	publicKeyURL         string
    22  	publicKeyURLTemplate string
    23  
    24  	privateKeyFilePath         string
    25  	privateKeyFilePathTemplate string
    26  
    27  	privateKeyURL         string
    28  	privateKeyURLTemplate string
    29  )
    30  
    31  func TestMain(m *testing.M) {
    32  	currentDirectory, err := os.Getwd()
    33  	if err != nil {
    34  		fmt.Fprintf(os.Stderr, "Unable to obtain current working directory: %v\n", err)
    35  		os.Exit(1)
    36  	}
    37  
    38  	httpServer = httptest.NewServer(http.FileServer(http.Dir(currentDirectory)))
    39  	defer httpServer.Close()
    40  	fmt.Printf("started test server at %s\n", httpServer.URL)
    41  
    42  	publicKeyFilePath = fmt.Sprintf("%s/%s.pub", currentDirectory, keyId)
    43  	publicKeyFilePathTemplate = fmt.Sprintf("%s/{%s}.pub", currentDirectory, KeyIdParameterName)
    44  
    45  	publicKeyURL = fmt.Sprintf("%s/%s.pub", httpServer.URL, keyId)
    46  	publicKeyURLTemplate = fmt.Sprintf("%s/{%s}.pub", httpServer.URL, KeyIdParameterName)
    47  
    48  	privateKeyFilePath = fmt.Sprintf("%s/%s", currentDirectory, keyId)
    49  	privateKeyFilePathTemplate = fmt.Sprintf("%s/{%s}", currentDirectory, KeyIdParameterName)
    50  
    51  	privateKeyURL = fmt.Sprintf("%s/%s", httpServer.URL, keyId)
    52  	privateKeyURLTemplate = fmt.Sprintf("%s/{%s}", httpServer.URL, KeyIdParameterName)
    53  
    54  	os.Exit(m.Run())
    55  }