-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Julien Duchesne
committed
Dec 20, 2018
1 parent
331fb17
commit a4503eb
Showing
3 changed files
with
91 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |