Skip to content

Commit

Permalink
Add unsupported type to Load (#27)
Browse files Browse the repository at this point in the history
* Added new test
* Load in filter to return unsupported type error
* Ignore vscode and html (coverage) files
  • Loading branch information
raakasf authored Feb 19, 2021
1 parent c860257 commit 0d9ff2b
Show file tree
Hide file tree
Showing 35 changed files with 359 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*.dll
*.so
*.dylib
*.html
.vscode/*

# Test binary, built with `go test -c`
*.test
Expand Down
3 changes: 3 additions & 0 deletions builder/aggregation/aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aggregation

import (
"encoding/json"
"errors"

"github.com/grafadruid/go-druid/builder"
)
Expand Down Expand Up @@ -94,6 +95,8 @@ func Load(data []byte) (builder.Aggregator, error) {
a = NewStringLastFolding()
case "stringLast":
a = NewStringLast()
default:
return nil, errors.New("unsupported type")
}
return a, json.Unmarshal(data, &a)
}
17 changes: 17 additions & 0 deletions builder/aggregation/aggregation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package aggregation

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestLoadUnsupportedType(t *testing.T) {
assert := assert.New(t)

f, err := Load([]byte("{\"type\": \"blahblahType\"}"))

assert.Nil(f, "filter should be nil")
assert.NotNil(err, "error should not be nil")
assert.Error(err, "unsupported type")
}
3 changes: 3 additions & 0 deletions builder/bound/bound.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bound

import (
"encoding/json"
"errors"

"github.com/grafadruid/go-druid/builder"
)
Expand Down Expand Up @@ -34,6 +35,8 @@ func Load(data []byte) (builder.Aggregator, error) {
b = NewRadius()
case "rectangular":
b = NewRectangular()
default:
return nil, errors.New("unsupported type")
}
return b, json.Unmarshal(data, &b)
}
17 changes: 17 additions & 0 deletions builder/bound/bound_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package bound

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestLoadUnsupportedType(t *testing.T) {
assert := assert.New(t)

f, err := Load([]byte("{\"type\": \"blahblahType\"}"))

assert.Nil(f, "filter should be nil")
assert.NotNil(err, "error should not be nil")
assert.Error(err, "unsupported type")
}
3 changes: 3 additions & 0 deletions builder/datasource/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package datasource

import (
"encoding/json"
"errors"

"github.com/grafadruid/go-druid/builder"
)
Expand Down Expand Up @@ -42,6 +43,8 @@ func Load(data []byte) (builder.DataSource, error) {
d = NewTable()
case "union":
d = NewUnion()
default:
return nil, errors.New("unsupported type")
}
return d, json.Unmarshal(data, &d)
}
17 changes: 17 additions & 0 deletions builder/datasource/data_source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package datasource

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestLoadUnsupportedType(t *testing.T) {
assert := assert.New(t)

f, err := Load([]byte("{\"type\": \"blahblahType\"}"))

assert.Nil(f, "filter should be nil")
assert.NotNil(err, "error should not be nil")
assert.Error(err, "unsupported type")
}
3 changes: 3 additions & 0 deletions builder/dimension/dimension.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dimension

import (
"encoding/json"
"errors"

"github.com/grafadruid/go-druid/builder"
"github.com/grafadruid/go-druid/builder/types"
Expand Down Expand Up @@ -59,6 +60,8 @@ func Load(data []byte) (builder.Dimension, error) {
d = NewPrefixFiltered()
case "regexFiltered":
d = NewRegexFiltered()
default:
return nil, errors.New("unsupported type")
}
return d, json.Unmarshal(data, &d)
}
17 changes: 17 additions & 0 deletions builder/dimension/dimension_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dimension

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestLoadUnsupportedType(t *testing.T) {
assert := assert.New(t)

f, err := Load([]byte("{\"type\": \"blahblahType\"}"))

assert.Nil(f, "filter should be nil")
assert.NotNil(err, "error should not be nil")
assert.Error(err, "unsupported type")
}
3 changes: 3 additions & 0 deletions builder/extractionfn/extraction_fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package extractionfn

import (
"encoding/json"
"errors"

"github.com/grafadruid/go-druid/builder"
)
Expand Down Expand Up @@ -58,6 +59,8 @@ func Load(data []byte) (builder.ExtractionFn, error) {
e = NewTimeFormat()
case "upper":
e = NewUpper()
default:
return nil, errors.New("unsupported type")
}
return e, json.Unmarshal(data, &e)
}
17 changes: 17 additions & 0 deletions builder/extractionfn/extraction_fn_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package extractionfn

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestLoadUnsupportedType(t *testing.T) {
assert := assert.New(t)

f, err := Load([]byte("{\"type\": \"blahblahType\"}"))

assert.Nil(f, "filter should be nil")
assert.NotNil(err, "error should not be nil")
assert.Error(err, "unsupported type")
}
3 changes: 3 additions & 0 deletions builder/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package filter

import (
"encoding/json"
"errors"

"github.com/grafadruid/go-druid/builder"
)
Expand Down Expand Up @@ -64,6 +65,8 @@ func Load(data []byte) (builder.Filter, error) {
f = NewSpatial()
case "true":
f = NewTrue()
default:
return nil, errors.New("unsupported type")
}
return f, json.Unmarshal(data, &f)
}
17 changes: 17 additions & 0 deletions builder/filter/filter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package filter

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestLoadUnsupportedType(t *testing.T) {
assert := assert.New(t)

f, err := Load([]byte("{\"type\": \"blahblahType\"}"))

assert.Nil(f, "filter should be nil")
assert.NotNil(err, "error should not be nil")
assert.Error(err, "unsupported type")
}
17 changes: 17 additions & 0 deletions builder/granularity/granularity_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package granularity

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestLoadUnsupportedType(t *testing.T) {
assert := assert.New(t)

f, err := Load([]byte("{\"type\": \"blahblahType\"}"))

assert.Nil(f, "filter should be nil")
assert.NotNil(err, "error should not be nil")
assert.Error(err, "unsupported type")
}
3 changes: 3 additions & 0 deletions builder/havingspec/having_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package havingspec

import (
"encoding/json"
"errors"

"github.com/grafadruid/go-druid/builder"
)
Expand Down Expand Up @@ -46,6 +47,8 @@ func Load(data []byte) (builder.Dimension, error) {
d = NewNot()
case "or":
d = NewOr()
default:
return nil, errors.New("unsupported type")
}
return d, json.Unmarshal(data, &d)
}
17 changes: 17 additions & 0 deletions builder/havingspec/having_spec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package havingspec

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestLoadUnsupportedType(t *testing.T) {
assert := assert.New(t)

f, err := Load([]byte("{\"type\": \"blahblahType\"}"))

assert.Nil(f, "filter should be nil")
assert.NotNil(err, "error should not be nil")
assert.Error(err, "unsupported type")
}
4 changes: 4 additions & 0 deletions builder/intervals/intervals.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package intervals

import (
"encoding/json"
"errors"

"github.com/grafadruid/go-druid/builder"
)

Expand Down Expand Up @@ -29,6 +31,8 @@ func Load(data []byte) (builder.Intervals, error) {
switch t.Typ {
case "intervals":
i = NewIntervals()
default:
return nil, errors.New("unsupported type")
}
return i, json.Unmarshal(data, &i)
}
17 changes: 17 additions & 0 deletions builder/intervals/intervals_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package intervals

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestLoadUnsupportedType(t *testing.T) {
assert := assert.New(t)

f, err := Load([]byte("{\"type\": \"blahblahType\"}"))

assert.Nil(f, "filter should be nil")
assert.NotNil(err, "error should not be nil")
assert.Error(err, "unsupported type")
}
3 changes: 3 additions & 0 deletions builder/limitspec/limit_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package limitspec

import (
"encoding/json"
"errors"

"github.com/grafadruid/go-druid/builder"
)
Expand Down Expand Up @@ -30,6 +31,8 @@ func Load(data []byte) (builder.Dimension, error) {
switch t.Typ {
case "default":
d = NewDefault()
default:
return nil, errors.New("unsupported type")
}
return d, json.Unmarshal(data, &d)
}
17 changes: 17 additions & 0 deletions builder/limitspec/limit_spec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package limitspec

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestLoadUnsupportedType(t *testing.T) {
assert := assert.New(t)

f, err := Load([]byte("{\"type\": \"blahblahType\"}"))

assert.Nil(f, "filter should be nil")
assert.NotNil(err, "error should not be nil")
assert.Error(err, "unsupported type")
}
3 changes: 3 additions & 0 deletions builder/lookup/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lookup

import (
"encoding/json"
"errors"

"github.com/grafadruid/go-druid/builder"
)
Expand Down Expand Up @@ -30,6 +31,8 @@ func Load(data []byte) (builder.LookupExtractor, error) {
switch t.Typ {
case "map":
l = NewMap()
default:
return nil, errors.New("unsupported type")
}
return l, json.Unmarshal(data, &l)
}
17 changes: 17 additions & 0 deletions builder/lookup/lookup_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package lookup

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestLoadUnsupportedType(t *testing.T) {
assert := assert.New(t)

f, err := Load([]byte("{\"type\": \"blahblahType\"}"))

assert.Nil(f, "filter should be nil")
assert.NotNil(err, "error should not be nil")
assert.Error(err, "unsupported type")
}
3 changes: 3 additions & 0 deletions builder/postaggregation/post_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package postaggregation

import (
"encoding/json"
"errors"

"github.com/grafadruid/go-druid/builder"
)
Expand Down Expand Up @@ -56,6 +57,8 @@ func Load(data []byte) (builder.PostAggregator, error) {
p = NewLongGreatest()
case "longLeast":
p = NewLongLeast()
default:
return nil, errors.New("unsupported type")
}
return p, json.Unmarshal(data, &p)
}
Loading

0 comments on commit 0d9ff2b

Please sign in to comment.