Skip to content

Commit

Permalink
Add overall test
Browse files Browse the repository at this point in the history
  • Loading branch information
guineveresaenger committed Nov 18, 2024
1 parent 79a989c commit f02a167
Show file tree
Hide file tree
Showing 4 changed files with 344 additions and 4 deletions.
10 changes: 10 additions & 0 deletions pkg/tfgen/installation_docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ func TestPlainDocsParser(t *testing.T) {
},
),
},
{
// Discovered while generating docs for SD-WAN.
// Tests whether the custom table renderer is used correctly in docsgen overall.
name: "Transforms table correctly",
docFile: DocFile{
Content: []byte(readfile(t, "test_data/convert-index-file-with-table/input.md")),
},
expected: []byte(readfile(t, "test_data/convert-index-file-with-table/expected.md")),
edits: defaultEditRules(),
},
}
for _, tt := range tests {
tt := tt
Expand Down
7 changes: 3 additions & 4 deletions pkg/tfgen/parse/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"strings"

"github.com/olekukonko/tablewriter"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen/parse/section"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
markdown "github.com/teekennedy/goldmark-markdown"
"github.com/yuin/goldmark"
Expand All @@ -30,6 +29,8 @@ import (
"github.com/yuin/goldmark/renderer"
"github.com/yuin/goldmark/text"
"github.com/yuin/goldmark/util"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen/parse/section"
)

// TFRegistryExtension is the catch-all extension to prepare TF registry markdown to be
Expand Down Expand Up @@ -162,7 +163,6 @@ func (tableRenderer *tableRenderer) renderTable(
tableRenderer.headerRow = make([]string, 0, tableRenderer.tableWidth)
tableRenderer.rows = [][]string{}
tableRenderer.tableWriter = tablewriter.NewWriter(writer)

} else {
_, err := writer.WriteRune('\n')
contract.AssertNoErrorf(err, "impossible")
Expand Down Expand Up @@ -196,7 +196,7 @@ func (tableRenderer *tableRenderer) renderRow(
entering bool,
) (ast.WalkStatus, error) {
if entering {
tableRenderer.rows = append(tableRenderer.rows, make([]string, 0, tableRenderer.tableWidth)) //TODO: call this table width
tableRenderer.rows = append(tableRenderer.rows, make([]string, 0, tableRenderer.tableWidth))
}

return ast.WalkContinue, nil
Expand All @@ -208,7 +208,6 @@ func (tableRenderer *tableRenderer) renderCell(
n ast.Node,
entering bool,
) (ast.WalkStatus, error) {

if entering {
var cell bytes.Buffer
textBlock := ast.NewTextBlock()
Expand Down
267 changes: 267 additions & 0 deletions pkg/tfgen/test_data/convert-index-file-with-table/expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
---
# *** WARNING: This file was auto-generated. Do not edit by hand unless you're certain you know what you are doing! ***
title: Libvirt Provider
meta_desc: Provides an overview on how to configure the Pulumi Libvirt provider.
layout: package
---
## Installation

The Libvirt provider is available as a package in all Pulumi languages:

* JavaScript/TypeScript: [`@pulumi/libvirt`](https://www.npmjs.com/package/@pulumi/libvirt)
* Python: [`pulumi-libvirt`](https://pypi.org/project/pulumi-libvirt/)
* Go: [`github.com/pulumi/pulumi-libvirt/sdk/go/libvirt`](https://github.com/pulumi/pulumi-libvirt)
* .NET: [`Pulumi.Libvirt`](https://www.nuget.org/packages/Pulumi.Libvirt)
* Java: [`com.pulumi/libvirt`](https://central.sonatype.com/artifact/com.pulumi/libvirt)
## Overview

The Libvirt provider is used to interact with Linux
[libvirt](https://libvirt.org) hypervisors.

The provider needs to be configured with the proper connection information
before it can be used.

| t1 | *t2* |
|----------|------|
| **r1c1** | r1c2 |

> **Note:** while libvirt can be used with several types of hypervisors, this
provider focuses on [KVM](http://libvirt.org/drvqemu.html). Other drivers may not be
working and haven't been tested.
## The connection URI

The provider understands [connection URIs](https://libvirt.org/uri.html). The supported transports are:

* `tcp` (non-encrypted connection)
* `unix` (UNIX domain socket)
* `tls` (See [here](https://libvirt.org/kbase/tlscerts.html) for information how to setup certificates)
* `ssh` (Secure shell)

Unlike the original libvirt, the `ssh` transport is not implemented using the ssh command and therefore does not require `nc` (netcat) on the server side.

Additionally, the `ssh` URI supports passwords using the `driver+ssh://[username:PASSWORD@][hostname][:port]/[path]?sshauth=ssh-password` syntax.

As the provider does not use libvirt on the client side, not all connection URI options are supported or apply.
## Example Usage

{{< chooser language "typescript,python,go,csharp,java,yaml" >}}
{{% choosable language typescript %}}
```yaml
# Pulumi.yaml provider configuration file
name: configuration-example
runtime: nodejs
config:
simple-provider:authUrl:
value: http://myauthurl:5000/v3
simple-provider:password:
value: pwd
simple-provider:region:
value: RegionOne
simple-provider:tenantName:
value: admin
simple-provider:userName:
value: admin

```
```typescript
import * as pulumi from "@pulumi/pulumi";
import * as simple from "@pulumi/simple";

//# Define a resource
const aResource = new simple.index.Resource("a_resource", {
inputOne: "hello",
inputTwo: true,
});
```
{{% /choosable %}}
{{% choosable language python %}}
```yaml
# Pulumi.yaml provider configuration file
name: configuration-example
runtime: python
config:
simple-provider:authUrl:
value: http://myauthurl:5000/v3
simple-provider:password:
value: pwd
simple-provider:region:
value: RegionOne
simple-provider:tenantName:
value: admin
simple-provider:userName:
value: admin

```
```python
import pulumi
import pulumi_simple as simple

## Define a resource
a_resource = simple.index.Resource("a_resource",
input_one=hello,
input_two=True)
```
{{% /choosable %}}
{{% choosable language csharp %}}
```yaml
# Pulumi.yaml provider configuration file
name: configuration-example
runtime: dotnet
config:
simple-provider:authUrl:
value: http://myauthurl:5000/v3
simple-provider:password:
value: pwd
simple-provider:region:
value: RegionOne
simple-provider:tenantName:
value: admin
simple-provider:userName:
value: admin

```
```csharp
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Simple = Pulumi.Simple;

return await Deployment.RunAsync(() =>
{
//# Define a resource
var aResource = new Simple.Index.Resource("a_resource", new()
{
InputOne = "hello",
InputTwo = true,
});

});

```
{{% /choosable %}}
{{% choosable language go %}}
```yaml
# Pulumi.yaml provider configuration file
name: configuration-example
runtime: go
config:
simple-provider:authUrl:
value: http://myauthurl:5000/v3
simple-provider:password:
value: pwd
simple-provider:region:
value: RegionOne
simple-provider:tenantName:
value: admin
simple-provider:userName:
value: admin

```
```go
package main

import (
"github.com/pulumi/pulumi-simple/sdk/go/simple"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
// # Define a resource
_, err := simple.NewResource(ctx, "a_resource", &simple.ResourceArgs{
InputOne: "hello",
InputTwo: true,
})
if err != nil {
return err
}
return nil
})
}
```
{{% /choosable %}}
{{% choosable language yaml %}}
```yaml
# Pulumi.yaml provider configuration file
name: configuration-example
runtime: yaml
config:
simple-provider:authUrl:
value: http://myauthurl:5000/v3
simple-provider:password:
value: pwd
simple-provider:region:
value: RegionOne
simple-provider:tenantName:
value: admin
simple-provider:userName:
value: admin

```
```yaml
resources:
## Define a resource
aResource:
type: simple:resource
name: a_resource
properties:
inputOne: hello
inputTwo: true
```
{{% /choosable %}}
{{% choosable language java %}}
```yaml
# Pulumi.yaml provider configuration file
name: configuration-example
runtime: java
config:
simple-provider:authUrl:
value: http://myauthurl:5000/v3
simple-provider:password:
value: pwd
simple-provider:region:
value: RegionOne
simple-provider:tenantName:
value: admin
simple-provider:userName:
value: admin

```
```java
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.simple.resource;
import com.pulumi.simple.ResourceArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}

public static void stack(Context ctx) {
//# Define a resource
var aResource = new Resource("aResource", ResourceArgs.builder()
.inputOne("hello")
.inputTwo(true)
.build());

}
}
```
{{% /choosable %}}
{{< /chooser >}}
## Configuration Reference

The following keys can be used to configure the provider.

* `uri` - (Required) The [connection URI](https://libvirt.org/uri.html) used
to connect to the libvirt host.
64 changes: 64 additions & 0 deletions pkg/tfgen/test_data/convert-index-file-with-table/input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
layout: "libvirt"
page_title: "Provider: libvirt"
sidebar_current: "docs-libvirt-index"
description: |-
The Libvirt provider is used to interact with Linux KVM/libvirt hypervisors. The provider needs to be configured with the proper connection information before it can be used.
---

# Libvirt Provider

The Libvirt provider is used to interact with Linux
[libvirt](https://libvirt.org) hypervisors.

The provider needs to be configured with the proper connection information
before it can be used.

|t1 | *t2* |
|------|------|
| **r1c1** | r1c2 |

~> **Note:** while libvirt can be used with several types of hypervisors, this
provider focuses on [KVM](http://libvirt.org/drvqemu.html). Other drivers may not be
working and haven't been tested.

## The connection URI

The provider understands [connection URIs](https://libvirt.org/uri.html). The supported transports are:

* `tcp` (non-encrypted connection)
* `unix` (UNIX domain socket)
* `tls` (See [here](https://libvirt.org/kbase/tlscerts.html) for information how to setup certificates)
* `ssh` (Secure shell)

Unlike the original libvirt, the `ssh` transport is not implemented using the ssh command and therefore does not require `nc` (netcat) on the server side.

Additionally, the `ssh` URI supports passwords using the `driver+ssh://[username:PASSWORD@][hostname][:port]/[path]?sshauth=ssh-password` syntax.

As the provider does not use libvirt on the client side, not all connection URI options are supported or apply.

## Example Usage

```hcl
# Configure the OpenStack Provider
provider "simple-provider" {
user_name = "admin"
tenant_name = "admin"
password = "pwd"
auth_url = "http://myauthurl:5000/v3"
region = "RegionOne"
}
## Define a resource
resource "simple_resource" "a_resource" {
input_one = "hello"
input_two = true
}
```

## Configuration Reference

The following keys can be used to configure the provider.

* `uri` - (Required) The [connection URI](https://libvirt.org/uri.html) used
to connect to the libvirt host.

0 comments on commit f02a167

Please sign in to comment.