|
| 1 | +/* |
| 2 | +Copyright 2019 The Kubernetes 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 repository |
| 18 | + |
| 19 | +import ( |
| 20 | + "os" |
| 21 | + "reflect" |
| 22 | + "testing" |
| 23 | + |
| 24 | + clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3" |
| 25 | + "sigs.k8s.io/cluster-api/cmd/clusterctl/pkg/client/config" |
| 26 | + "sigs.k8s.io/cluster-api/cmd/clusterctl/pkg/internal/test" |
| 27 | +) |
| 28 | + |
| 29 | +func Test_newRepositoryClient_LocalFileSystemRepository(t *testing.T) { |
| 30 | + tmpDir := createTempDir(t) |
| 31 | + defer os.RemoveAll(tmpDir) |
| 32 | + |
| 33 | + dst1 := createLocalTestProviderFile(t, tmpDir, "provider-1/v1.0.0/bootstrap-components.yaml", "") |
| 34 | + dst2 := createLocalTestProviderFile(t, tmpDir, "provider-2/v2.0.0/bootstrap-components.yaml", "") |
| 35 | + |
| 36 | + type fields struct { |
| 37 | + provider config.Provider |
| 38 | + } |
| 39 | + tests := []struct { |
| 40 | + name string |
| 41 | + fields fields |
| 42 | + }{ |
| 43 | + { |
| 44 | + name: "successfully creates repository client with local filesystem backend and scheme == \"\"", |
| 45 | + fields: fields{ |
| 46 | + provider: config.NewProvider("provider-1", dst1, clusterctlv1.BootstrapProviderType), |
| 47 | + }, |
| 48 | + }, |
| 49 | + { |
| 50 | + name: "successfully creates repository client with local filesystem backend and scheme == \"file\"", |
| 51 | + fields: fields{ |
| 52 | + provider: config.NewProvider("provider-2", "file://"+dst2, clusterctlv1.BootstrapProviderType), |
| 53 | + }, |
| 54 | + }, |
| 55 | + } |
| 56 | + for _, tt := range tests { |
| 57 | + t.Run(tt.name, func(t *testing.T) { |
| 58 | + repoClient, err := newRepositoryClient(tt.fields.provider, test.NewFakeVariableClient()) |
| 59 | + if err != nil { |
| 60 | + t.Fatalf("got error %v when none was expected", err) |
| 61 | + } |
| 62 | + if _, ok := repoClient.repository.(*localRepository); !ok { |
| 63 | + t.Fatalf("got repository of type %v when *repository.localRepository was expected", reflect.TypeOf(repoClient.repository)) |
| 64 | + } |
| 65 | + }) |
| 66 | + } |
| 67 | +} |
0 commit comments