github.com/fredbi/git-chglog@v0.0.0-20190706071416-d35c598eac81/cmd/git-chglog/processor_factory_test.go (about)

     1  package main
     2  
     3  import (
     4  	"testing"
     5  
     6  	chglog "github.com/fredbi/git-chglog"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestProcessorFactory(t *testing.T) {
    11  	assert := assert.New(t)
    12  	factory := NewProcessorFactory()
    13  
    14  	processor, err := factory.Create(&Config{
    15  		Info: Info{
    16  			RepositoryURL: "https://example.com/owner/repo",
    17  		},
    18  	})
    19  
    20  	assert.Nil(err)
    21  	assert.Nil(processor)
    22  }
    23  
    24  func TestProcessorFactoryForGitHub(t *testing.T) {
    25  	assert := assert.New(t)
    26  	factory := NewProcessorFactory()
    27  
    28  	// github.com
    29  	processor, err := factory.Create(&Config{
    30  		Info: Info{
    31  			RepositoryURL: "https://github.com/owner/repo",
    32  		},
    33  	})
    34  
    35  	assert.Nil(err)
    36  	assert.Equal(
    37  		&chglog.GitHubProcessor{
    38  			Host: "https://github.com",
    39  		},
    40  		processor,
    41  	)
    42  
    43  	// ghe
    44  	processor, err = factory.Create(&Config{
    45  		Style: "github",
    46  		Info: Info{
    47  			RepositoryURL: "https://ghe-example.com/owner/repo",
    48  		},
    49  	})
    50  
    51  	assert.Nil(err)
    52  	assert.Equal(
    53  		&chglog.GitHubProcessor{
    54  			Host: "https://ghe-example.com",
    55  		},
    56  		processor,
    57  	)
    58  }
    59  
    60  func TestProcessorFactoryForGitLab(t *testing.T) {
    61  	assert := assert.New(t)
    62  	factory := NewProcessorFactory()
    63  
    64  	// gitlab.com
    65  	processor, err := factory.Create(&Config{
    66  		Info: Info{
    67  			RepositoryURL: "https://gitlab.com/owner/repo",
    68  		},
    69  	})
    70  
    71  	assert.Nil(err)
    72  	assert.Equal(
    73  		&chglog.GitLabProcessor{
    74  			Host: "https://gitlab.com",
    75  		},
    76  		processor,
    77  	)
    78  
    79  	// self-hosted
    80  	processor, err = factory.Create(&Config{
    81  		Style: "gitlab",
    82  		Info: Info{
    83  			RepositoryURL: "https://original-gitserver.com/owner/repo",
    84  		},
    85  	})
    86  
    87  	assert.Nil(err)
    88  	assert.Equal(
    89  		&chglog.GitLabProcessor{
    90  			Host: "https://original-gitserver.com",
    91  		},
    92  		processor,
    93  	)
    94  }
    95  
    96  func TestProcessorFactoryForBitbucket(t *testing.T) {
    97  	assert := assert.New(t)
    98  	factory := NewProcessorFactory()
    99  
   100  	// bitbucket.org
   101  	processor, err := factory.Create(&Config{
   102  		Info: Info{
   103  			RepositoryURL: "https://bitbucket.org/owner/repo",
   104  		},
   105  	})
   106  
   107  	assert.Nil(err)
   108  	assert.Equal(
   109  		&chglog.BitbucketProcessor{
   110  			Host: "https://bitbucket.org",
   111  		},
   112  		processor,
   113  	)
   114  
   115  	// self-hosted
   116  	processor, err = factory.Create(&Config{
   117  		Style: "bitbucket",
   118  		Info: Info{
   119  			RepositoryURL: "https://original-gitserver.com/owner/repo",
   120  		},
   121  	})
   122  
   123  	assert.Nil(err)
   124  	assert.Equal(
   125  		&chglog.BitbucketProcessor{
   126  			Host: "https://original-gitserver.com",
   127  		},
   128  		processor,
   129  	)
   130  }