github.com/saadullahsaeed/fragmenta-cms@v1.5.4/server_test.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  )
     8  
     9  // TestServer tests running the server and using http client to GET /
    10  // this test will fail if there is no secrets file.
    11  func TestServer(t *testing.T) {
    12  	// Setup our server from config
    13  	s, err := SetupServer()
    14  	if err != nil {
    15  		t.Fatalf("server: error setting up %s\n", err)
    16  	}
    17  
    18  	// Start the server
    19  	go s.Start()
    20  
    21  	// Try hitting the server to see if it is working
    22  
    23  	host := fmt.Sprintf("http://localhost%s/", s.PortString())
    24  	r, err := http.Get(host)
    25  	if err != nil {
    26  		t.Fatalf("server: error getting /  %s", err)
    27  	}
    28  
    29  	if r.StatusCode != http.StatusOK {
    30  		t.Fatalf("server: error getting / expected:%d got:%d", http.StatusOK, r.StatusCode)
    31  	}
    32  
    33  }