Skip to content

Commit

Permalink
repo: add tests for json and yaml index options
Browse files Browse the repository at this point in the history
Signed-off-by: MeurillonGuillaume <[email protected]>
  • Loading branch information
MeurillonGuillaume committed Dec 7, 2023
1 parent a1f1d03 commit bd79a7a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/repo/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ limitations under the License.
package repo

import (
"encoding/json"
"fmt"
"testing"
"time"

"strings"

"github.com/stretchr/testify/suite"
"sigs.k8s.io/yaml"

"helm.sh/helm/v3/pkg/chart"
helm_repo "helm.sh/helm/v3/pkg/repo"
Expand Down Expand Up @@ -119,6 +121,27 @@ func (suite *IndexTestSuite) TestServerInfo() {
suite.True(strings.Contains(string(index.Raw), "contextPath: /v1/helm"), "context path is in index")
}

func (suite *IndexTestSuite) TestYAMLIndex() {
index := NewIndex("", "", &ServerInfo{}, false)
chartVersion := getChartVersion("a", 0, time.Now())
index.AddEntry(chartVersion)
suite.NoError(index.Regenerate())

suite.False(json.Valid(index.Raw))
suite.NoError(yaml.Unmarshal(index.Raw, &IndexFile{}))
}

func (suite *IndexTestSuite) TestJSONIndex() {
index := NewIndex("", "", &ServerInfo{}, true)
chartVersion := getChartVersion("a", 0, time.Now())
index.AddEntry(chartVersion)
suite.NoError(index.Regenerate())

// Since YAML is a superset of JSON, any valid JSON should be valid YAML
suite.True(json.Valid(index.Raw))
suite.NoError(yaml.Unmarshal(index.Raw, &IndexFile{}))
}

func TestIndexTestSuite(t *testing.T) {
suite.Run(t, new(IndexTestSuite))
}

0 comments on commit bd79a7a

Please sign in to comment.