Skip to content

Commit

Permalink
added tests and updated changelog&version
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarrell-NS1 committed Mar 13, 2023
1 parent 57ca233 commit d543ef7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.7.5 (March 13, 2023)
BUG FIXES:

* Fixes `additonal_metadata` parsing

## 2.7.4 (January 17, 2023)
FEATURES:

Expand Down
2 changes: 1 addition & 1 deletion rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

const (
clientVersion = "2.7.4"
clientVersion = "2.7.5"

defaultEndpoint = "https://api.nsone.net/v1/"
defaultShouldFollowPagination = true
Expand Down
37 changes: 35 additions & 2 deletions rest/model/data/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func TestMeta_StringMap(t *testing.T) {
"bias": "*0.55",
"a5m_cutoff": 0.9,
}}
meta.AdditionalMetadata = []interface{}{map[string]interface{}{
"a": "1",
"b": "2",
"c": "3",
}}
m := meta.StringMap()

if m["up"].(string) != "1" {
Expand Down Expand Up @@ -70,6 +75,11 @@ func TestMeta_StringMap(t *testing.T) {
t.Fatal("pulsar should be", expected, "was", m["pulsar"].(string))
}

expected = `[{"a":"1","b":"2","c":"3"}]`
if m["additional_metadata"].(string) != expected {
t.Fatal("additional_metadata should be", expected, "was", m["additional_metadata"].(string))
}

expected = `{"feed":"12345678"}`
if m["longitude"].(string) != expected {
t.Fatal("longitude should be", expected, "was", m["longitude"].(string))
Expand Down Expand Up @@ -152,6 +162,7 @@ func TestMetaFromMap(t *testing.T) {
m["ip_prefixes"] = "1.1.1.1/24,2.2.2.2/24"
m["asn"] = "1"
m["pulsar"] = `[{"job_id":"abcdef","bias":"*0.55","a5m_cutoff":0.9}]`
m["additional_metadata"] = `[{"a":"1","b":"2","c":"3"}]`
meta := MetaFromMap(m)

if meta.ASN.(string) != "1" {
Expand Down Expand Up @@ -183,6 +194,15 @@ func TestMetaFromMap(t *testing.T) {
t.Fatalf("meta.Pulsar should be %v, was %v", expect, meta.Pulsar)
}

expect = []map[string]interface{}{map[string]interface{}{
"a": "1",
"b": "2",
"c": "3",
}}
if !reflect.DeepEqual(meta.AdditionalMetadata, expect) {
t.Fatalf("meta.AdditonalMetadata should be %v, was %v", expect, meta.AdditionalMetadata)
}

expected := []string{"1.1.1.1/24", "2.2.2.2/24"}
if !reflect.DeepEqual(meta.IPPrefixes.([]string), expected) {
t.Fatal("meta.IPPrefixes should be a slice containing elements `1.1.1.1/24` and `2.2.2.2/24`")
Expand Down Expand Up @@ -271,6 +291,11 @@ func TestMeta_Validate(t *testing.T) {
"bias": "*0.55",
"a5m_cutoff": 0.9,
}}
m.AdditionalMetadata = []interface{}{map[string]interface{}{
"a": "1",
"b": "2",
"c": "3",
}}
errs := m.Validate()
if len(errs) > 0 {
t.Fatal("there should be 0 errors, but there were", len(errs), ":", errs)
Expand Down Expand Up @@ -298,9 +323,17 @@ func TestMeta_Validate(t *testing.T) {
m.IPPrefixes = "1234567"
m.Priority = -1
m.Pulsar = []interface{}{map[string]interface{}{}}
addData := make([]map[string]interface{}, 2)
addData[0] = map[string]interface{}{
"a": "1",
}
addData[1] = map[string]interface{}{
"b": "2",
}
m.AdditionalMetadata = addData
errs = m.Validate()
if len(errs) != 16 {
t.Fatal("expected 15 errors, but there were", len(errs), ":", errs)
if len(errs) != 17 {
t.Fatal("expected 17 errors, but there were", len(errs), ":", errs)
}

m = &Meta{}
Expand Down

0 comments on commit d543ef7

Please sign in to comment.