github.com/sirkon/goproxy@v1.4.8/plugin/gitlab/module_test.go (about)

     1  package gitlab
     2  
     3  import (
     4  	"context"
     5  	"reflect"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/sirkon/gitlab/gitlabdata"
    10  	"github.com/stretchr/testify/mock"
    11  
    12  	"github.com/sirkon/goproxy/internal/mocks/gitlabapi"
    13  )
    14  
    15  func Test_gitlabModule_Versions(t *testing.T) {
    16  	client1 := &gitlabapi.GitlabAPICLient{}
    17  	client1.On("Tags", "github.com/user/project", "").Return(
    18  		[]*gitlabdata.Tag{
    19  			{
    20  				Commit: &gitlabdata.Commit{
    21  					ID:        "1",
    22  					ShortID:   "1",
    23  					CreatedAt: time.RFC3339,
    24  				},
    25  				Release: nil,
    26  				Name:    "v0.0.1",
    27  			},
    28  			{
    29  				Commit: &gitlabdata.Commit{
    30  					ID:        "1",
    31  					ShortID:   "1",
    32  					CreatedAt: time.RFC3339,
    33  				},
    34  				Release: nil,
    35  				Name:    "v0.0.2",
    36  			},
    37  			{
    38  				Commit: &gitlabdata.Commit{
    39  					ID:        "1",
    40  					ShortID:   "1",
    41  					CreatedAt: time.RFC3339,
    42  				},
    43  				Release: nil,
    44  				Name:    "v0.0.3",
    45  			},
    46  		},
    47  		nil,
    48  	)
    49  
    50  	tests := []struct {
    51  		name    string
    52  		gitlab  *gitlabModule
    53  		prefix  string
    54  		want    []string
    55  		wantErr bool
    56  	}{
    57  		{
    58  			name: "test-1",
    59  			gitlab: &gitlabModule{
    60  				client:          client1,
    61  				fullPath:        "github.com/user/project",
    62  				path:            "github.com/user/project",
    63  				pathUnversioned: "github.com/user/project",
    64  			},
    65  			prefix:  "",
    66  			want:    []string{"v0.0.1", "v0.0.2", "v0.0.3"},
    67  			wantErr: false,
    68  		},
    69  	}
    70  	for _, tt := range tests {
    71  		t.Run(tt.name, func(t *testing.T) {
    72  			got, err := tt.gitlab.Versions(context.Background(), tt.prefix)
    73  			if (err != nil) != tt.wantErr {
    74  				t.Errorf("Versions() error = %v, wantErr %v", err, tt.wantErr)
    75  				return
    76  			}
    77  			if !reflect.DeepEqual(got, tt.want) {
    78  				t.Errorf("Versions() got = %v, want %v", got, tt.want)
    79  			}
    80  		})
    81  	}
    82  
    83  	mock.AssertExpectationsForObjects(t, client1)
    84  }