github.com/covergates/covergates@v0.2.2-0.20201009050117-42ef8a19fb95/cmd/cli/main_test.go (about)

     1  package main
     2  
     3  import (
     4  	"net/http"
     5  	"net/http/httptest"
     6  	"os"
     7  	"testing"
     8  
     9  	"github.com/google/go-cmp/cmp"
    10  )
    11  
    12  func TestUpload(t *testing.T) {
    13  	ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
    14  		token := r.Header.Get("Authorization")
    15  		if diff := cmp.Diff("Bearer token", token); diff != "" {
    16  			t.Fatal(diff)
    17  		}
    18  		if diff := cmp.Diff("/reports/123", r.URL.String()); diff != "" {
    19  			t.Fatal(diff)
    20  		}
    21  	}))
    22  	defer ts.Close()
    23  	os.Setenv("API_URL", ts.URL)
    24  	os.Setenv("REPORT_ID", "123")
    25  	os.Setenv("GATES_TOKEN", "token")
    26  	args := []string{"", "upload", "--type", "go", "./testdata/coverage.out"}
    27  	if err := app.Run(args); err != nil {
    28  		t.Fatal(err)
    29  	}
    30  
    31  }