mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Fix audit unit test file location
This commit is contained in:
parent
a4e5239bdc
commit
91e5d98b57
@ -21,6 +21,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
@ -33,6 +34,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestAuditValidOptions(t *testing.T) {
|
func TestAuditValidOptions(t *testing.T) {
|
||||||
|
tmpDir := t.TempDir()
|
||||||
|
auditPath := filepath.Join(tmpDir, "audit")
|
||||||
|
|
||||||
webhookConfig := makeTmpWebhookConfig(t)
|
webhookConfig := makeTmpWebhookConfig(t)
|
||||||
defer os.Remove(webhookConfig)
|
defer os.Remove(webhookConfig)
|
||||||
|
|
||||||
@ -50,7 +54,7 @@ func TestAuditValidOptions(t *testing.T) {
|
|||||||
name: "default log",
|
name: "default log",
|
||||||
options: func() *AuditOptions {
|
options: func() *AuditOptions {
|
||||||
o := NewAuditOptions()
|
o := NewAuditOptions()
|
||||||
o.LogOptions.Path = "/audit"
|
o.LogOptions.Path = auditPath
|
||||||
o.PolicyFile = policy
|
o.PolicyFile = policy
|
||||||
return o
|
return o
|
||||||
},
|
},
|
||||||
@ -59,7 +63,7 @@ func TestAuditValidOptions(t *testing.T) {
|
|||||||
name: "default log no policy",
|
name: "default log no policy",
|
||||||
options: func() *AuditOptions {
|
options: func() *AuditOptions {
|
||||||
o := NewAuditOptions()
|
o := NewAuditOptions()
|
||||||
o.LogOptions.Path = "/audit"
|
o.LogOptions.Path = auditPath
|
||||||
return o
|
return o
|
||||||
},
|
},
|
||||||
expected: "",
|
expected: "",
|
||||||
@ -94,7 +98,7 @@ func TestAuditValidOptions(t *testing.T) {
|
|||||||
name: "default union",
|
name: "default union",
|
||||||
options: func() *AuditOptions {
|
options: func() *AuditOptions {
|
||||||
o := NewAuditOptions()
|
o := NewAuditOptions()
|
||||||
o.LogOptions.Path = "/audit"
|
o.LogOptions.Path = auditPath
|
||||||
o.WebhookOptions.ConfigFile = webhookConfig
|
o.WebhookOptions.ConfigFile = webhookConfig
|
||||||
o.PolicyFile = policy
|
o.PolicyFile = policy
|
||||||
return o
|
return o
|
||||||
@ -105,7 +109,7 @@ func TestAuditValidOptions(t *testing.T) {
|
|||||||
options: func() *AuditOptions {
|
options: func() *AuditOptions {
|
||||||
o := NewAuditOptions()
|
o := NewAuditOptions()
|
||||||
o.LogOptions.BatchOptions.Mode = ModeBatch
|
o.LogOptions.BatchOptions.Mode = ModeBatch
|
||||||
o.LogOptions.Path = "/audit"
|
o.LogOptions.Path = auditPath
|
||||||
o.WebhookOptions.BatchOptions.Mode = ModeBlocking
|
o.WebhookOptions.BatchOptions.Mode = ModeBlocking
|
||||||
o.WebhookOptions.ConfigFile = webhookConfig
|
o.WebhookOptions.ConfigFile = webhookConfig
|
||||||
o.PolicyFile = policy
|
o.PolicyFile = policy
|
||||||
@ -148,6 +152,9 @@ func TestAuditValidOptions(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAuditInvalidOptions(t *testing.T) {
|
func TestAuditInvalidOptions(t *testing.T) {
|
||||||
|
tmpDir := t.TempDir()
|
||||||
|
auditPath := filepath.Join(tmpDir, "audit")
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
options func() *AuditOptions
|
options func() *AuditOptions
|
||||||
@ -155,7 +162,7 @@ func TestAuditInvalidOptions(t *testing.T) {
|
|||||||
name: "invalid log format",
|
name: "invalid log format",
|
||||||
options: func() *AuditOptions {
|
options: func() *AuditOptions {
|
||||||
o := NewAuditOptions()
|
o := NewAuditOptions()
|
||||||
o.LogOptions.Path = "/audit"
|
o.LogOptions.Path = auditPath
|
||||||
o.LogOptions.Format = "foo"
|
o.LogOptions.Format = "foo"
|
||||||
return o
|
return o
|
||||||
},
|
},
|
||||||
@ -163,7 +170,7 @@ func TestAuditInvalidOptions(t *testing.T) {
|
|||||||
name: "invalid log mode",
|
name: "invalid log mode",
|
||||||
options: func() *AuditOptions {
|
options: func() *AuditOptions {
|
||||||
o := NewAuditOptions()
|
o := NewAuditOptions()
|
||||||
o.LogOptions.Path = "/audit"
|
o.LogOptions.Path = auditPath
|
||||||
o.LogOptions.BatchOptions.Mode = "foo"
|
o.LogOptions.BatchOptions.Mode = "foo"
|
||||||
return o
|
return o
|
||||||
},
|
},
|
||||||
@ -171,7 +178,7 @@ func TestAuditInvalidOptions(t *testing.T) {
|
|||||||
name: "invalid log buffer size",
|
name: "invalid log buffer size",
|
||||||
options: func() *AuditOptions {
|
options: func() *AuditOptions {
|
||||||
o := NewAuditOptions()
|
o := NewAuditOptions()
|
||||||
o.LogOptions.Path = "/audit"
|
o.LogOptions.Path = auditPath
|
||||||
o.LogOptions.BatchOptions.Mode = "batch"
|
o.LogOptions.BatchOptions.Mode = "batch"
|
||||||
o.LogOptions.BatchOptions.BatchConfig.BufferSize = -3
|
o.LogOptions.BatchOptions.BatchConfig.BufferSize = -3
|
||||||
return o
|
return o
|
||||||
@ -180,7 +187,7 @@ func TestAuditInvalidOptions(t *testing.T) {
|
|||||||
name: "invalid webhook mode",
|
name: "invalid webhook mode",
|
||||||
options: func() *AuditOptions {
|
options: func() *AuditOptions {
|
||||||
o := NewAuditOptions()
|
o := NewAuditOptions()
|
||||||
o.WebhookOptions.ConfigFile = "/audit"
|
o.WebhookOptions.ConfigFile = auditPath
|
||||||
o.WebhookOptions.BatchOptions.Mode = "foo"
|
o.WebhookOptions.BatchOptions.Mode = "foo"
|
||||||
return o
|
return o
|
||||||
},
|
},
|
||||||
@ -188,7 +195,7 @@ func TestAuditInvalidOptions(t *testing.T) {
|
|||||||
name: "invalid webhook buffer throttle qps",
|
name: "invalid webhook buffer throttle qps",
|
||||||
options: func() *AuditOptions {
|
options: func() *AuditOptions {
|
||||||
o := NewAuditOptions()
|
o := NewAuditOptions()
|
||||||
o.WebhookOptions.ConfigFile = "/audit"
|
o.WebhookOptions.ConfigFile = auditPath
|
||||||
o.WebhookOptions.BatchOptions.Mode = "batch"
|
o.WebhookOptions.BatchOptions.Mode = "batch"
|
||||||
o.WebhookOptions.BatchOptions.BatchConfig.ThrottleQPS = -1
|
o.WebhookOptions.BatchOptions.BatchConfig.ThrottleQPS = -1
|
||||||
return o
|
return o
|
||||||
@ -197,7 +204,7 @@ func TestAuditInvalidOptions(t *testing.T) {
|
|||||||
name: "invalid webhook truncate max event size",
|
name: "invalid webhook truncate max event size",
|
||||||
options: func() *AuditOptions {
|
options: func() *AuditOptions {
|
||||||
o := NewAuditOptions()
|
o := NewAuditOptions()
|
||||||
o.WebhookOptions.ConfigFile = "/audit"
|
o.WebhookOptions.ConfigFile = auditPath
|
||||||
o.WebhookOptions.TruncateOptions.Enabled = true
|
o.WebhookOptions.TruncateOptions.Enabled = true
|
||||||
o.WebhookOptions.TruncateOptions.TruncateConfig.MaxEventSize = -1
|
o.WebhookOptions.TruncateOptions.TruncateConfig.MaxEventSize = -1
|
||||||
return o
|
return o
|
||||||
@ -206,7 +213,7 @@ func TestAuditInvalidOptions(t *testing.T) {
|
|||||||
name: "invalid webhook truncate max batch size",
|
name: "invalid webhook truncate max batch size",
|
||||||
options: func() *AuditOptions {
|
options: func() *AuditOptions {
|
||||||
o := NewAuditOptions()
|
o := NewAuditOptions()
|
||||||
o.WebhookOptions.ConfigFile = "/audit"
|
o.WebhookOptions.ConfigFile = auditPath
|
||||||
o.WebhookOptions.TruncateOptions.Enabled = true
|
o.WebhookOptions.TruncateOptions.Enabled = true
|
||||||
o.WebhookOptions.TruncateOptions.TruncateConfig.MaxEventSize = 2
|
o.WebhookOptions.TruncateOptions.TruncateConfig.MaxEventSize = 2
|
||||||
o.WebhookOptions.TruncateOptions.TruncateConfig.MaxBatchSize = 1
|
o.WebhookOptions.TruncateOptions.TruncateConfig.MaxBatchSize = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user