-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✅ add test by host #2
Open
dzove855
wants to merge
7
commits into
main
Choose a base branch
from
add_tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b211978
:white_check_mark: add test by host
dzove855 d670dc6
:construction_worker: remove mockserver
dzove855 e1a8686
:construction_worker: :green_heart: add github secrets
dzove855 4ab19b1
:construction_worker: :green_heart: fix env key word
dzove855 a9edd88
:white_check_mark: add multiple tests
dzove855 06c75ed
:white_check_mark: add testify
dzove855 eaf2017
:construction_worker: add golang test verbosity
dzove855 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -6,6 +6,88 @@ import ( | |
"os" | ||
) | ||
|
||
func TestHostCreate(t *testing.T) { | ||
netbox.NETBOX_URL = os.Getenv("NETBOX_URL") | ||
netbox.NETBOX_TOKEN = os.Getenv("NETBOX_TOKEN") | ||
|
||
host, err := HostCreate(HostCreateStruct{Name: "testhost", Endpoint: "http://test:[email protected]:1880/"}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if host.Name != "testhost" { | ||
t.Fatal(host.Name) | ||
} | ||
} | ||
|
||
func TestRegistryCreate(t *testing.T) { | ||
netbox.NETBOX_URL = os.Getenv("NETBOX_URL") | ||
netbox.NETBOX_TOKEN = os.Getenv("NETBOX_TOKEN") | ||
|
||
host, err := HostSearchByName("testhost") | ||
registry, err := RegistryCreate(RegistryCreateStruct{Name: "testregistry", ServerAddress: "http://test.com:5000", Username: "test", Password: "test", Host: host.Id}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if registry.Name != "testregistry" { | ||
t.Fatal(registry.Name) | ||
} | ||
} | ||
|
||
func TestImageCreate(t *testing.T) { | ||
netbox.NETBOX_URL = os.Getenv("NETBOX_URL") | ||
netbox.NETBOX_TOKEN = os.Getenv("NETBOX_TOKEN") | ||
|
||
host, err := HostSearchByName("testhost") | ||
registry, err := RegistrySearchByName("testregistry", host.Id) | ||
|
||
image, err := ImageCreate(ImageCreateStruct{Name: "testimage", Host: host.Id, Registry: registry.Id, ImageID: "0", Version: "0"}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if image.Name != "testimage" { | ||
t.Fatal(image.Name) | ||
} | ||
} | ||
|
||
func TestContainerCreate(t *testing.T) { | ||
netbox.NETBOX_URL = os.Getenv("NETBOX_URL") | ||
netbox.NETBOX_TOKEN = os.Getenv("NETBOX_TOKEN") | ||
|
||
host, err := HostSearchByName("testhost") | ||
image, err := ImageSearchByName("testimage", host.Id) | ||
|
||
containerS := ContainerCreateStruct{Name: "testcontainer", Host: host.Id, Image: image.Id, State: "none", Operation: "create"} | ||
containerS.Restart_policy = "no" | ||
containerS.Labels = []Label{} | ||
containerS.Env = []Env{} | ||
containerS.Ports = []Port{} | ||
containerS.Mounts = []Mount{} | ||
containerS.NetworkSettings = []Network{} | ||
|
||
container, err := ContainerCreate(containerS) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if container.Name != "testcontainer" { | ||
t.Fatal(container.Name) | ||
} | ||
} | ||
|
||
func TestVolumeCreate(t *testing.T) { | ||
netbox.NETBOX_URL = os.Getenv("NETBOX_URL") | ||
netbox.NETBOX_TOKEN = os.Getenv("NETBOX_TOKEN") | ||
|
||
host, err := HostSearchByName("testhost") | ||
|
||
volume, err := VolumeCreate(VolumeCreateStruct{Name: "testvolume", Host: host.Id, Driver: "local"}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if volume.Name != "testvolume" { | ||
t.Fatal(volume.Name) | ||
} | ||
} | ||
|
||
func TestVolumeList(t *testing.T) { | ||
netbox.NETBOX_URL = os.Getenv("NETBOX_URL") | ||
netbox.NETBOX_TOKEN = os.Getenv("NETBOX_TOKEN") | ||
|
@@ -14,7 +96,86 @@ func TestVolumeList(t *testing.T) { | |
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if len(vols.Results) != 2 { | ||
if len(vols.Results) == 0 { | ||
t.Fatal("No volumes found") | ||
} | ||
} | ||
|
||
func TestVolumeListByHost(t *testing.T) { | ||
netbox.NETBOX_URL = os.Getenv("NETBOX_URL") | ||
netbox.NETBOX_TOKEN = os.Getenv("NETBOX_TOKEN") | ||
|
||
host, err := HostSearchByName("testhost") | ||
vols, err := VolumeListByHost(host.Id) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if len(vols.Results) > 0 { | ||
if vols.Results[0].Host.Name != "testhost" { | ||
t.Fatal(vols.Results[0].Host.Name) | ||
} | ||
} else { | ||
t.Fatal("No volumes found") | ||
} | ||
} | ||
|
||
func TestContainerDelete(t *testing.T) { | ||
netbox.NETBOX_URL = os.Getenv("NETBOX_URL") | ||
netbox.NETBOX_TOKEN = os.Getenv("NETBOX_TOKEN") | ||
|
||
host, err := HostSearchByName("testhost") | ||
container, err := ContainerSearchByName(host, "testcontainer") | ||
err = ContainerDelete(container.Id) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
} | ||
|
||
func TestVolumeDelete(t *testing.T) { | ||
netbox.NETBOX_URL = os.Getenv("NETBOX_URL") | ||
netbox.NETBOX_TOKEN = os.Getenv("NETBOX_TOKEN") | ||
|
||
host, err := HostSearchByName("testhost") | ||
volume, err := VolumeSearchByName("testvolume", host.Id) | ||
err = VolumeDelete(volume.Id) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestImageDelete(t *testing.T) { | ||
netbox.NETBOX_URL = os.Getenv("NETBOX_URL") | ||
netbox.NETBOX_TOKEN = os.Getenv("NETBOX_TOKEN") | ||
|
||
host, err := HostSearchByName("testhost") | ||
image, err := ImageSearchByName("testimage", host.Id) | ||
err = ImageDelete(image.Id) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestRegistryDelete(t *testing.T) { | ||
netbox.NETBOX_URL = os.Getenv("NETBOX_URL") | ||
netbox.NETBOX_TOKEN = os.Getenv("NETBOX_TOKEN") | ||
|
||
host, err := HostSearchByName("testhost") | ||
registry, err := RegistrySearchByName("testregistry", host.Id) | ||
err = RegistryDelete(registry.Id) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestHostDelete(t *testing.T) { | ||
netbox.NETBOX_URL = os.Getenv("NETBOX_URL") | ||
netbox.NETBOX_TOKEN = os.Getenv("NETBOX_TOKEN") | ||
|
||
host, err := HostSearchByName("testhost") | ||
err = HostDelete(host.Id) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function err(err) {
if err != nil {
t.Fatal(err)
}
err(VolumeSearchByName("testvolume", host.Id))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not idiomatic go, this is: