mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2026-02-02 09:25:08 +01:00
Fix typo in parseDependency name and add tests
This commit is contained in:
parent
95226f7f9b
commit
4630466006
3 changed files with 82 additions and 9 deletions
|
|
@ -46,14 +46,7 @@ func installCommand(dir, jsonnetHome string, paths ...string) int {
|
||||||
|
|
||||||
if len(paths) > 0 {
|
if len(paths) > 0 {
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
// install package specified in command
|
newDep := parseDependency(path)
|
||||||
// $ jsonnetpkg install ksonnet git@github.com:ksonnet/ksonnet-lib
|
|
||||||
// $ jsonnetpkg install grafonnet git@github.com:grafana/grafonnet-lib grafonnet
|
|
||||||
// $ jsonnetpkg install github.com/grafana/grafonnet-lib/grafonnet
|
|
||||||
//
|
|
||||||
// github.com/(slug)/(dir)
|
|
||||||
|
|
||||||
newDep := parseDepedency(path)
|
|
||||||
if newDep == nil {
|
if newDep == nil {
|
||||||
kingpin.Errorf("ignoring unrecognized path: %s", path)
|
kingpin.Errorf("ignoring unrecognized path: %s", path)
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ func Main() int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseDepedency(urlString string) *spec.Dependency {
|
func parseDependency(urlString string) *spec.Dependency {
|
||||||
if spec := parseGitSSHDependency(urlString); spec != nil {
|
if spec := parseGitSSHDependency(urlString); spec != nil {
|
||||||
return spec
|
return spec
|
||||||
}
|
}
|
||||||
|
|
|
||||||
80
cmd/jb/main_test.go
Normal file
80
cmd/jb/main_test.go
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
// Copyright 2018 jsonnet-bundler authors
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
// http://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.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jsonnet-bundler/jsonnet-bundler/spec"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestParseDepedency(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
path string
|
||||||
|
want *spec.Dependency
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Empty",
|
||||||
|
path: "",
|
||||||
|
want: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Invalid",
|
||||||
|
path: "github.com/foo",
|
||||||
|
want: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "GitHub",
|
||||||
|
path: "github.com/jsonnet-bundler/jsonnet-bundler",
|
||||||
|
want: &spec.Dependency{
|
||||||
|
Name: "jsonnet-bundler",
|
||||||
|
Source: spec.Source{
|
||||||
|
GitSource: &spec.GitSource{
|
||||||
|
Remote: "https://github.com/jsonnet-bundler/jsonnet-bundler",
|
||||||
|
Subdir: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Version: "master",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "SSH",
|
||||||
|
path: "git+ssh://git@github.com:jsonnet-bundler/jsonnet-bundler.git",
|
||||||
|
want: &spec.Dependency{
|
||||||
|
Name: "jsonnet-bundler",
|
||||||
|
Source: spec.Source{
|
||||||
|
GitSource: &spec.GitSource{
|
||||||
|
Remote: "git@github.com:jsonnet-bundler/jsonnet-bundler",
|
||||||
|
Subdir: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Version: "master",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
_ = t.Run(tt.name, func(t *testing.T) {
|
||||||
|
dependency := parseDependency(tt.path)
|
||||||
|
|
||||||
|
if tt.path == "" {
|
||||||
|
assert.Nil(t, dependency)
|
||||||
|
} else {
|
||||||
|
assert.Equal(t, tt.want, dependency)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue