Skip to content

Commit

Permalink
Add data source tests for file
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Duchesne committed Dec 20, 2018
1 parent 331fb17 commit a4503eb
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 12 deletions.
59 changes: 59 additions & 0 deletions data_source_quantum_file_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package main

import (
"fmt"
"io/ioutil"
"os"
"testing"

r "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestFile_basic(t *testing.T) {
var cases = []struct {
path string
content string
config string
}{
{
"quantum_file",
"This is some content",
`data "quantum_file" "file" {
content = "This is some content"
filename = "quantum_file"
}`,
},
{
"quantum_file",
"This is some sensitive content",
`data "quantum_file" "file" {
sensitive_content = "This is some sensitive content"
filename = "quantum_file"
}`,
},
}

for _, tt := range cases {
r.UnitTest(t, r.TestCase{
Providers: testProviders,
Steps: []r.TestStep{
{
Config: tt.config,
Check: func(s *terraform.State) error {
content, err := ioutil.ReadFile(tt.path)
if err != nil {
return fmt.Errorf("config:\n%s\n,got: %s\n", tt.config, err)
}
if string(content) != tt.content {
return fmt.Errorf("config:\n%s\ngot:\n%s\nwant:\n%s\n", tt.config, content, tt.content)
}
return nil
},
},
},
})
}

os.Remove("quantum_file")
}
26 changes: 14 additions & 12 deletions provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ import (
"github.com/hashicorp/terraform/terraform"
)

func Provider() terraform.ResourceProvider {
return &schema.Provider{
DataSourcesMap: map[string]*schema.Resource{
"quantum_file": dataSourceQuantumFile(),
"quantum_query_json": dataSourceQuantumQueryJSON(),
"quantum_list_files": dataSourceQuantumListFiles(),
},
ResourcesMap: map[string]*schema.Resource{
"quantum_password": resourceQuantumPassword(),
},
}
}

func main() {
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: func() terraform.ResourceProvider {
return &schema.Provider{
DataSourcesMap: map[string]*schema.Resource{
"quantum_file": dataSourceQuantumFile(),
"quantum_query_json": dataSourceQuantumQueryJSON(),
"quantum_list_files": dataSourceQuantumListFiles(),
},
ResourcesMap: map[string]*schema.Resource{
"quantum_password": resourceQuantumPassword(),
},
}
},
ProviderFunc: Provider,
})
}
18 changes: 18 additions & 0 deletions provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"testing"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)

var testProviders = map[string]terraform.ResourceProvider{
"quantum": Provider(),
}

func TestProvider(t *testing.T) {
if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
}

0 comments on commit a4503eb

Please sign in to comment.