refactor: implement mocking functions and tests
This commit is contained in:
parent
339dba4e13
commit
f8ef2ef2d5
21 changed files with 398 additions and 90 deletions
50
osinfo_test.go
Normal file
50
osinfo_test.go
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// osmanager_test.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewOSManager(t *testing.T) {
|
||||
os := &OS{ID: "ubuntu", PackageManager: "apt"}
|
||||
sudoPassword := "testpassword"
|
||||
packages := []string{"git", "curl"}
|
||||
|
||||
manager := NewOSManager(os, sudoPassword, packages)
|
||||
|
||||
if manager.OS != os {
|
||||
t.Errorf("Expected OS to be %v, got %v", os, manager.OS)
|
||||
}
|
||||
if manager.SudoPassword != sudoPassword {
|
||||
t.Errorf("Expected SudoPassword to be %s, got %s", sudoPassword, manager.SudoPassword)
|
||||
}
|
||||
if len(manager.Packages) != len(packages) {
|
||||
t.Errorf("Expected Packages length to be %d, got %d", len(packages), len(manager.Packages))
|
||||
}
|
||||
}
|
||||
|
||||
func TestOSManagerName(t *testing.T) {
|
||||
manager := &OSManager{}
|
||||
if manager.Name() != "OS Package Manager" {
|
||||
t.Errorf("Expected name to be 'OS Package Manager', got %s", manager.Name())
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseOsRelease(t *testing.T) {
|
||||
osReleaseContent := `
|
||||
ID=ubuntu
|
||||
NAME="Ubuntu"
|
||||
VERSION_ID="20.04"
|
||||
`
|
||||
os := parseOsRelease(osReleaseContent)
|
||||
|
||||
if os.ID != "ubuntu" {
|
||||
t.Errorf("Expected ID to be 'ubuntu', got %s", os.ID)
|
||||
}
|
||||
if os.Name != "Ubuntu" {
|
||||
t.Errorf("Expected Name to be 'Ubuntu', got %s", os.Name)
|
||||
}
|
||||
if os.Version != "20.04" {
|
||||
t.Errorf("Expected Version to be '20.04', got %s", os.Version)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue