-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Channel default value by changing default logic
In a nutshell, the newly introduced plugin.PopulateDefaults function populates all fields of a Plugin-implementing struct with those fields from Info.ConfigAttributes where ConfigOption.Default is set. Thus, a single function call before parsing the user-submitted configuration within the Plugin.SetConfig method sets default values. As a result of the discussion between the Go daemon team and the web team, summarized in #205, web does not store or stores default values as JSON "null" values. The Go JSON unmarshaller does not overwrite existing field values for JSON nulls. Prior, an already JSON-encoded version of the ConfigOption slice was present in plugin.Info. Thus, this data wasn't easily available anymore. As the new code now needs to access this field, it was changed and a custom sql driver.Valuer was implemented for a slice type. While working on this, all ConfigOptions were put in the same order as the struct fields. Closes #205.
- Loading branch information
Showing
5 changed files
with
136 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestEmail_SetConfig(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
jsonMsg string | ||
want *Email | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "empty-string", | ||
jsonMsg: ``, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "empty-json-obj", | ||
jsonMsg: `{}`, | ||
want: &Email{SenderName: "Icinga", SenderMail: "icinga@example.com"}, | ||
}, | ||
{ | ||
name: "sender-mail-empty-val", | ||
jsonMsg: `{"sender_mail": ""}`, | ||
want: &Email{SenderName: "Icinga", SenderMail: ""}, | ||
}, | ||
{ | ||
name: "example", | ||
jsonMsg: `{"sender_name":"icinga","sender_mail":"icinga@example.com","host":"smtp.example.com","port":"25","encryption":"none"}`, | ||
want: &Email{ | ||
Host: "smtp.example.com", | ||
Port: "25", | ||
SenderName: "icinga", | ||
SenderMail: "icinga@example.com", | ||
User: "", | ||
Password: "", | ||
Encryption: "none", | ||
}, | ||
}, | ||
{ | ||
name: "user-but-missing-pass", | ||
jsonMsg: `{"user": "foo"}`, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
email := &Email{} | ||
err := email.SetConfig(json.RawMessage(tt.jsonMsg)) | ||
assert.Equal(t, tt.wantErr, err != nil, "SetConfig() error = %v, wantErr = %t", err, tt.wantErr) | ||
if err != nil { | ||
return | ||
} | ||
|
||
assert.Equal(t, tt.want, email, "Email differs") | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters