Skip to content

Commit

Permalink
fix: remove var env dependency by moving tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nepo26 committed Sep 10, 2023
1 parent 913cc49 commit 3f2182a
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 13 deletions.
18 changes: 5 additions & 13 deletions pkg/helm/chart_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/norwoodj/helm-docs/pkg/helm"
"github.com/spf13/viper"
"github.com/stretchr/testify/suite"
"os"
"path/filepath"
"regexp"
"testing"
Expand All @@ -18,27 +17,20 @@ func (_ *ChartParsingTestSuite) SetupTest() {
viper.Set("values-file", "values.yaml")
}

func (suite *ChartParsingTestSuite) resolveRelativePath(chartPath string) string {
projectRoot := os.Getenv("PROJECT_ROOT")
if projectRoot == "" {
suite.T().Fatal("PROJECT_ROOT environment variable is not set")
}
return filepath.Join(projectRoot, chartPath)
}
func TestChartParsingTestSuite(t *testing.T) {
suite.Run(t, new(ChartParsingTestSuite))
}

func (suite *ChartParsingTestSuite) TestNotFullyDocumentedChartStrictModeOff() {
chartPath := suite.resolveRelativePath("example-charts/full-template/")
chartPath := filepath.Join("test-fixtures", "full-template")
_, err := helm.ParseChartInformation(chartPath, helm.ChartValuesDocumentationParsingConfig{
StrictMode: false,
})
suite.NoError(err)
}

func (suite *ChartParsingTestSuite) TestNotFullyDocumentedChartStrictModeOn() {
chartPath := suite.resolveRelativePath("example-charts/full-template/")
chartPath := filepath.Join("test-fixtures", "full-template")
_, err := helm.ParseChartInformation(chartPath, helm.ChartValuesDocumentationParsingConfig{
StrictMode: true,
})
Expand All @@ -61,7 +53,7 @@ controller.service.type`
}

func (suite *ChartParsingTestSuite) TestNotFullyDocumentedChartStrictModeOnIgnores() {
chartPath := suite.resolveRelativePath("example-charts/full-template/")
chartPath := filepath.Join("test-fixtures", "full-template")
_, err := helm.ParseChartInformation(chartPath, helm.ChartValuesDocumentationParsingConfig{
StrictMode: true,
AllowedMissingValuePaths: []string{
Expand All @@ -85,7 +77,7 @@ func (suite *ChartParsingTestSuite) TestNotFullyDocumentedChartStrictModeOnIgnor
}

func (suite *ChartParsingTestSuite) TestNotFullyDocumentedChartStrictModeOnIgnoresRegexp() {
chartPath := suite.resolveRelativePath("example-charts/full-template/")
chartPath := filepath.Join("test-fixtures", "full-template")
_, err := helm.ParseChartInformation(chartPath, helm.ChartValuesDocumentationParsingConfig{
StrictMode: true,
AllowedMissingValueRegexps: []*regexp.Regexp{
Expand All @@ -96,7 +88,7 @@ func (suite *ChartParsingTestSuite) TestNotFullyDocumentedChartStrictModeOnIgnor
}

func (suite *ChartParsingTestSuite) TestFullyDocumentedChartStrictModeOn() {
chartPath := suite.resolveRelativePath("example-charts/fully-documented/")
chartPath := filepath.Join("test-fixtures", "fully-documented")
_, err := helm.ParseChartInformation(chartPath, helm.ChartValuesDocumentationParsingConfig{
StrictMode: true,
})
Expand Down
19 changes: 19 additions & 0 deletions pkg/helm/test-fixtures/full-template/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v2
name: full-template
deprecated: true
version: "1.0.0"
type: application
appVersion: "13.0.0"
description: A chart for showing every README-element
home: "https://github.com/norwoodj/helm-docs/tree/master/example-charts/full-template"
maintainers:
- email: [email protected]
name: John Norwood
sources: ["https://github.com/norwoodj/helm-docs/tree/master/example-charts/full-template"]
kubeVersion: "<=1.18"
engine: gotpl

dependencies:
- name: nginx-ingress
version: "0.22.1"
repository: "@stable"
166 changes: 166 additions & 0 deletions pkg/helm/test-fixtures/full-template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# full-template

## `extra.flower`
```
,-.
, ,-. ,-.
/ \ ( )-( )
\ | ,.>-( )-<
\|,' ( )-( )
Y ___`-' `-'
|/__/ `-'
|
|
| -hi-
__|_____________
```

## `chart.deprecationWarning`
> **:exclamation: This Helm Chart is deprecated!**
## `chart.name`

full-template

## `chart.description`

A chart for showing every README-element

## `chart.version`

1.0.0

## `chart.versionBadge`

![Version: 1.0.0](https://img.shields.io/badge/Version-1.0.0-informational?style=flat-square)

## `chart.type`

application

## `chart.typeBadge`

![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)

## `chart.appVersion`

13.0.0

## `chart.appVersionBadge`

![AppVersion: 13.0.0](https://img.shields.io/badge/AppVersion-13.0.0-informational?style=flat-square)

## `chart.badgesSection`

![Version: 1.0.0](https://img.shields.io/badge/Version-1.0.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 13.0.0](https://img.shields.io/badge/AppVersion-13.0.0-informational?style=flat-square)

## `chart.homepage`

https://github.com/norwoodj/helm-docs/tree/master/example-charts/full-template

## `chart.homepageLine`

**Homepage:** <https://github.com/norwoodj/helm-docs/tree/master/example-charts/full-template>

## `chart.maintainersHeader`

## Maintainers

## `chart.maintainersTable`

| Name | Email | Url |
| ---- | ------ | --- |
| John Norwood | <[email protected]> | |

## `chart.maintainersSection`

## Maintainers

| Name | Email | Url |
| ---- | ------ | --- |
| John Norwood | <[email protected]> | |

## `chart.sourcesHeader`

## Source Code

## `chart.sourcesList`

* <https://github.com/norwoodj/helm-docs/tree/master/example-charts/full-template>

## `chart.sourcesSection`

## Source Code

* <https://github.com/norwoodj/helm-docs/tree/master/example-charts/full-template>

## `chart.kubeVersion`

<=1.18

## `chart.kubeVersionLine`

Kubernetes: `<=1.18`

## `chart.requirementsHeader`

## Requirements

## `chart.requirementsTable`

| Repository | Name | Version |
|------------|------|---------|
| @stable | nginx-ingress | 0.22.1 |

## `chart.requirementsSection`

## Requirements

Kubernetes: `<=1.18`

| Repository | Name | Version |
|------------|------|---------|
| @stable | nginx-ingress | 0.22.1 |

## `chart.valuesHeader`

## Values

## `chart.valuesTable`

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| controller.extraVolumes[0].configMap.name | string | `"nginx-ingress-config"` | Uses the name of the configmap created by this chart |
| controller.extraVolumes[0].name | string | `"config-volume"` | |
| controller.image.repository | string | `"nginx-ingress-controller"` | |
| controller.image.tag | string | `"18.0831"` | |
| controller.ingressClass | string | `"nginx"` | Name of the ingress class to route through this controller |
| controller.name | string | `"controller"` | |
| controller.persistentVolumeClaims | list | the chart will construct this list internally unless specified | List of persistent volume claims to create. For very long comments, break them into multiple lines. |
| controller.podLabels | object | `{}` | The labels to be applied to instances of the controller pod |
| controller.publishService.enabled | bool | `false` | Whether to expose the ingress controller to the public world |
| controller.replicas | int | `nil` | Number of nginx-ingress pods to load balance between |
| controller.service.annotations."external-dns.alpha.kubernetes.io/hostname" | string | `"stupidchess.jmn23.com"` | Hostname to be assigned to the ELB for the service |
| controller.service.type | string | `"LoadBalancer"` | |

## `chart.valuesSection`

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| controller.extraVolumes[0].configMap.name | string | `"nginx-ingress-config"` | Uses the name of the configmap created by this chart |
| controller.extraVolumes[0].name | string | `"config-volume"` | |
| controller.image.repository | string | `"nginx-ingress-controller"` | |
| controller.image.tag | string | `"18.0831"` | |
| controller.ingressClass | string | `"nginx"` | Name of the ingress class to route through this controller |
| controller.name | string | `"controller"` | |
| controller.persistentVolumeClaims | list | the chart will construct this list internally unless specified | List of persistent volume claims to create. For very long comments, break them into multiple lines. |
| controller.podLabels | object | `{}` | The labels to be applied to instances of the controller pod |
| controller.publishService.enabled | bool | `false` | Whether to expose the ingress controller to the public world |
| controller.replicas | int | `nil` | Number of nginx-ingress pods to load balance between |
| controller.service.annotations."external-dns.alpha.kubernetes.io/hostname" | string | `"stupidchess.jmn23.com"` | Hostname to be assigned to the ELB for the service |
| controller.service.type | string | `"LoadBalancer"` | |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.11.0](https://github.com/norwoodj/helm-docs/releases/v1.11.0)
111 changes: 111 additions & 0 deletions pkg/helm/test-fixtures/full-template/README.md.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{{ template "chart.header" . }}


## `extra.flower`
{{ template "extra.flower" . }}

## `chart.deprecationWarning`
{{ template "chart.deprecationWarning" . }}

## `chart.name`

{{ template "chart.name" . }}

## `chart.description`

{{ template "chart.description" . }}

## `chart.version`

{{ template "chart.version" . }}

## `chart.versionBadge`

{{ template "chart.versionBadge" . }}

## `chart.type`

{{ template "chart.type" . }}


## `chart.typeBadge`

{{ template "chart.typeBadge" . }}

## `chart.appVersion`

{{ template "chart.appVersion" . }}

## `chart.appVersionBadge`

{{ template "chart.appVersionBadge" . }}

## `chart.badgesSection`

{{ template "chart.badgesSection" . }}

## `chart.homepage`

{{ template "chart.homepage" . }}

## `chart.homepageLine`

{{ template "chart.homepageLine" . }}

## `chart.maintainersHeader`

{{ template "chart.maintainersHeader" . }}

## `chart.maintainersTable`

{{ template "chart.maintainersTable" . }}

## `chart.maintainersSection`

{{ template "chart.maintainersSection" . }}

## `chart.sourcesHeader`

{{ template "chart.sourcesHeader" . }}

## `chart.sourcesList`

{{ template "chart.sourcesList" . }}

## `chart.sourcesSection`

{{ template "chart.sourcesSection" . }}

## `chart.kubeVersion`

{{ template "chart.kubeVersion" . }}

## `chart.kubeVersionLine`

{{ template "chart.kubeVersionLine" . }}

## `chart.requirementsHeader`

{{ template "chart.requirementsHeader" . }}

## `chart.requirementsTable`

{{ template "chart.requirementsTable" . }}

## `chart.requirementsSection`

{{ template "chart.requirementsSection" . }}

## `chart.valuesHeader`

{{ template "chart.valuesHeader" . }}

## `chart.valuesTable`

{{ template "chart.valuesTable" . }}

## `chart.valuesSection`

{{ template "chart.valuesSection" . }}

{{ template "helm-docs.versionFooter" . }}
Loading

0 comments on commit 3f2182a

Please sign in to comment.