github.com/inteleradmedicalsystems/go-codecommit@v0.1.0/pkg/codecommit/codecommit_test.go (about)

     1  package codecommit
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestCloneURLRegion(t *testing.T) {
     8  	e := NewCloneURLTest(t,
     9  		TestOptions{
    10  			uRL:    "https://git-codecommit.ca-central-1.amazonaws.com/v1/repos/ops-cloudpacs-dev",
    11  			region: "ca-central-1",
    12  			method: "get",
    13  		})
    14  	e.assertRegion()
    15  }
    16  func TestCloneURLInvalidRegion(t *testing.T) {
    17  	e := NewCloneURLTest(t,
    18  		TestOptions{
    19  			uRL:    "",
    20  			region: "ca-central-1",
    21  			method: "get",
    22  		})
    23  	e.assertInvalidRegion()
    24  }
    25  
    26  func NewCloneURLTest(t *testing.T, topts TestOptions) *CloneURLTest {
    27  	return &CloneURLTest{
    28  		t,
    29  		topts,
    30  	}
    31  }
    32  
    33  type TestOptions struct {
    34  	uRL    string
    35  	region string
    36  	method string
    37  }
    38  
    39  type CloneURLTest struct {
    40  	t     *testing.T
    41  	topts TestOptions
    42  }
    43  
    44  func (e *CloneURLTest) assertInvalidRegion() {
    45  	t := e.t
    46  	c := CloneURL{
    47  		RawURL: e.topts.uRL,
    48  	}
    49  	err := c.setURL()
    50  	if err != nil {
    51  		t.Error(err)
    52  	}
    53  
    54  	actual, err := c.parseRegion()
    55  	if err == nil {
    56  		t.Errorf("expected error not returned, actual %q", actual)
    57  	}
    58  }
    59  
    60  func (e *CloneURLTest) assertRegion() {
    61  	t := e.t
    62  	c := CloneURL{
    63  		RawURL: e.topts.uRL,
    64  	}
    65  	err := c.setURL()
    66  	if err != nil {
    67  		t.Error(err)
    68  	}
    69  
    70  	actual, err := c.parseRegion()
    71  	if err != nil {
    72  		t.Error(err)
    73  	}
    74  	expected := e.topts.region
    75  	if actual != expected {
    76  		t.Errorf("expected region %q, actual %q", expected, actual)
    77  	}
    78  }