| // 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 cros |
| |
| import ( |
| "context" |
| "fmt" |
| "testing" |
| "time" |
| |
| "go.chromium.org/luci/common/testing/truth/assert" |
| "go.chromium.org/luci/common/testing/truth/should" |
| |
| "go.chromium.org/infra/cros/recovery/internal/components" |
| ) |
| |
| func TestNormalizeVendorProductSku(t *testing.T) { |
| t.Parallel() |
| |
| assert.That(t, normalizeVendorProductSku("spiffy_1234"), should.Equal("google_spiffy")) |
| } |
| |
| func TestValidateFRID(t *testing.T) { |
| t.Parallel() |
| |
| assert.That(t, validateFRID(""), should.ErrLike("cannot be empty")) |
| assert.That(t, validateFRID("google_A"), should.ErrLike("not exclusively lowercase")) |
| assert.That(t, validateFRID("notgoogle_spiffy"), should.ErrLike("missing google_ prefix")) |
| } |
| |
| func TestReadFRID(t *testing.T) { |
| t.Parallel() |
| |
| ctx := context.Background() |
| |
| var runner components.Runner = func(_ context.Context, _ time.Duration, cmd string, args ...string) (string, error) { |
| switch cmd { |
| case "getprop": |
| return "spiffy_12345", nil |
| } |
| panic(fmt.Sprintf("bad command %q %v", cmd, args)) |
| } |
| |
| frid, err := ReadFRID(ctx, time.Minute, runner) |
| assert.NoErr(t, err) |
| assert.That(t, frid, should.Match("google_spiffy")) |
| } |