...

Source file src/github.com/sigstore/timestamp-authority/pkg/tests/server.go

Documentation: github.com/sigstore/timestamp-authority/pkg/tests

     1  //
     2  // Copyright 2022 The Sigstore Authors.
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  
    16  package tests
    17  
    18  import (
    19  	"net/http"
    20  	"net/http/httptest"
    21  	"testing"
    22  	"time"
    23  
    24  	"github.com/spf13/viper"
    25  
    26  	"github.com/sigstore/timestamp-authority/pkg/server"
    27  )
    28  
    29  func createServer(t *testing.T) string {
    30  	viper.Set("timestamp-signer", "memory")
    31  	viper.Set("timestamp-signer-hash", "sha256")
    32  	// unused port
    33  	apiServer := server.NewRestAPIServer("localhost", 0, []string{"http"}, false, 10*time.Second, 10*time.Second)
    34  	server := httptest.NewServer(apiServer.GetHandler())
    35  	t.Cleanup(server.Close)
    36  
    37  	// verify the server's health
    38  	response, err := http.Get(server.URL + "/ping")
    39  	if err != nil || response.StatusCode != 200 {
    40  		t.Fatalf("unexpected error starting up server - status code: %d, err: %v", response.StatusCode, err)
    41  	}
    42  
    43  	return server.URL
    44  }
    45  

View as plain text