-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcreatePolicyFile_test.go
More file actions
49 lines (40 loc) · 1.34 KB
/
createPolicyFile_test.go
File metadata and controls
49 lines (40 loc) · 1.34 KB
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 (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestValidateOutputFile_AcceptsYamlExtension(t *testing.T) {
dir := t.TempDir()
assert.NoError(t, validateOutputFile(filepath.Join(dir, "policy.yaml")))
}
func TestValidateOutputFile_AcceptsYmlExtension(t *testing.T) {
dir := t.TempDir()
assert.NoError(t, validateOutputFile(filepath.Join(dir, "policy.yml")))
}
func TestValidateOutputFile_AcceptsUppercaseExtension(t *testing.T) {
dir := t.TempDir()
assert.NoError(t, validateOutputFile(filepath.Join(dir, "policy.YAML")))
}
func TestValidateOutputFile_RejectsNonYamlExtension(t *testing.T) {
dir := t.TempDir()
err := validateOutputFile(filepath.Join(dir, "policy.json"))
require.Error(t, err)
assert.Contains(t, err.Error(), ".yaml or .yml")
}
func TestValidateOutputFile_RejectsNoExtension(t *testing.T) {
dir := t.TempDir()
err := validateOutputFile(filepath.Join(dir, "policy"))
require.Error(t, err)
assert.Contains(t, err.Error(), ".yaml or .yml")
}
func TestValidateOutputFile_RejectsExistingFile(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "existing.yaml")
require.NoError(t, os.WriteFile(path, []byte("test"), 0644))
err := validateOutputFile(path)
require.Error(t, err)
assert.Contains(t, err.Error(), "already exists")
}