| // Copyright 2026 The Chromium Authors |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| package cellular |
| |
| import ( |
| "fmt" |
| "testing" |
| |
| "go.chromium.org/infra/cros/internal/assert" |
| ) |
| |
| const ( |
| imei = "123456789012345" |
| activeSimSlot = "1" |
| state = "registered" |
| sim = "/org/freedesktop/ModemManager1/SIM/0" |
| simSlots = "/org/freedesktop/ModemManager1/SIM/0" |
| ownNumbers = "123456789098" |
| ) |
| |
| var mockMmcliJson = fmt.Sprintf(`{ |
| "modem": { |
| "3gpp": { |
| "imei": "%s" |
| }, |
| "generic": { |
| "primary-sim-slot": "%s", |
| "state": "%s", |
| "sim": "%s", |
| "sim-slots": ["%s"], |
| "own-numbers": ["%s"] |
| } |
| } |
| }`, imei, activeSimSlot, state, sim, simSlots, ownNumbers) |
| |
| func TestParseModemInfo(t *testing.T) { |
| info, err := parseModemInfo(mockMmcliJson) |
| assert.NilError(t, err) |
| |
| assert.StringsEqual(t, |
| info.GetModem().GetG3Pp().GetImei(), |
| imei, |
| ) |
| |
| assert.StringsEqual(t, |
| info.GetModem().GetGeneric().GetActiveSimSlot(), |
| activeSimSlot, |
| ) |
| assert.StringsEqual(t, |
| info.GetModem().GetGeneric().GetState(), |
| state, |
| ) |
| assert.StringsEqual(t, |
| info.GetModem().GetGeneric().GetSim(), |
| sim, |
| ) |
| assert.StringArrsEqual(t, |
| info.GetModem().GetGeneric().GetSimSlots(), |
| []string{simSlots}, |
| ) |
| assert.StringArrsEqual(t, |
| info.GetModem().GetGeneric().GetOwnNumbers(), |
| []string{ownNumbers}, |
| ) |
| } |