github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/nomad/structs/config/audit_test.go (about) 1 package config 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/hashicorp/nomad/ci" 8 "github.com/hashicorp/nomad/helper/pointer" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestAuditConfig_Merge(t *testing.T) { 13 ci.Parallel(t) 14 15 c1 := &AuditConfig{ 16 Enabled: pointer.Of(true), 17 Sinks: []*AuditSink{ 18 { 19 DeliveryGuarantee: "enforced", 20 Name: "file", 21 Type: "file", 22 Format: "json", 23 Path: "/opt/nomad/audit.log", 24 RotateDuration: 24 * time.Hour, 25 RotateDurationHCL: "24h", 26 RotateBytes: 100, 27 RotateMaxFiles: 10, 28 }, 29 }, 30 Filters: []*AuditFilter{ 31 { 32 Name: "one", 33 Type: "HTTPEvent", 34 Endpoints: []string{"/v1/metrics"}, 35 Stages: []string{"*"}, 36 Operations: []string{"*"}, 37 }, 38 }, 39 } 40 41 c2 := &AuditConfig{ 42 Sinks: []*AuditSink{ 43 { 44 DeliveryGuarantee: "best-effort", 45 Name: "file", 46 Type: "file", 47 Format: "json", 48 Path: "/opt/nomad/audit.log", 49 RotateDuration: 48 * time.Hour, 50 RotateDurationHCL: "48h", 51 RotateBytes: 20, 52 RotateMaxFiles: 2, 53 }, 54 }, 55 Filters: []*AuditFilter{ 56 { 57 Name: "one", 58 Type: "HTTPEvent", 59 Endpoints: []string{"/v1/metrics"}, 60 Stages: []string{"OperationReceived"}, 61 Operations: []string{"GET"}, 62 }, 63 { 64 Name: "two", 65 Type: "HTTPEvent", 66 Endpoints: []string{"*"}, 67 Stages: []string{"OperationReceived"}, 68 Operations: []string{"OPTIONS"}, 69 }, 70 }, 71 } 72 73 e := &AuditConfig{ 74 Enabled: pointer.Of(true), 75 Sinks: []*AuditSink{ 76 { 77 DeliveryGuarantee: "best-effort", 78 Name: "file", 79 Type: "file", 80 Format: "json", 81 Path: "/opt/nomad/audit.log", 82 RotateDuration: 48 * time.Hour, 83 RotateDurationHCL: "48h", 84 RotateBytes: 20, 85 RotateMaxFiles: 2, 86 }, 87 }, 88 Filters: []*AuditFilter{ 89 { 90 Name: "one", 91 Type: "HTTPEvent", 92 Endpoints: []string{"/v1/metrics"}, 93 Stages: []string{"OperationReceived"}, 94 Operations: []string{"GET"}, 95 }, 96 { 97 Name: "two", 98 Type: "HTTPEvent", 99 Endpoints: []string{"*"}, 100 Stages: []string{"OperationReceived"}, 101 Operations: []string{"OPTIONS"}, 102 }, 103 }, 104 } 105 106 result := c1.Merge(c2) 107 108 require.Equal(t, e, result) 109 }