-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Shubham <[email protected]>
- Loading branch information
1 parent
74be2a2
commit e3308b1
Showing
2 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2021 VMware, Inc. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// nolint: testpackage | ||
package registration | ||
|
||
import ( | ||
"fmt" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
func getMockFile(targetOs string) ([]byte, error) { | ||
out := fmt.Sprintf(`NAME="Ubuntu" | ||
VERSION="20.04.4 LTS (Focal Fossa)" | ||
ID=ubuntu | ||
ID_LIKE=debian | ||
PRETTY_NAME="%s" | ||
VERSION_ID="20.04" | ||
HOME_URL="https://www.ubuntu.com/" | ||
SUPPORT_URL="https://help.ubuntu.com/" | ||
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" | ||
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" | ||
VERSION_CODENAME=focal | ||
UBUNTU_CODENAME=focal`, targetOs) | ||
return []byte(out), nil | ||
} | ||
|
||
var _ = Describe("Host Registrar Tests", func() { | ||
|
||
var ( | ||
targetOs = "Ubuntu 20.04.4 LTS" | ||
) | ||
|
||
Context("When the OS is detected", func() { | ||
It("Should return the operating system for os following /etc/os-release", func() { | ||
detectedOS, err := getOperatingSystem(func(string) ([]byte, error) { return getMockFile(targetOs) }) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
Expect(detectedOS).To(Equal("Ubuntu 20.04.4 LTS")) | ||
}) | ||
|
||
It("Should return the operating system for os following /usr/lib/os-release", func() { | ||
targetOs = "Clear Linux Initramfs" | ||
detectedOS, err := getOperatingSystem(func(releaseFile string) ([]byte, error) { | ||
if releaseFile == "/etc/os-release" { | ||
return nil, os.ErrNotExist | ||
} | ||
return getMockFile(targetOs) | ||
}) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
Expect(detectedOS).To(Equal("Clear Linux Initramfs")) | ||
}) | ||
|
||
It("Should not error with real hostnamectl", func() { | ||
_, err := getOperatingSystem(ioutil.ReadFile) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
}) | ||
}) | ||
}) |