Skip to content

Commit c681553

Browse files
spec: add missing TestSpec tests for agentdrain.Miner.Train and cli.SetVersionInfo (#29763)
1 parent b1a9569 commit c681553

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

pkg/agentdrain/spec_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,20 @@ func TestSpec_PublicAPI_Miner_ClusterCount_SPEC_MISMATCH(t *testing.T) {
494494
assert.Len(t, miner.Clusters(), 1, "cluster count should be 1 after training one unique event")
495495
}
496496

497+
// TestSpec_PublicAPI_Miner_Train validates that Miner.Train processes a raw log line.
498+
// Spec: "Process a raw log line (training + matching in one step)"
499+
func TestSpec_PublicAPI_Miner_Train(t *testing.T) {
500+
cfg := agentdrain.DefaultConfig()
501+
miner, err := agentdrain.NewMiner(cfg)
502+
require.NoError(t, err)
503+
504+
result, err := miner.Train("user action completed step 1 successfully")
505+
require.NoError(t, err, "Train should not error on a valid raw log line")
506+
assert.NotNil(t, result, "Train should return a non-nil MatchResult")
507+
assert.Positive(t, result.ClusterID, "Train result ClusterID should be positive")
508+
assert.NotEmpty(t, result.Template, "Train result Template should be a non-empty space-joined string")
509+
}
510+
497511
// TestSpec_Types_Snapshot validates the documented Snapshot/SnapshotCluster type structures.
498512
// Spec: Snapshot{Config, Clusters []SnapshotCluster, NextID}, SnapshotCluster{ID, Template, Size, Stage}.
499513
func TestSpec_Types_Snapshot(t *testing.T) {

pkg/cli/spec_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,16 @@ func TestSpec_PublicAPI_GetVersion(t *testing.T) {
841841
assert.NotEmpty(t, version, "GetVersion should return a non-empty version string")
842842
}
843843

844+
// TestSpec_PublicAPI_SetVersionInfo validates that SetVersionInfo stores the version returned by GetVersion.
845+
// Spec: "Sets the version at startup"
846+
func TestSpec_PublicAPI_SetVersionInfo(t *testing.T) {
847+
original := GetVersion()
848+
t.Cleanup(func() { SetVersionInfo(original) })
849+
850+
SetVersionInfo("v99.99.99-spec-test")
851+
assert.Equal(t, "v99.99.99-spec-test", GetVersion(), "GetVersion should return the value set by SetVersionInfo")
852+
}
853+
844854
// TestSpec_PublicAPI_IsRunningInCI validates that IsRunningInCI returns a bool without panicking.
845855
// Spec: detects CI environment.
846856
func TestSpec_PublicAPI_IsRunningInCI(t *testing.T) {

0 commit comments

Comments
 (0)