Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests for bundle finder and http client #513

Merged
merged 3 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions pkg/kudoctl/bundle/finder/bundle_finder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package finder

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestManager_GetBundle(t *testing.T) {
f := &Manager{
kensipe marked this conversation as resolved.
Show resolved Hide resolved
local: NewLocal(),
uri: nil,
}
b, err := f.GetBundle("../testdata/zk", "")
kensipe marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
t.Errorf("Manager.GetBundle() error = %v", err)
return
}

crd, err := b.GetCRDs()
if err != nil {
t.Errorf("bundle.GetCRDs error = %v", err)
}
assert.EqualValues(t, "zookeeper", crd.Operator.Name)
}

func TestLocalFinder_GetBundle(t *testing.T) {
f := NewLocal()
b, err := f.GetBundle("../testdata/zk", "")
if err != nil {
t.Errorf("Manager.GetBundle() error = %v", err)
return
}

crd, err := b.GetCRDs()
if err != nil {
t.Errorf("bundle.GetCRDs error = %v", err)
}
assert.EqualValues(t, "zookeeper", crd.Operator.Name)
}

func TestLocalFinder_Failure(t *testing.T) {
f := NewLocal()
_, err := f.GetBundle("../testdata/zk-bad", "")
assert.Errorf(t, err, "should have errored on bad folder name")
}
26 changes: 26 additions & 0 deletions pkg/kudoctl/http/http_client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package http

import (
"testing"
)

func TestIsValidURL(t *testing.T) {

tests := []struct {
name string
uri string
want bool
}{
{name: "string", uri: "foo", want: false},
{name: "http", uri: "http://kudo.dev", want: true},
{name: "https", uri: "https://kudo.dev", want: true},
{name: "no http prefix", uri: "kudo.dev", want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsValidURL(tt.uri); got != tt.want {
t.Errorf("IsValidURL() = %v, want %v", got, tt.want)
}
})
}
}