-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Segment test cases for system metadata (#63)
* refactor: continuous outbound MQTT topic structure * bump: project requirements * docs: resolve formatting issues with markdownlint * feat: create experimental dev container * feat: outline basic application + republisher content testing * refactor: test payload attributes w/ verification & timestamp * fix: check on missing topic & test cases for payload contents * ci: workflow for testing code (coverage)
- Loading branch information
1 parent
ef68314
commit acec3a1
Showing
15 changed files
with
274 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
// README at: https://github.com/devcontainers/templates/tree/main/src/go | ||
{ | ||
"name": "Go", | ||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile | ||
"image": "mcr.microsoft.com/devcontainers/go:1-1.22-bookworm" | ||
|
||
// Features to add to the dev container. More info: https://containers.dev/features. | ||
// "features": {}, | ||
|
||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
|
||
// Use 'postCreateCommand' to run commands after the container is created. | ||
// "postCreateCommand": "go version", | ||
|
||
// Configure tool-specific properties. | ||
// "customizations": {}, | ||
|
||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. | ||
// "remoteUser": "root" | ||
} |
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,12 @@ | ||
# To get started with Dependabot version updates, you'll need to specify which | ||
# package ecosystems to update and where the package manifests are located. | ||
# Please see the documentation for more information: | ||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
# https://containers.dev/guide/dependabot | ||
|
||
version: 2 | ||
updates: | ||
- package-ecosystem: "devcontainers" | ||
directory: "/" | ||
schedule: | ||
interval: weekly |
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 |
---|---|---|
|
@@ -10,6 +10,9 @@ build: | |
test: | ||
go test -v ./... | ||
|
||
coverage: | ||
go test -cover ./... | ||
|
||
run: build | ||
./${BIN_NAME} --help | ||
|
||
|
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
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
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,31 @@ | ||
package utility | ||
|
||
import ( | ||
"crypto/md5" | ||
"encoding/base64" | ||
"fmt" | ||
"time" | ||
) | ||
|
||
func MakeTimestamp() int64 { | ||
return time.Now().UnixMicro() | ||
} | ||
|
||
func Verification(data string) string { | ||
hash := md5.New() | ||
hash.Write([]byte(data)) | ||
return fmt.Sprintf("%x", hash.Sum(nil)) | ||
} | ||
|
||
func EncapsulatePayload(message string) string { | ||
encoded := base64.StdEncoding.EncodeToString([]byte(message)) | ||
return encoded | ||
} | ||
|
||
func UnencapsulatePayload(message string) string { | ||
decoded, err := base64.StdEncoding.DecodeString(message) | ||
if err != nil { | ||
fmt.Println(">> [!] Error decoding the message: ", err) | ||
} | ||
return string(decoded) | ||
} |
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,68 @@ | ||
package utility | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestMakeTimestamp(t *testing.T) { | ||
actual := MakeTimestamp() | ||
expected := 16 | ||
|
||
length := len(fmt.Sprintf("%d", actual)) | ||
|
||
if length != expected { | ||
t.Errorf("Expected %d but got %d", expected, length) | ||
} | ||
} | ||
|
||
func TestVerification(t *testing.T) { | ||
testcases := []struct { | ||
input string | ||
}{ | ||
{"data-diode"}, | ||
} | ||
|
||
for _, test := range testcases { | ||
actual := Verification(test.input) | ||
expected := "ef217cdf54b0b3ece89a0d7686da550b" | ||
|
||
if actual != expected { | ||
t.Errorf("Expected %s but got %s", expected, actual) | ||
} | ||
} | ||
} | ||
|
||
func TestEncapsulatePayload(t *testing.T) { | ||
testcases := []struct { | ||
input string | ||
}{ | ||
{"data-diode"}, | ||
} | ||
|
||
for _, test := range testcases { | ||
actual := EncapsulatePayload(test.input) | ||
expected := "ZGF0YS1kaW9kZQ==" | ||
|
||
if actual != expected { | ||
t.Errorf("Expected %s but got %s", expected, actual) | ||
} | ||
} | ||
} | ||
|
||
func TestUnencapsulatePayload(t *testing.T) { | ||
testcases := []struct { | ||
input string | ||
}{ | ||
{"ZGF0YS1kaW9kZQ=="}, | ||
} | ||
|
||
for _, test := range testcases { | ||
actual := UnencapsulatePayload(test.input) | ||
expected := "data-diode" | ||
|
||
if actual != expected { | ||
t.Errorf("Expected %s but got %s", expected, actual) | ||
} | ||
} | ||
} |
Oops, something went wrong.