Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lwm2m2 unitest #1021

Closed
wants to merge 14 commits into from
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ require (
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/pion/dtls/v3 v3.0.2 // indirect
github.com/pion/logging v0.2.2 // indirect
github.com/pion/transport/v3 v3.0.7 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand Down
30 changes: 30 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,36 @@ github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4=
github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
github.com/pascaldekloe/goe v0.1.1 h1:Ah6WQ56rZONR3RW3qWa2NCZ6JAVvSpUcoLBaOmYFt9Q=
github.com/pascaldekloe/goe v0.1.1/go.mod h1:KSyfaxQOh0HZPjDP1FL/kFtbqYqrALJTaMafFUIccqU=
<<<<<<< HEAD
github.com/pion/dtls/v2 v2.2.8-0.20240201071732-2597464081c8 h1:r7K+oQUYubeA0am08kTAvd2wT2D8PZggs/CpMGp0nkM=
github.com/pion/dtls/v2 v2.2.8-0.20240201071732-2597464081c8/go.mod h1:/gft3czh67pwl4nM1BBUvF7eTy72uGkObJXOYfxRDbA=
github.com/pion/dtls/v2 v2.2.12 h1:KP7H5/c1EiVAAKUmXyCzPiQe5+bCJrpOeKg/L05dunk=
github.com/pion/dtls/v2 v2.2.12/go.mod h1:d9SYc9fch0CqK90mRk1dC7AkzzpwJj6u2GU3u+9pqFE=
github.com/pion/dtls/v3 v3.0.2 h1:425DEeJ/jfuTTghhUDW0GtYZYIwwMtnKKJNMcWccTX0=
github.com/pion/dtls/v3 v3.0.2/go.mod h1:dfIXcFkKoujDQ+jtd8M6RgqKK3DuaUilm3YatAbGp5k=
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
github.com/pion/transport/v2 v2.2.4 h1:41JJK6DZQYSeVLxILA2+F4ZkKb4Xd/tFJZRFZQ9QAlo=
github.com/pion/transport/v2 v2.2.4/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0=
github.com/pion/transport/v3 v3.0.1 h1:gDTlPJwROfSfz6QfSi0ZmeCSkFcnWWiiR9ES0ouANiM=
github.com/pion/transport/v3 v3.0.1/go.mod h1:UY7kiITrlMv7/IKgd5eTUcaahZx5oUN3l9SzK5f5xE0=
=======
github.com/pion/dtls/v3 v3.0.4 h1:44CZekewMzfrn9pmGrj5BNnTMDCFwr+6sLH+cCuLM7U=
github.com/pion/dtls/v3 v3.0.4/go.mod h1:R373CsjxWqNPf6MEkfdy3aSe9niZvL/JaKlGeFphtMg=
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
>>>>>>> main
github.com/pion/transport/v3 v3.0.7 h1:iRbMH05BzSNwhILHoBoAPxoB9xQgOaJk+591KC9P1o0=
github.com/pion/transport/v3 v3.0.7/go.mod h1:YleKiTZ4vqNxVwh77Z0zytYi7rXHl7j6uPLGhhz9rwo=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
<<<<<<< HEAD
github.com/plgd-dev/go-coap/v3 v3.1.6 h1:hU2ztY57G1tRz5C6soxnnJiTJaK19W/W5eUSoYyt82Y=
github.com/plgd-dev/go-coap/v3 v3.1.6/go.mod h1:O5P/Bja4MBeDw3SaNxf+9PNyfe80SHBIJKyWVwT0W5Y=
=======
>>>>>>> main
github.com/plgd-dev/go-coap/v3 v3.3.6 h1:8F7Y+ZYcFsvz2nBaphdYYd0cLdRNpjqCzjQjxGdGKFY=
github.com/plgd-dev/go-coap/v3 v3.3.6/go.mod h1:Cs6sfxmF/b8ktTVfPMf6FzihFx+0mEZ/ClbFNUnnsZw=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down Expand Up @@ -233,8 +253,18 @@ go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
<<<<<<< HEAD
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
=======
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
>>>>>>> main
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 h1:kx6Ds3MlpiUHKj7syVnbp57++8WpuKPcR5yjLBjvLEA=
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
Expand Down
70 changes: 70 additions & 0 deletions pkg/deviceshifu/deviceshifulwm2m/deviceshifulwm2mconfig_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package deviceshifulwm2m

import (
"reflect"
"testing"

"github.com/edgenesis/shifu/pkg/deviceshifu/deviceshifubase"
)

func TestCreateLwM2MInstructions(t *testing.T) {
// Initialize test data
dsInstructions := &deviceshifubase.DeviceShifuInstructions{
Instructions: map[string]*deviceshifubase.DeviceShifuInstruction{
"instruction1": {
DeviceShifuProtocolProperties: map[string]string{
objectIdStr: "123",
enableObserveStr: "true",
},
},
"instruction2": {
DeviceShifuProtocolProperties: map[string]string{
objectIdStr: "456",
enableObserveStr: "false",
},
},
},
}

// Expected result
expectedResult := &LwM2MInstruction{
Instructions: map[string]*LwM2MProtocolProperty{
"instruction1": {
ObjectId: "123",
EnableObserve: true,
},
"instruction2": {
ObjectId: "456",
EnableObserve: false,
},
},
}

beingStrongeryqqq marked this conversation as resolved.
Show resolved Hide resolved
// Call the function under test
result := CreateLwM2MInstructions(dsInstructions)

// Assert that the result matches the expected result using reflect.DeepEqual
if !reflect.DeepEqual(expectedResult, result) {
t.Errorf("Unexpected result. Expected: %+v, Got: %+v", expectedResult, result)
}
}

func TestCreateLwM2MInstructions_EmptyInstructions(t *testing.T) {
// Test the case of an empty instruction map
dsInstructions := &deviceshifubase.DeviceShifuInstructions{
Instructions: map[string]*deviceshifubase.DeviceShifuInstruction{},
}

// Expected result
expectedResult := &LwM2MInstruction{
Instructions: map[string]*LwM2MProtocolProperty{},
}

// Call the function under test
result := CreateLwM2MInstructions(dsInstructions)

// Assert that the result matches the expected result using reflect.DeepEqual
if !reflect.DeepEqual(expectedResult, result) {
t.Errorf("Unexpected result. Expected: %+v, Got: %+v", expectedResult, result)
}
}
66 changes: 66 additions & 0 deletions pkg/deviceshifu/deviceshifulwm2m/lwm2m/ciphersuite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package lwm2m

import (
"reflect"
"testing"

"github.com/edgenesis/shifu/pkg/k8s/api/v1alpha1"
"github.com/pion/dtls/v3"
)

func TestCipherSuiteStringsToCodes(t *testing.T) {
beingStrongeryqqq marked this conversation as resolved.
Show resolved Hide resolved
tests := []struct {
name string
input []v1alpha1.CipherSuite
expectedOutput []dtls.CipherSuiteID
expectError bool
}{
{
name: "Valid cipher suites",
input: []v1alpha1.CipherSuite{
v1alpha1.CipherSuite_TLS_ECDHE_ECDSA_WITH_AES_128_CCM,
v1alpha1.CipherSuite_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
},
expectedOutput: []dtls.CipherSuiteID{
TLS_ECDHE_ECDSA_WITH_AES_128_CCM,
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
},
expectError: false,
},
{
name: "Invalid cipher suite",
input: []v1alpha1.CipherSuite{
v1alpha1.CipherSuite("INVALID_CIPHER_SUITE"),
},
expectedOutput: nil,
expectError: true,
},
{
name: "Mixed valid and invalid cipher suites",
input: []v1alpha1.CipherSuite{
v1alpha1.CipherSuite_TLS_ECDHE_ECDSA_WITH_AES_128_CCM,
v1alpha1.CipherSuite("INVALID_CIPHER_SUITE"),
},
expectedOutput: nil,
expectError: true,
},
{
name: "Empty input",
input: []v1alpha1.CipherSuite{},
expectedOutput: []dtls.CipherSuiteID{},
expectError: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
output, err := CipherSuiteStringsToCodes(tt.input)
if (err != nil) != tt.expectError {
t.Errorf("expected error: %v, got: %v", tt.expectError, err)
}
if !tt.expectError && !reflect.DeepEqual(output, tt.expectedOutput) {
t.Errorf("expected output: %v, got: %v", tt.expectedOutput, output)
}
})
}
}
Loading