github.com/kvattikuti/drone@v0.2.1-0.20140603034306-d400229a327a/pkg/plugin/notify/slack_test.go (about)

     1  package notify
     2  
     3  import (
     4  	"github.com/drone/drone/pkg/model"
     5  	"testing"
     6  )
     7  
     8  func Test_getBuildUrl(t *testing.T) {
     9  	c := &Context{
    10  		Host: "http://examplehost.com",
    11  		Repo: &model.Repo{
    12  			Slug: "examplegit.com/owner/repo",
    13  		},
    14  		Commit: &model.Commit{
    15  			Hash:   "abc",
    16  			Branch: "example",
    17  		},
    18  	}
    19  	expected := "http://examplehost.com/examplegit.com/owner/repo/commit/abc?branch=example"
    20  	output := getBuildUrl(c)
    21  
    22  	if output != expected {
    23  		t.Errorf("Failed to build url. Expected: %s, got %s", expected, output)
    24  	}
    25  
    26  	c.Commit.Branch = "url/unsafe/branch"
    27  	expected = "http://examplehost.com/examplegit.com/owner/repo/commit/abc?branch=url%2Funsafe%2Fbranch"
    28  	output = getBuildUrl(c)
    29  
    30  	if output != expected {
    31  		t.Errorf("Failed to build url. Expected: %s, got %s", expected, output)
    32  	}
    33  
    34  	c.Commit.Branch = ""
    35  	expected = "http://examplehost.com/examplegit.com/owner/repo/commit/abc?"
    36  	output = getBuildUrl(c)
    37  
    38  	if output != expected {
    39  		t.Errorf("Failed to build url. Expected: %s, got %s", expected, output)
    40  	}
    41  }