Skip to content

Commit

Permalink
t.error to t.fatal
Browse files Browse the repository at this point in the history
Signed-off-by: Ayush Rangwala <[email protected]>
  • Loading branch information
aayushrangwala committed Dec 14, 2023
1 parent 578a0a5 commit 9335b44
Show file tree
Hide file tree
Showing 27 changed files with 347 additions and 279 deletions.
63 changes: 42 additions & 21 deletions test/e2e/capacitytest/capacity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ func TestCli_Capacity(t *testing.T) {
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
t.Cleanup(func() {
w.Close()
os.Stdout = rescueStdout
})

if err := root.Execute(); err != nil {
t.Error(err)
t.Fatal(err)
}
w.Close()

out, _ := io.ReadAll(r)
os.Stdout = rescueStdout
if !strings.Contains(string(out[:]), "n3.xlarge.x86") &&
!strings.Contains(string(out[:]), "m3.large.x86") &&
!strings.Contains(string(out[:]), "s3.xlarge.x86") &&
Expand All @@ -70,12 +74,16 @@ func TestCli_Capacity(t *testing.T) {
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
t.Cleanup(func() {
w.Close()
os.Stdout = rescueStdout
})

if err := root.Execute(); err != nil {
t.Error(err)
t.Fatal(err)
}
w.Close()

out, _ := io.ReadAll(r)
os.Stdout = rescueStdout
if !strings.Contains(string(out[:]), "c3.small.x86") &&
!strings.Contains(string(out[:]), "mt") &&
!strings.Contains(string(out[:]), "sv") &&
Expand All @@ -99,12 +107,16 @@ func TestCli_Capacity(t *testing.T) {
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
t.Cleanup(func() {
w.Close()
os.Stdout = rescueStdout
})

if err := root.Execute(); err != nil {
t.Error(err)
t.Fatal(err)
}
w.Close()

out, _ := io.ReadAll(r)
os.Stdout = rescueStdout
if !strings.Contains(string(out[:]), "m3.large.x86") &&
!strings.Contains(string(out[:]), "mt") &&
!strings.Contains(string(out[:]), "sv") &&
Expand All @@ -127,13 +139,16 @@ func TestCli_Capacity(t *testing.T) {
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
t.Cleanup(func() {
w.Close()
os.Stdout = rescueStdout
})

if err := root.Execute(); err != nil {
t.Error(err)
return
t.Fatal(err)
}
w.Close()

out, _ := io.ReadAll(r)
os.Stdout = rescueStdout
if !strings.Contains(string(out[:]), "c3.medium.x86") &&
!strings.Contains(string(out[:]), "ny") &&
!strings.Contains(string(out[:]), "da") {
Expand All @@ -154,13 +169,16 @@ func TestCli_Capacity(t *testing.T) {
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
t.Cleanup(func() {
w.Close()
os.Stdout = rescueStdout
})

if err := root.Execute(); err != nil {
t.Error(err)
return
t.Fatal(err)
}
w.Close()

out, _ := io.ReadAll(r)
os.Stdout = rescueStdout
if !strings.Contains(string(out[:]), "c3.medium.x86") &&
!strings.Contains(string(out[:]), "m3.large.x86") &&
!strings.Contains(string(out[:]), "ny") &&
Expand All @@ -182,13 +200,16 @@ func TestCli_Capacity(t *testing.T) {
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
t.Cleanup(func() {
w.Close()
os.Stdout = rescueStdout
})

if err := root.Execute(); err != nil {
t.Error(err)
return
t.Fatal(err)
}
w.Close()

out, _ := io.ReadAll(r)
os.Stdout = rescueStdout
if !strings.Contains(string(out[:]), "c3.medium.x86") &&
!strings.Contains(string(out[:]), "m3.large.x86") &&
!strings.Contains(string(out[:]), "ny") &&
Expand Down
38 changes: 15 additions & 23 deletions test/e2e/devices/devicecreateflagstest/device_create_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
func TestCli_Devices_Create_Flags(t *testing.T) {
var projectId, deviceId string
var err error
var resp bool
subCommand := "device"
consumerToken := ""
apiURL := ""
Expand Down Expand Up @@ -51,8 +50,7 @@ func TestCli_Devices_Create_Flags(t *testing.T) {
}
})
if err != nil {
t.Error(err)
return
t.Fatal(err)
}

if len(projectId) != 0 {
Expand All @@ -61,19 +59,16 @@ func TestCli_Devices_Create_Flags(t *testing.T) {
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
t.Cleanup(func() {
w.Close()
os.Stdout = rescueStdout
})

if err := root.Execute(); err != nil {
t.Error(err)
return
t.Fatal(err)
}
w.Close()

out, _ := io.ReadAll(r)
os.Stdout = rescueStdout
t.Cleanup(func() {
if err := helper.CleanTestDevice(t, deviceId); err != nil &&
!strings.Contains(err.Error(), "Not Found") {
t.Error(err)
}
})

if !strings.Contains(string(out[:]), "metal-cli-create-flags-dev") &&
!strings.Contains(string(out[:]), "Ubuntu 20.04 LTS") &&
Expand All @@ -89,18 +84,15 @@ func TestCli_Devices_Create_Flags(t *testing.T) {
// Extract the ID from the match
if len(match) > 1 {
deviceId = strings.TrimSpace(match[1])
resp, err = helper.IsDeviceStateActive(t, deviceId)
if err == nil && resp == true {
err = helper.CleanTestDevice(t, deviceId)
if err != nil {
t.Error(err)
}
err = helper.CleanTestProject(t, projectId)
if err != nil {
_, err = helper.IsDeviceStateActive(t, deviceId)
t.Cleanup(func() {
if err := helper.CleanTestDevice(t, deviceId); err != nil &&
!strings.Contains(err.Error(), "Not Found") {
t.Error(err)
}
} else {
t.Error(err)
})
if err != nil {
t.Fatal(err)
}
}
}
Expand Down
40 changes: 15 additions & 25 deletions test/e2e/devices/devicecreatetest/device_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
func TestCli_Devices_Create(t *testing.T) {
var projectId, deviceId string
var err error
var resp bool
subCommand := "device"
consumerToken := ""
apiURL := ""
Expand Down Expand Up @@ -51,8 +50,7 @@ func TestCli_Devices_Create(t *testing.T) {
}
})
if err != nil {
t.Error(err)
return
t.Fatal(err)
}

if len(projectId) != 0 {
Expand All @@ -62,20 +60,16 @@ func TestCli_Devices_Create(t *testing.T) {
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
t.Cleanup(func() {
w.Close()
os.Stdout = rescueStdout
})

if err := root.Execute(); err != nil {
t.Error(err)
return
t.Fatal(err)
}
w.Close()
out, _ := io.ReadAll(r)
os.Stdout = rescueStdout

t.Cleanup(func() {
if err := helper.CleanTestDevice(t, deviceId); err != nil &&
!strings.Contains(err.Error(), "Not Found") {
t.Error(err)
}
})
out, _ := io.ReadAll(r)

if !strings.Contains(string(out[:]), deviceName) &&
!strings.Contains(string(out[:]), "Ubuntu 20.04 LTS") &&
Expand All @@ -91,19 +85,15 @@ func TestCli_Devices_Create(t *testing.T) {
// Extract the ID from the match
if len(match) > 1 {
deviceId = strings.TrimSpace(match[1])
resp, err = helper.IsDeviceStateActive(t, deviceId)
if err != nil || resp {
if !resp {
resp, err = helper.IsDeviceStateActive(t, deviceId)
}
err = helper.CleanTestDevice(t, deviceId)
if err != nil {
t.Error(err)
}
err = helper.CleanTestProject(t, projectId)
if err != nil {
_, err = helper.IsDeviceStateActive(t, deviceId)
t.Cleanup(func() {
if err := helper.CleanTestDevice(t, deviceId); err != nil &&
!strings.Contains(err.Error(), "Not Found") {
t.Error(err)
}
})
if err != nil {
t.Fatal(err)
}
}
}
Expand Down
47 changes: 17 additions & 30 deletions test/e2e/devices/devicegettest/device_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
func TestCli_Devices_Get(t *testing.T) {
var projectId, deviceId string
var err error
var resp bool
subCommand := "device"
consumerToken := ""
apiURL := ""
Expand Down Expand Up @@ -50,49 +49,37 @@ func TestCli_Devices_Get(t *testing.T) {
}
})
if err != nil {
t.Error(err)
return
t.Fatal(err)
}

deviceId, err = helper.CreateTestDevice(t, projectId, "metal-cli-get-dev")
t.Cleanup(func() {
if err := helper.CleanTestDevice(t, deviceId); err != nil &&
!strings.Contains(err.Error(), "Not Found") {
t.Error(err)
}
})
if err != nil {
t.Error(err)
return
t.Fatal(err)
}

root.SetArgs([]string{subCommand, "get", "-i", deviceId})
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
t.Cleanup(func() {
w.Close()
os.Stdout = rescueStdout
})

if err := root.Execute(); err != nil {
t.Error(err)
t.Fatal(err)
}
w.Close()

out, _ := io.ReadAll(r)
os.Stdout = rescueStdout
t.Cleanup(func() {
if err := helper.CleanTestDevice(t, deviceId); err != nil &&
!strings.Contains(err.Error(), "Not Found") {
t.Error(err)
}
})

if !strings.Contains(string(out[:]), deviceId) {
t.Error("expected output should include " + deviceId)
}
if len(projectId) != 0 && len(deviceId) != 0 {
resp, err = helper.IsDeviceStateActive(t, deviceId)
if err == nil && resp == true {
err = helper.CleanTestDevice(t, deviceId)
if err != nil {
t.Error(err)
}
err = helper.CleanTestProject(t, projectId)
if err != nil {
t.Error(err)
}
} else {
t.Error(err)
}
t.Fatal("expected output should include " + deviceId)
}
},
},
Expand Down
Loading

0 comments on commit 9335b44

Please sign in to comment.