github.com/oam-dev/kubevela@v1.9.11/references/cli/registry_test.go (about)

     1  /*
     2  Copyright 2021 The KubeVela Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package cli
    18  
    19  import (
    20  	"context"
    21  	"path/filepath"
    22  	"testing"
    23  
    24  	"github.com/stretchr/testify/assert"
    25  )
    26  
    27  func TestRegistry(t *testing.T) {
    28  	t.Skip("temporary pend this test")
    29  	testAddon := "dynamic-sa"
    30  	regName := "testReg"
    31  	localPath, err := filepath.Abs("../../e2e/plugin/testdata")
    32  	assert.Nil(t, err)
    33  
    34  	cases := map[string]struct {
    35  		url       string
    36  		expectReg Registry
    37  	}{
    38  		"oss registry": {
    39  			url:       "oss://registry.kubevela.net/",
    40  			expectReg: OssRegistry{},
    41  		},
    42  		"github registry": {
    43  			url:       "https://github.com/oam-dev/catalog/tree/master/registry",
    44  			expectReg: GithubRegistry{},
    45  		},
    46  		"local registry": {
    47  			url:       "file://" + localPath,
    48  			expectReg: LocalRegistry{},
    49  		},
    50  	}
    51  
    52  	for _, c := range cases {
    53  		registry, err := NewRegistry(context.Background(), "", regName, c.url)
    54  		assert.NoError(t, err, c.url)
    55  		assert.IsType(t, c.expectReg, registry, regName)
    56  
    57  		caps, err := registry.ListCaps()
    58  		assert.NoError(t, err, c.url)
    59  		assert.NotEmpty(t, caps, c.url)
    60  
    61  		capability, data, err := registry.GetCap(testAddon)
    62  		assert.NoError(t, err, c.url)
    63  		assert.NotNil(t, capability, testAddon)
    64  		assert.NotNil(t, data, testAddon)
    65  	}
    66  }
    67  
    68  func TestParseURL(t *testing.T) {
    69  	cases := map[string]struct {
    70  		url     string
    71  		exp     *GithubContent
    72  		expType string
    73  	}{
    74  		"api-github": {
    75  			url:     "https://api.github.com/repos/oam-dev/catalog/contents/traits?ref=master",
    76  			expType: TypeGithub,
    77  			exp: &GithubContent{
    78  				URL:   "https://api.github.com/repos/oam-dev/catalog/contents/traits?ref=master",
    79  				Owner: "oam-dev",
    80  				Repo:  "catalog",
    81  				Path:  "traits",
    82  				Ref:   "master",
    83  			},
    84  		},
    85  		"github-copy-path": {
    86  			url:     "https://github.com/oam-dev/catalog/tree/master/repository",
    87  			expType: TypeGithub,
    88  			exp: &GithubContent{
    89  				URL:   "https://github.com/oam-dev/catalog/tree/master/repository",
    90  				Owner: "oam-dev",
    91  				Repo:  "catalog",
    92  				Path:  "repository",
    93  				Ref:   "master",
    94  			},
    95  		},
    96  		"github-manual-write-path": {
    97  			url:     "https://github.com/oam-dev/catalog/traits",
    98  			expType: TypeGithub,
    99  			exp: &GithubContent{
   100  				URL:   "https://github.com/oam-dev/catalog/traits",
   101  				Owner: "oam-dev",
   102  				Repo:  "catalog",
   103  				Path:  "traits",
   104  			},
   105  		},
   106  	}
   107  	for caseName, c := range cases {
   108  		tp, content, err := Parse(c.url)
   109  		assert.NoError(t, err, caseName)
   110  		assert.Equal(t, c.exp, &content.GithubContent, caseName)
   111  		assert.Equal(t, c.expType, tp, caseName)
   112  	}
   113  }