github.com/etecs-ru/gnomock@v0.13.2/preset/splunk/README.md (about) 1 # Gnomock Splunk 2 3 Gnomock Splunk is a [Gnomock](https://github.com/orlangure/gnomock) preset for running tests against a real Splunk 4 container, without mocks. 5 6 ```go 7 package splunk_test 8 9 import ( 10 "fmt" 11 "sort" 12 "time" 13 14 "github.com/orlangure/gnomock" 15 "github.com/orlangure/gnomock/preset/splunk" 16 ) 17 18 func ExamplePreset() { 19 events := []splunk.Event{ 20 { 21 Event: "action=foo", 22 Index: "events", 23 Source: "app", 24 SourceType: "http", 25 Time: time.Now().UnixNano(), 26 }, 27 { 28 Event: "action=bar", 29 Index: "events", 30 Source: "app", 31 SourceType: "http", 32 Time: time.Now().UnixNano(), 33 }, 34 } 35 36 p := splunk.Preset( 37 splunk.WithVersion("latest"), 38 splunk.WithLicense(true), 39 splunk.WithPassword("12345678"), 40 splunk.WithValues(events), 41 ) 42 43 // created container now includes two events in "events" index 44 container, err := gnomock.Start(p) 45 fmt.Println("error:", err) 46 fmt.Println(len(container.Ports), "exposed ports:") 47 48 defer func() { 49 _ = gnomock.Stop(container) 50 }() 51 52 // Port numbers as well as container address are non-deterministic, so they 53 // are skipped in this example. The usage would be: 54 // 55 // container.Address("web") 56 // container.Address("api") 57 58 portNames := make([]string, 0) 59 60 for portName := range container.Ports { 61 portNames = append(portNames, portName) 62 } 63 64 sort.Strings(portNames) 65 fmt.Println(portNames) 66 67 // Output: 68 // error: <nil> 69 // 3 exposed ports: 70 // [api collector web] 71 } 72 ```