Skip to content

Commit

Permalink
Merge pull request #15 from Comcast/hotfix/tr1d1umDNS
Browse files Browse the repository at this point in the history
In the case of SimpleRequestResponse messages, talaria uses transacti…
  • Loading branch information
schmidtw authored Oct 31, 2017
2 parents 2190d23 + bbda3cd commit ddeb5b2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
9 changes: 8 additions & 1 deletion src/tr1d1um/conversion_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type EncodingHelper struct{}
//ConversionWDMP implements the definitions defined in ConversionTool
type ConversionWDMP struct {
encodingHelper EncodingTool
WRPSource string
}

//The following functions with names of the form {command}FlavorFormat serve as the low level builders of WDMP objects
Expand Down Expand Up @@ -193,13 +194,19 @@ func (cw *ConversionWDMP) GetConfiguredWRP(wdmp []byte, pathVars Vars, header ht
Type: wrp.SimpleRequestResponseMessageType,
ContentType: header.Get("Content-Type"),
Payload: wdmp,
Source: WRPSource + "/" + service,
Source: cw.GetWRPSource() + "/" + service,
Destination: deviceID + "/" + service,
TransactionUUID: GetOrGenTID(header),
}
return
}

// GetWRPSource returns the Source that should be used in every
// WRP transaction message
func (cw *ConversionWDMP) GetWRPSource() string {
return cw.WRPSource
}

/* Encoding Helper methods below */

//DecodeJSON decodes data from the input into v. It uses json.Unmarshall to perform actual decoding
Expand Down
12 changes: 6 additions & 6 deletions src/tr1d1um/conversion_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestGetFlavorFormat(t *testing.T) {

func TestSetFlavorFormat(t *testing.T) {
assert := assert.New(t)
c := ConversionWDMP{&EncodingHelper{}}
c := ConversionWDMP{encodingHelper:&EncodingHelper{}, WRPSource: "dns:machineDNS"}
commonURL := "http://device/config?k=v"
var req *http.Request

Expand Down Expand Up @@ -163,7 +163,7 @@ func TestSetFlavorFormat(t *testing.T) {
func TestDeleteFlavorFormat(t *testing.T) {
assert := assert.New(t)
commonVars := Vars{"param": "rowName", "emptyParam": ""}
c := ConversionWDMP{&EncodingHelper{}}
c := ConversionWDMP{encodingHelper:&EncodingHelper{}, WRPSource: "dns:machineDNS"}

t.Run("NoRowName", func(t *testing.T) {
_, err := c.DeleteFlavorFormat(Vars{}, "param")
Expand All @@ -188,7 +188,7 @@ func TestReplaceFlavorFormat(t *testing.T) {
assert := assert.New(t)
commonVars := Vars{"uThere?": "yes!"}
emptyVars := Vars{}
c := ConversionWDMP{&EncodingHelper{}}
c := ConversionWDMP{encodingHelper:&EncodingHelper{}, WRPSource: "dns:machineDNS"}

t.Run("TableNotProvided", func(t *testing.T) {
_, err := c.ReplaceFlavorFormat(nil, emptyVars, "uThere?")
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestAddFlavorFormat(t *testing.T) {
assert := assert.New(t)
emptyVars := Vars{}

c := ConversionWDMP{&EncodingHelper{}}
c := ConversionWDMP{encodingHelper:&EncodingHelper{}, WRPSource: "dns:machineDNS"}

t.Run("TableNotProvided", func(t *testing.T) {
_, err := c.AddFlavorFormat(nil, emptyVars, "uThere?")
Expand Down Expand Up @@ -433,15 +433,15 @@ func TestGetConfiguredWRP(t *testing.T) {
service := "webpaService"
tid := "uniqueVal"

c := ConversionWDMP{}
c := ConversionWDMP{WRPSource:"dns:source"}

inputVars := Vars{"service": service, "deviceid": deviceID}
inputHeader := http.Header{}
inputHeader.Set("Content-Type", wrp.JSON.ContentType())
inputHeader.Set(HeaderWPATID, tid)
inputWdmpPayload := []byte(`{irrelevantFormat}`)

expectedSource := WRPSource + "/" + service
expectedSource := "dns:source/" + service
expectedDest := deviceID + "/" + service

wrpMsg := c.GetConfiguredWRP(inputWdmpPayload, inputVars, inputHeader)
Expand Down
2 changes: 1 addition & 1 deletion src/tr1d1um/tr1d1um.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func SetUpHandler(v *viper.Viper, logger log.Logger) (cHandler *ConversionHandle

cHandler = &ConversionHandler{
Requester: &ContextTimeoutRequester{&http.Client{Timeout: clientTimeout}},
wdmpConvert: &ConversionWDMP{&EncodingHelper{}},
wdmpConvert: &ConversionWDMP{encodingHelper: &EncodingHelper{}, WRPSource: v.GetString("WRPSource")},
sender: &Tr1SendAndHandle{log: logger, NewHTTPRequest: http.NewRequest, respTimeout: respTimeout},
encodingHelper: &EncodingHelper{}, logger: logger,
targetURL: v.GetString("targetURL"),
Expand Down
2 changes: 0 additions & 2 deletions src/tr1d1um/wdmp_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ const (
HeaderWPATID = "X-WebPA-Transaction-Id"

ErrUnsuccessfulDataParse = "Unsuccessful Data Parse"

WRPSource = "dns:tr1d1um.webpa.comcast.net"
)

//GetWDMP serves as container for data used for the GET-flavored commands
Expand Down

0 comments on commit ddeb5b2

Please sign in to comment.