Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

tests(data): added test coverage to data package #16

Merged
merged 1 commit into from
Sep 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
35 changes: 35 additions & 0 deletions src/api/data/charts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package data

import (
"testing"

"github.com/arschles/assert"
)

const (
repoName = "stable"
chartName = "apache"
)

func TestGetChart(t *testing.T) {
chart, err := GetChart(repoName, chartName)
assert.NoErr(t, err)
assert.Equal(t, *chart.ID, repoName+"/"+chartName, "chart ID")
chart, err = GetChart("bogon", chartName)
assert.ExistsErr(t, err, "sent bogus repo name to GetChart")
assert.Nil(t, chart.ID, "zero value ID")
}

func TestGetAllCharts(t *testing.T) {
_, err := GetAllCharts()
assert.NoErr(t, err)
}

func TestGetChartsInRepo(t *testing.T) {
charts, err := GetChartsInRepo(repoName)
assert.NoErr(t, err)
assert.True(t, len(charts) > 0, "returned charts")
noCharts, err := GetChartsInRepo("bogon")
assert.ExistsErr(t, err, "sent bogus repo name to GetChartsInRepo")
assert.True(t, len(noCharts) == 0, "empty charts slice")
}
17 changes: 12 additions & 5 deletions src/api/mocks/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import (
func GetChartFromMockRepo(repo, chartName string) (models.Resource, error) {
var ret models.Resource
y, err := getMockRepo(repo)
if err != nil {
return ret, err
}
charts, err := helpers.ParseYAMLRepo(y)
if err != nil {
log.Fatalf("couldn't parse mock repo!")
log.Printf("couldn't parse mock repo %s!\n", repo)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol... Fatalf is evil.

return ret, err
}
chart, err := helpers.GetLatestChartVersion(charts, chartName)
Expand All @@ -33,7 +36,7 @@ func GetAllChartsFromMockRepos() ([]*models.Resource, error) {
y, err := getMockRepo(repo)
charts, err := helpers.ParseYAMLRepo(y)
if err != nil {
log.Fatalf("couldn't parse mock repo!")
log.Printf("couldn't parse mock repo %s!\n", repo)
return ret, err
}
for _, chart := range charts {
Expand All @@ -48,9 +51,12 @@ func GetAllChartsFromMockRepos() ([]*models.Resource, error) {
func GetChartsFromMockRepo(repo string) ([]*models.Resource, error) {
var ret []*models.Resource
y, err := getMockRepo(repo)
if err != nil {
return ret, err
}
charts, err := helpers.ParseYAMLRepo(y)
if err != nil {
log.Fatalf("couldn't parse mock repo %s!\n", repo)
log.Printf("couldn't parse mock repo %s!\n", repo)
return ret, err
}
for _, chart := range charts {
Expand All @@ -62,9 +68,10 @@ func GetChartsFromMockRepo(repo string) ([]*models.Resource, error) {

// getMockRepo is a convenience that loads a yaml repo from the filesystem
func getMockRepo(repo string) ([]byte, error) {
y, err := getYAML(getMocksWd() + fmt.Sprintf("repo-%s.yaml", repo))
path := getMocksWd() + fmt.Sprintf("repo-%s.yaml", repo)
y, err := getYAML(path)
if err != nil {
log.Fatalf("couldn't load mock repo %s!\n", repo)
log.Printf("couldn't load mock repo %s!\n", path)
return nil, err
}
return y, nil
Expand Down