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

Commit

Permalink
ref(data): incorporates latest changes to index.yml spec (#27)
Browse files Browse the repository at this point in the history
* ref(data): incorporates latest changes to index.yml spec

Of especial notice:

- data model property changes: 'checksum' becomes 'digest', 'url' becomes a 'urls' array, a new 'sources' array
- helper conveniences updated to handle new data models
- mock data updated to reflect new index.yml spec

* (fix): avoid variable shadowing
  • Loading branch information
jackfrancis authored Oct 18, 2016
1 parent 06fff2a commit 516a561
Show file tree
Hide file tree
Showing 8 changed files with 404 additions and 216 deletions.
25 changes: 15 additions & 10 deletions src/api/data/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ func ParseYAMLRepo(rawYAML []byte) ([]*models.ChartVersion, error) {
if err := yaml.Unmarshal(rawYAML, &repo); err != nil {
return nil, err
}
entries := repo["entries"]
if entries == nil {
return nil, fmt.Errorf("error parsing entries from YAMLified repo")
}
e, _ := yaml.Marshal(&entries)
chartEntries := make(map[string][]models.ChartVersion)
if err := yaml.Unmarshal(e, &chartEntries); err != nil {
return nil, err
}
var charts []*models.ChartVersion
for chartVersion := range repo {
cV := repo[chartVersion]
// we drop the error response because we can never enter into this error state:
// 1. "repo" is statically produced above
// 2. the key value at "cV" is a resilient, yaml-marshallable interface: it was unmarshalled from yaml above
c, _ := yaml.Marshal(&cV)
var chart models.ChartVersion
if err := yaml.Unmarshal(c, &chart); err != nil {
return nil, err
for entry := range chartEntries {
for i := range chartEntries[entry] {
charts = append(charts, &chartEntries[entry][i])
}
charts = append(charts, &chart)
}
return charts, nil
}
Expand All @@ -51,7 +53,10 @@ func MakeChartResource(chart *models.ChartVersion, repo string) *models.Resource
Name: chart.Name,
Description: chart.Description,
Created: chart.Created,
Digest: chart.Digest,
Home: chart.Home,
Sources: chart.Sources,
Urls: chart.Urls,
}
return &ret
}
Expand Down
34 changes: 21 additions & 13 deletions src/api/data/helpers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ const (
repoName = "stable"
chartName = "apache"
chartURL = "https://storage.googleapis.com/kubernetes-charts/apache-0.0.1.tgz"
chartCreated = "2016-05-26 11:23:44.086354411 +0000 UTC"
chartChecksum = "68eb4f96567c1d5fa9417b2bb9b9cbb2"
chartSource = "https://github.com/kubernetes/charts/apache"
chartCreated = "2016-10-06T16:23:20.499814565-06:00"
chartDigest = "99c76e403d752c84ead610644d4b1c2f2b453a74b921f422b9dcb8a7c8b559cd"
chartDescription = "Chart for Apache HTTP Server"
chartVersion = "0.0.1"
chartHome = "https://github.com/kubernetes/charts/apache"
chartHome = "https://k8s.io/helm"
)

func TestIsYAML(t *testing.T) {
Expand All @@ -33,12 +34,13 @@ func TestParseYAMLRepo(t *testing.T) {
assert.NoErr(t, err)
assert.Equal(t, len(charts), 1, "charts slice response from ParseYAMLRepo")
assert.Equal(t, *charts[0].Name, chartName, "chart name field value")
assert.Equal(t, *charts[0].URL, chartURL, "chart URL field value")
assert.Equal(t, *charts[0].Created, chartCreated, "chart created field value")
assert.Equal(t, *charts[0].Checksum, chartChecksum, "chart checksum field value")
assert.Equal(t, *charts[0].Digest, chartDigest, "chart checksum field value")
assert.Equal(t, *charts[0].Description, chartDescription, "chart description field value")
assert.Equal(t, *charts[0].Version, chartVersion, "chart version field value")
assert.Equal(t, *charts[0].Home, chartHome, "chart home field value")
//assert.Equal(t, *charts[0].Urls[0], chartURL, "chart URL field value")
//assert.Equal(t, *charts[0].Sources[0], chartSource, "chart URL field value")
_, err = ParseYAMLRepo([]byte(fmt.Sprintf(`this is not yaml`)))
assert.ExistsErr(t, err, "sent something not yaml to ParseYAMLRepo")
_, err = ParseYAMLRepo([]byte(fmt.Sprintf(`andy: kaufman`)))
Expand Down Expand Up @@ -132,12 +134,18 @@ func TestStrToPtr(t *testing.T) {

func getTestRepoYAML() []byte {
return []byte(fmt.Sprintf(`
%s-%s:
name: %s
url: %s
created: %s
checksum: %s
description: %s
version: %s
home: %s`, chartName, chartVersion, chartName, chartURL, chartCreated, chartChecksum, chartDescription, chartVersion, chartHome))
apiVersion: v1
entries:
apache:
- created: %s
description: %s
digest: %s
home: %s
name: %s
sources:
- %s
urls:
- %s
version: %s
generated: 2016-10-06T16:23:20.499029981-06:00`, chartCreated, chartDescription, chartDigest, chartHome, chartName, chartSource, chartURL, chartVersion))
}
41 changes: 25 additions & 16 deletions src/api/mocks/testdata/repo-incubator.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
mysql-0.3.0:
name: mysql
url: https://storage.googleapis.com/incubator-charts/mysql-0.3.0.tgz
created: 2016-05-26 11:23:44.086354411 +0000 UTC
checksum: 2cea3987cf85d588204e1b1cc0674472b4517919
description: Deploy a basic mysql pod
version: 0.3.0
home: https://github.com/kubernetes/charts/incubator/mysql
zookeeper-0.1.0:
name: zookeeper
url: https://storage.googleapis.com/incubator-charts/zookeeper-0.1.0.tgz
created: 2016-05-26 11:23:44.086354411 +0000 UTC
checksum: a61575c2d3160e5e39abf2a5ec984d6119404d13
description: Deploy a basic Zookeeper pod
version: 0.1.0
home: https://github.com/kubernetes/charts/incubator/zookeeper
apiVersion: v1
entries:
mysql:
- created: 2016-10-06T16:23:20.499814565-06:00
description: Deploy a basic mysql pod
digest: 99c76e403d752c84ead610644d4b1c2f2b453a74b921f422b9dcb8a7c8b559cd
home: https://k8s.io/helm
name: mysql
sources:
- https://github.com/kubernetes/charts/incubator/mysql
urls:
- https://storage.googleapis.com/incubator-charts/mysql-0.3.0.tgz
version: 0.3.0
zookeeper:
- created: 2016-10-06T16:23:20.499814565-06:00
description: Deploy a basic Zookeeper pod
digest: 99c76e403d752c84ead610644d4b1c2f2b453a74b921f422b9dcb8a7c8b559cd
home: https://k8s.io/helm
name: zookeeper
sources:
- https://github.com/kubernetes/charts/incubator/zookeeper
urls:
- https://storage.googleapis.com/incubator-charts/zookeeper-0.1.0.tgz
version: 0.1.0
generated: 2016-10-06T16:23:20.499029981-06:00
Loading

0 comments on commit 516a561

Please sign in to comment.