2020-04-01 09:55:42 -05:00
|
|
|
/*
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
Split document model, add entrypoints for repos
Add NewBundleByPath function, that would return bundle built from
the specified path argument
Add CurrentContextEntryPoint method of the config
object, that would allow easily get kustomize root path based on
clusterType and phase. You can also leave phase arg empty string,
which would try to return bundle for all phases
Introduce changes to config pakage objects:
- Manifest:
SubPath: this is relative path to the root of the repository that
contains directories with sites (SiteNames)
PrimaryRepositoryName: this is a string that must correspond to a key
of the Repositories map of manifest object, which is used to derive
primary repository
Repositories object is a map, map keys correspond to names of the
directories where `document pull` command will download repositories
defined in manifest prepended by manifest.TargetPath.
Introduce new config method CurrentContextEntryPoint(), method takes
TargetPath, PrimaryRepo.URL, SubPath, and clusterType and phase
constructs a path to the entry point out of which the DocumentBundle
should be build, and returns it to the caller. After that caller can
build a bundle out of it, the bundle will contain documents relevant to
particular cluster-type and phase.
All objects that depend on bundle interface are updated to use the
CurrentContextEntryPoint() method of the config object
Relates-To: #99
Closes: #99
Change-Id: I99320c4cb626841d46f4c298b583e9af90b1dce4
2020-03-06 00:48:50 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGitDirNameFromURL(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
input string
|
|
|
|
expectedOutput string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
input: "https://github.com/kubernetes/kubectl.git",
|
|
|
|
expectedOutput: "kubectl",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "git@github.com:kubernetes/kubectl.git",
|
|
|
|
expectedOutput: "kubectl",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "https://github.com/kubernetes/kube.somepath.ctl.git",
|
|
|
|
expectedOutput: "kube.somepath.ctl",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "https://github.com/kubernetes/kubectl",
|
|
|
|
expectedOutput: "kubectl",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "git@github.com:kubernetes/kubectl",
|
|
|
|
expectedOutput: "kubectl",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "github.com:kubernetes/kubectl.git",
|
|
|
|
expectedOutput: "kubectl",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "/kubernetes/kubectl.git",
|
|
|
|
expectedOutput: "kubectl",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "/kubernetes/kubectl.git/",
|
|
|
|
expectedOutput: "",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
assert.Equal(t, test.expectedOutput, GitDirNameFromURL(test.input))
|
|
|
|
}
|
|
|
|
}
|