Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Commit

Permalink
Additional tests to improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome Froelich committed Apr 12, 2017
1 parent 7644997 commit 7aa64a1
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,49 @@ func TestNewPolicyFromSchema(t *testing.T) {
assert.Equal(t, test.expectedPolicy, actualPolicy)
}
}

func TestNewPoliciesFromSchema(t *testing.T) {
tests := []struct {
policies []*schema.Policy
expectedPolicies []Policy
expectedErr bool
}{
// invalid precision
{
policies: []*schema.Policy{
&schema.Policy{
Resolution: &schema.Resolution{WindowSize: 100, Precision: 42},
Retention: &schema.Retention{Period: 20},
},
},
expectedErr: true,
},
// valid policy
{
policies: []*schema.Policy{
&schema.Policy{
Resolution: &schema.Resolution{WindowSize: 100, Precision: int64(time.Second)},
Retention: &schema.Retention{Period: 20},
},
},
expectedPolicies: []Policy{
Policy{
resolution: Resolution{Window: 100, Precision: xtime.Second},
retention: 20,
},
},
expectedErr: false,
},
}

for _, test := range tests {
actualPolicies, actualErr := NewPoliciesFromSchema(test.policies)
if test.expectedErr {
assert.Error(t, actualErr)
continue
}

assert.NoError(t, actualErr)
assert.Equal(t, test.expectedPolicies, actualPolicies)
}
}

0 comments on commit 7aa64a1

Please sign in to comment.