Skip to content

Commit 75dbb48

Browse files
committed
added tests
1 parent 16b5fab commit 75dbb48

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

internal/ota-api/dto.go

+3
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ func hasReachedFlashState(states []State) bool {
177177
}
178178

179179
func formatStateData(state, data string, firmware_size *int64, hasReceivedFlashState bool) string {
180+
if data == "" || strings.ToLower(data) == "unknown" {
181+
return ""
182+
}
180183
if state == "fetch" {
181184
// This is the state 'fetch' of OTA progress. This contains a numer that represents the number of bytes fetched
182185
if hasReceivedFlashState {

internal/ota-api/dto_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package otaapi
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestProgressBar_notCompletePct(t *testing.T) {
10+
firmwareSize := int64(25665 * 2)
11+
bar := formatStateData("fetch", "25665", &firmwareSize, false)
12+
assert.Equal(t, "[===== ] 50.00%", bar)
13+
}
14+
15+
func TestProgressBar_ifFlashState_goTo100Pct(t *testing.T) {
16+
firmwareSize := int64(25665 * 2)
17+
bar := formatStateData("fetch", "25665", &firmwareSize, true) // If in flash status, go to 100%
18+
assert.Equal(t, "[==========] 100.00%", bar)
19+
}

0 commit comments

Comments
 (0)