-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: subscription message decode (#3553)
* fix: subscription message decode * fix type check * fix panics
- Loading branch information
1 parent
c57a99b
commit c53915f
Showing
3 changed files
with
53 additions
and
1 deletion.
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,41 @@ | ||
package subscription_test | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/kubeshop/tracetest/server/subscription" | ||
"github.com/stretchr/testify/require" | ||
"gotest.tools/v3/assert" | ||
) | ||
|
||
func TestDecode(t *testing.T) { | ||
type msg struct { | ||
Value int | ||
AnotherValue string | ||
} | ||
|
||
realMessage := msg{ | ||
Value: 2, | ||
AnotherValue: "cat", | ||
} | ||
|
||
message := subscription.Message{ | ||
ResourceID: "xxx", | ||
Content: realMessage, | ||
} | ||
|
||
msgBytes, err := json.Marshal(message) | ||
require.NoError(t, err) | ||
|
||
var target subscription.Message | ||
err = json.Unmarshal(msgBytes, &target) | ||
require.NoError(t, err) | ||
|
||
var targetMsg msg | ||
err = target.DecodeContent(&targetMsg) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, 2, targetMsg.Value) | ||
assert.Equal(t, "cat", targetMsg.AnotherValue) | ||
} |
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