|
| 1 | +package elastic |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +func TestFetchSourceContextNoFetchSource(t *testing.T) { |
| 9 | + builder := NewFetchSourceContext(false) |
| 10 | + data, err := json.Marshal(builder.Source()) |
| 11 | + if err != nil { |
| 12 | + t.Fatalf("marshaling to JSON failed: %v", err) |
| 13 | + } |
| 14 | + got := string(data) |
| 15 | + expected := `false` |
| 16 | + if got != expected { |
| 17 | + t.Errorf("expected\n%s\n,got:\n%s", expected, got) |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +func TestFetchSourceContextNoFetchSourceIgnoreIncludesAndExcludes(t *testing.T) { |
| 22 | + builder := NewFetchSourceContext(false).Include("a", "b").Exclude("c") |
| 23 | + data, err := json.Marshal(builder.Source()) |
| 24 | + if err != nil { |
| 25 | + t.Fatalf("marshaling to JSON failed: %v", err) |
| 26 | + } |
| 27 | + got := string(data) |
| 28 | + expected := `false` |
| 29 | + if got != expected { |
| 30 | + t.Errorf("expected\n%s\n,got:\n%s", expected, got) |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +func TestFetchSourceContextFetchSource(t *testing.T) { |
| 35 | + builder := NewFetchSourceContext(true) |
| 36 | + data, err := json.Marshal(builder.Source()) |
| 37 | + if err != nil { |
| 38 | + t.Fatalf("marshaling to JSON failed: %v", err) |
| 39 | + } |
| 40 | + got := string(data) |
| 41 | + expected := `{"excludes":[],"includes":[]}` |
| 42 | + if got != expected { |
| 43 | + t.Errorf("expected\n%s\n,got:\n%s", expected, got) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +func TestFetchSourceContextFetchSourceWithIncludesAndExcludes(t *testing.T) { |
| 48 | + builder := NewFetchSourceContext(true).Include("a", "b").Exclude("c") |
| 49 | + data, err := json.Marshal(builder.Source()) |
| 50 | + if err != nil { |
| 51 | + t.Fatalf("marshaling to JSON failed: %v", err) |
| 52 | + } |
| 53 | + got := string(data) |
| 54 | + expected := `{"excludes":["c"],"includes":["a","b"]}` |
| 55 | + if got != expected { |
| 56 | + t.Errorf("expected\n%s\n,got:\n%s", expected, got) |
| 57 | + } |
| 58 | +} |
0 commit comments