|
| 1 | +package tfgen |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/stretchr/testify/require" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +func TestPlainDocsParser(t *testing.T) { |
| 9 | + t.Parallel() |
| 10 | + |
| 11 | + type testCase struct { |
| 12 | + // The name of the test case. |
| 13 | + name string |
| 14 | + docFile DocFile |
| 15 | + expected []byte |
| 16 | + g *Generator |
| 17 | + } |
| 18 | + |
| 19 | + tests := []testCase{ |
| 20 | + { |
| 21 | + name: "Replaces Upstream Front Matter With Pulumi Front Matter", |
| 22 | + docFile: DocFile{ |
| 23 | + Content: []byte("---\nlayout: \"openstack\"\npage_title: \"Provider: OpenStack\"\nsidebar_current: \"docs-openstack-index\"\ndescription: |-\n The OpenStack provider is used to interact with the many resources supported by OpenStack. The provider needs to be configured with the proper credentials before it can be used.\n---\n\n# OpenStack Provider\n\nThe OpenStack provider is used to interact with the\nmany resources supported by OpenStack. The provider needs to be configured\nwith the proper credentials before it can be used.\n\nUse the navigation to the left to read about the available resources."), |
| 24 | + }, |
| 25 | + expected: []byte("---\ntitle: OpenStack Provider Installation & Configuration\nmeta_desc: Provides an overview on how to configure the Pulumi OpenStack Provider.\nlayout: package\n---\n\nThe OpenStack provider is used to interact with the\nmany resources supported by OpenStack. The provider needs to be configured\nwith the proper credentials before it can be used.\n\nUse the navigation to the left to read about the available resources."), |
| 26 | + }, |
| 27 | + { |
| 28 | + name: "Writes Pulumi Style Front Matter If Not Present", |
| 29 | + docFile: DocFile{ |
| 30 | + Content: []byte("# Artifactory Provider\n\nThe [Artifactory](https://jfrog.com/artifactory/) provider is used to interact with the resources supported by Artifactory. The provider needs to be configured with the proper credentials before it can be used.\n\nLinks to documentation for specific resources can be found in the table of contents to the left.\n\nThis provider requires access to Artifactory APIs, which are only available in the _licensed_ pro and enterprise editions. You can determine which license you have by accessing the following the URL `${host}/artifactory/api/system/licenses/`.\n\nYou can either access it via API, or web browser - it require admin level credentials."), |
| 31 | + }, |
| 32 | + expected: []byte("---\ntitle: Artifactory Provider Installation & Configuration\nmeta_desc: Provides an overview on how to configure the Pulumi Artifactory Provider.\nlayout: package\n---\n\nThe [Artifactory](https://jfrog.com/artifactory/) provider is used to interact with the resources supported by Artifactory. The provider needs to be configured with the proper credentials before it can be used.\n\nLinks to documentation for specific resources can be found in the table of contents to the left.\n\nThis provider requires access to Artifactory APIs, which are only available in the _licensed_ pro and enterprise editions. You can determine which license you have by accessing the following the URL `${host}/artifactory/api/system/licenses/`.\n\nYou can either access it via API, or web browser - it require admin level credentials."), |
| 33 | + }, |
| 34 | + } |
| 35 | + for _, tt := range tests { |
| 36 | + tt := tt |
| 37 | + t.Run(tt.name, func(t *testing.T) { |
| 38 | + t.Skipf("this function is under development and will receive tests once all parts are completed") |
| 39 | + t.Parallel() |
| 40 | + g := &Generator{ |
| 41 | + sink: mockSink{t}, |
| 42 | + } |
| 43 | + actual, err := plainDocsParser(&tt.docFile, g) |
| 44 | + require.NoError(t, err) |
| 45 | + require.Equal(t, string(tt.expected), string(actual)) |
| 46 | + }) |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +func TestWriteInstallationInstructions(t *testing.T) { |
| 51 | + t.Parallel() |
| 52 | + |
| 53 | + type testCase struct { |
| 54 | + // The name of the test case. |
| 55 | + name string |
| 56 | + docFile DocFile |
| 57 | + goImportBasePath string |
| 58 | + packageName string |
| 59 | + expected string |
| 60 | + } |
| 61 | + |
| 62 | + tc := testCase{ |
| 63 | + |
| 64 | + name: "Generates Install Information From Package Name", |
| 65 | + expected: "## Installation\n\n" + |
| 66 | + "The testcase provider is available as a package in all Pulumi languages:\n\n" + |
| 67 | + "* JavaScript/TypeScript: [`@pulumi/testcase`](https://www.npmjs.com/package/@pulumi/testcase)\n" + |
| 68 | + "* Python: [`pulumi-testcase`](https://pypi.org/project/pulumi-testcase/)\n" + //TODO: get the Go mod version somehow :blood_sob: |
| 69 | + "* Go: [`github.com/pulumi/pulumi-testcase/sdk/v3/go/pulumi-testcase`](https://github.com/pulumi/pulumi-testcase)\n" + |
| 70 | + "* .NET: [`Pulumi.Testcase`](https://www.nuget.org/packages/Pulumi.Testcase)\n" + //TODO: use capitalized |
| 71 | + "* Java: [`com.pulumi/testcase`](https://central.sonatype.com/artifact/com.pulumi/testcase)\n\n", |
| 72 | + goImportBasePath: "github.com/pulumi/pulumi-testcase/sdk/v3/go/pulumi-testcase", |
| 73 | + packageName: "testcase", |
| 74 | + } |
| 75 | + |
| 76 | + t.Run(tc.name, func(t *testing.T) { |
| 77 | + t.Parallel() |
| 78 | + actual := writeInstallationInstructions(tc.goImportBasePath, tc.packageName) |
| 79 | + require.Equal(t, string(tc.expected), actual) |
| 80 | + }) |
| 81 | +} |
| 82 | + |
| 83 | +func TestWriteFrontMatter(t *testing.T) { |
| 84 | + t.Parallel() |
| 85 | + |
| 86 | + type testCase struct { |
| 87 | + // The name of the test case. |
| 88 | + name string |
| 89 | + docFile DocFile |
| 90 | + title string |
| 91 | + expected string |
| 92 | + } |
| 93 | + |
| 94 | + tc := testCase{ |
| 95 | + name: "Generates Front Matter for installation-configuration.md", |
| 96 | + title: "Testcase Provider", |
| 97 | + expected: delimiter + |
| 98 | + "title: Testcase Provider Installation & Configuration\n" + |
| 99 | + "meta_desc: Provides an overview on how to configure the Pulumi Testcase Provider.\n" + |
| 100 | + "layout: package\n" + |
| 101 | + delimiter + |
| 102 | + "\n", |
| 103 | + } |
| 104 | + |
| 105 | + t.Run(tc.name, func(t *testing.T) { |
| 106 | + t.Parallel() |
| 107 | + actual := writeFrontMatter(tc.title) |
| 108 | + require.Equal(t, tc.expected, actual) |
| 109 | + }) |
| 110 | +} |
| 111 | + |
| 112 | +func TestWriteIndexFrontMatter(t *testing.T) { |
| 113 | + t.Parallel() |
| 114 | + |
| 115 | + type testCase struct { |
| 116 | + // The name of the test case. |
| 117 | + name string |
| 118 | + docFile DocFile |
| 119 | + displayName string |
| 120 | + expected string |
| 121 | + } |
| 122 | + |
| 123 | + tc := testCase{ |
| 124 | + name: "Generates Front Matter for _index.md", |
| 125 | + displayName: "Testcase", |
| 126 | + expected: delimiter + |
| 127 | + "title: Testcase\n" + |
| 128 | + "meta_desc: The Testcase provider for Pulumi can be used to provision any of the cloud resources available in Testcase.\n" + |
| 129 | + "layout: package\n" + |
| 130 | + delimiter, |
| 131 | + } |
| 132 | + |
| 133 | + t.Run(tc.name, func(t *testing.T) { |
| 134 | + t.Parallel() |
| 135 | + actual := writeIndexFrontMatter(tc.displayName) |
| 136 | + require.Equal(t, tc.expected, actual) |
| 137 | + }) |
| 138 | +} |
0 commit comments