forked from alexandrst88/terraform-variables-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator_test.go
49 lines (40 loc) · 1.02 KB
/
generator_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"bufio"
"os"
"testing"
)
var mockFile = "tf_configuration.mock"
var testExtFile = "*.mock"
func TestContainsElement(t *testing.T) {
testSlice := []string{"Terraform", "Puppet", "Ansible"}
if containsElement(testSlice, "Chef") {
t.Error("Should return false, but return true")
}
}
func TestGetAllFiles(t *testing.T) {
files, err := getAllFiles(testExtFile)
checkError(err)
if len(files) == 0 {
t.Error("Should found at least one file")
}
}
func TestMatchVariable(t *testing.T) {
ter := &terraformVars{}
var messages []string
file, err := getAllFiles(testExtFile)
checkError(err)
fileHandle, _ := os.Open(file[0])
defer fileHandle.Close()
fileScanner := bufio.NewScanner(fileHandle)
for fileScanner.Scan() {
messages = append(messages, fileScanner.Text())
}
for _, text := range messages {
ter.matchVarPref(text, varPrefix)
}
if len(ter.Variables) != 5 {
t.Errorf("Should return five variable. but returned %d", len(ter.Variables))
t.Errorf("Variables found: %s", ter.Variables)
}
}