1package statement 2 3import ( 4 "fmt" 5 "testing" 6 7 "github.com/influxdata/influxdb/stress/v2/stress_client" 8) 9 10func TestSetSetID(t *testing.T) { 11 e := newTestSet("database", "foo") 12 newID := "oaijnifo" 13 e.SetID(newID) 14 if e.StatementID != newID { 15 t.Errorf("Expected: %v\nGot: %v\n", newID, e.StatementID) 16 } 17} 18 19func TestSetRun(t *testing.T) { 20 properties := []string{ 21 "precision", 22 "startdate", 23 "batchsize", 24 "resultsaddress", 25 "testname", 26 "addresses", 27 "writeinterval", 28 "queryinterval", 29 "database", 30 "writeconcurrency", 31 "queryconcurrency", 32 } 33 for _, prop := range properties { 34 testSetRunUtl(t, prop, "1") 35 } 36} 37 38func testSetRunUtl(t *testing.T, property string, value string) { 39 i := newTestSet(property, value) 40 s, _, directiveCh := stressClient.NewTestStressTest() 41 // Listen to the other side of the directiveCh 42 go func() { 43 for d := range directiveCh { 44 if i.Var != d.Property { 45 t.Errorf("wrong property sent to stressClient\n expected: %v\n got: %v\n", i.Var, d.Property) 46 } 47 if i.Value != d.Value { 48 t.Errorf("wrong value sent to stressClient\n expected: %v\n got: %v\n", i.Value, d.Value) 49 } 50 d.Tracer.Done() 51 } 52 }() 53 // Run the statement 54 i.Run(s) 55 // Check the result 56 switch i.Var { 57 case "precision": 58 if i.Value != s.Precision { 59 t.Errorf("Failed to set %v\n", i.Var) 60 } 61 case "startdate": 62 if i.Value != s.StartDate { 63 t.Errorf("Failed to set %v\n", i.Var) 64 } 65 case "batchsize": 66 if parseInt(i.Value) != s.BatchSize { 67 t.Errorf("Failed to set %v\n", i.Var) 68 } 69 // TODO: Actually test this 70 case "resultsaddress": 71 default: 72 } 73} 74 75func TestSetReport(t *testing.T) { 76 set := newTestSet("this", "that") 77 s, _, _ := stressClient.NewTestStressTest() 78 rpt := set.Report(s) 79 expected := fmt.Sprintf("SET %v = '%v'", set.Var, set.Value) 80 if rpt != expected { 81 t.Errorf("expected: %v\ngot: %v\n", expected, rpt) 82 } 83} 84 85func newTestSet(toSet, value string) *SetStatement { 86 return &SetStatement{ 87 Var: toSet, 88 Value: value, 89 Tracer: stressClient.NewTracer(make(map[string]string)), 90 StatementID: "fooID", 91 } 92} 93