Skip to content
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

start of update tests #60

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ Use the [hacking guide](HACKING.md) to run local acceptance testing and debuggin
Currently test cases are not supported portion of our CI/CD approval process but might be made available from this test suite in the future. Contributions to the test suite is appreciated.

## License
This project is licensed under the Apache License, Version 2.0. See LICENSE for full license text.
This project is licensed under the Apache License, Version 2.0. See LICENSE for full license text.
8 changes: 4 additions & 4 deletions ov/api_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestGetAPIVersion(t *testing.T) {
c *OVClient
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
d, c = getTestDriverA()
d, c = getTestDriverA("dev")
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
Expand All @@ -26,7 +26,7 @@ func TestGetAPIVersion(t *testing.T) {
assert.Equal(t, true, d.Tc.EqualFaceI(d.Tc.GetExpectsData(d.Env, "CurrentVersion"), data.CurrentVersion))
assert.Equal(t, true, d.Tc.EqualFaceI(d.Tc.GetExpectsData(d.Env, "MinimumVersion"), data.MinimumVersion))
} else {
_, c = getTestDriverU()
_, c = getTestDriverU("dev")
data, err := c.GetAPIVersion()
assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, data))
}
Expand All @@ -40,7 +40,7 @@ func TestRefreshVersion(t *testing.T) {
c *OVClient
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
d, c = getTestDriverA()
d, c = getTestDriverA("dev")
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
Expand All @@ -50,7 +50,7 @@ func TestRefreshVersion(t *testing.T) {
assert.NoError(t, err, "RefreshVersion threw error -> %s", err)
assert.True(t, d.Tc.EqualFaceI(d.Tc.GetExpectsData(d.Env, "CurrentVersion"), c.APIVersion))
} else {
_, c = getTestDriverU()
_, c = getTestDriverU("dev")
err := c.RefreshVersion()
assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s", err))
}
Expand Down
26 changes: 14 additions & 12 deletions ov/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"
"testing"
"time"
//"time"

"github.com/docker/machine/libmachine/log"
"github.com/stretchr/testify/assert"
Expand All @@ -18,7 +18,7 @@ func TestSessionLogin(t *testing.T) {
// env = os.Getenv("ONEVIEW_TEST_ENV") || "dev"
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
_, c = getTestDriverA()
_, c = getTestDriverA("dev")
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
Expand All @@ -35,7 +35,7 @@ func TestSessionLogin(t *testing.T) {
data, err = c.SessionLogin()
assert.NoError(t, err, "SessionLogin threw error -> %s", err)
} else {
_, c = getTestDriverU()
_, c = getTestDriverU("dev")
data, err := c.SessionLogin()
assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, data))
assert.Equal(t, "none", c.APIKey)
Expand All @@ -50,7 +50,7 @@ func TestSessionLogout(t *testing.T) {
//testSerial string
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
_, c = getTestDriverA()
_, c = getTestDriverA("dev")
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
Expand All @@ -68,7 +68,7 @@ func TestSessionLogout(t *testing.T) {
//_, err = c.GetProfileBySN(testSerial)
//assert.Error(t, err, "SessionLogin threw error -> %s", err)
} else {
/*_, c = getTestDriverU()
/*_, c = getTestDriverU("dev")
data, err := c.SessionLogin()
assert.Error(t,err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n",err, data))
assert.Equal(t, "none", c.APIKey)
Expand All @@ -83,7 +83,7 @@ func TestGetIdleTimeout(t *testing.T) {
// d *OVTest
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
_, c = getTestDriverA()
_, c = getTestDriverA("dev")
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
Expand All @@ -106,7 +106,7 @@ func TestSetIdleTimeout(t *testing.T) {
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
testtime = 25000
_, c = getTestDriverA()
_, c = getTestDriverA("dev")
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
Expand All @@ -125,14 +125,15 @@ func TestSetIdleTimeout(t *testing.T) {

}

/*
// Test for expired key and see if RefreshLogin can restore the key if we have a bad key
func TestSessionExpiredKey(t *testing.T) {
var (
c *OVClient
d *OVTest
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
d, c = getTestDriverA()
d, c = getTestDriverA("test_ethernet_network")
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
Expand All @@ -152,11 +153,12 @@ func TestSessionExpiredKey(t *testing.T) {

// verify that we can access something from icps with this client
// This should not fail because it uses RefreshLogin to get a new login session and avoid timeout
profileName := d.Tc.GetTestData(d.Env, "ServerProfileName").(string)
data, err := c.GetProfileByName(profileName)
assert.NoError(t, err, "GetProfileByName threw error -> %s", err)
assert.Equal(t, profileName, data.Name)
ethNetName := d.Tc.GetTestData(d.Env, "Name").(string)
data, err := c.GetEthernetNetworkByName(ethNetName)
assert.NoError(t, err, "GetEthNetByName threw error -> %s", err)
assert.Equal(t, ethNetName, data.Name)

}

}
*/
2 changes: 1 addition & 1 deletion ov/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestConnections(t *testing.T) {
c *OVClient
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
d, c = getTestDriverA()
d, c = getTestDriverA("dev")
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
Expand Down
16 changes: 8 additions & 8 deletions ov/ov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ type OVTest struct {
}

// get Environment
func (ot *OVTest) GetEnvironment() {
func (ot *OVTest) GetEnvironment(env string) {
if os.Getenv("ONEVIEW_TEST_ENV") != "" {
ot.Env = os.Getenv("ONEVIEW_TEST_ENV")
return
}
ot.Env = "dev"
ot.Env = env
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to understand why we want this. Could you explain the challenge your facing with not letting environment represent a default globally for all test here and what use case we're solving by allowing every test case to define their own default environment value? My thoughts on environment was that we could add progressively complex testing for things like a test and production environment in the future, but in this scenario, I'm thinking we might just be moving a default that should be located here to all other test case calls.... wanted to get your take on this.

Copy link
Contributor Author

@mbfrahry mbfrahry Jul 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So at the time, it seemed like this was server_profile test specific. So when I was adding new tests I added tests specific to other things. It keeps the test chunks small and specific to the tests we are running. I might have misunderstood this though. My test data looks like

{
  "name": "dev"
  //initial test data
},
{
  "name": "test_ethernet_network",
  // data for ethernet
}
.
.
.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that makes sense... so instead of environments, we are really saying we can purpose this as a way to select test specific to a particular unit case where we can start separating.... I think your way might actually be cleaner, it's to bad go doesn't support defaults. Then we wouldn't need to pass arguments like "dev" every time. OK, I'll accept that as a good way to go +1.

I'm going to merge my other PR for the make process, this should allow you to rebase and try this build again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect!

return
}

// get a test driver for acceptance testing
func getTestDriverA() (*OVTest, *OVClient) {
func getTestDriverA(env string) (*OVTest, *OVClient) {
// os.Setenv("DEBUG", "true") // remove comment to debug logs
var ot *OVTest
var tc *testconfig.TestConfig
ot = &OVTest{Tc: tc.NewTestConfig(), Env: "dev"}
ot.GetEnvironment()
ot = &OVTest{Tc: tc.NewTestConfig(), Env: env}
ot.GetEnvironment(env)
ot.Tc.GetTestingConfiguration(os.Getenv("ONEVIEW_TEST_DATA"))
ot.Client = &OVClient{
rest.Client{
Expand All @@ -70,11 +70,11 @@ func getTestDriverA() (*OVTest, *OVClient) {
}

// Unit test
func getTestDriverU() (*OVTest, *OVClient) {
func getTestDriverU(env string) (*OVTest, *OVClient) {
var ot *OVTest
var tc *testconfig.TestConfig
ot = &OVTest{Tc: tc.NewTestConfig(), Env: "dev"}
ot.GetEnvironment()
ot = &OVTest{Tc: tc.NewTestConfig(), Env: env}
ot.GetEnvironment(env)
ot.Tc.GetTestingConfiguration(os.Getenv("ONEVIEW_TEST_DATA"))
ot.Client = &OVClient{
rest.Client{
Expand Down
2 changes: 1 addition & 1 deletion ov/power_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestPowerState(t *testing.T) {
expectsData string
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
d, c = getTestDriverA()
d, c = getTestDriverA("dev")
testData = utils.Nstring(d.Tc.GetTestData(d.Env, "ServerHardwareURI").(string))
expectsData = d.Tc.GetExpectsData(d.Env, "SerialNumber").(string)
if c == nil {
Expand Down
4 changes: 2 additions & 2 deletions ov/profile_templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestGetProfileTemplateByName(t *testing.T) {
testname string
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
d, c = getTestDriverA()
d, c = getTestDriverA("dev")
// determine if we should execute
testname = d.Tc.GetTestData(d.Env, "TemplateProfile").(string)
if c == nil {
Expand All @@ -31,7 +31,7 @@ func TestGetProfileTemplateByName(t *testing.T) {
assert.Equal(t, "", data.Name)

} else {
d, c = getTestDriverU()
d, c = getTestDriverU("dev")
// determine if we should execute
if c.ProfileTemplatesNotSupported() {
return
Expand Down
24 changes: 12 additions & 12 deletions ov/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestCreateProfileFromTemplate(t *testing.T) {
testTemplate ServerProfile
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
d, c = getTestDriverA()
d, c = getTestDriverA("dev")
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestGetProfileByName(t *testing.T) {
testname string
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
d, c = getTestDriverA()
d, c = getTestDriverA("dev")
testname = d.Tc.GetTestData(d.Env, "ServerProfileName").(string)
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
Expand All @@ -99,7 +99,7 @@ func TestGetProfileByName(t *testing.T) {
assert.Equal(t, "", data.Name)

} else {
d, c = getTestDriverU()
d, c = getTestDriverU("dev")
testname = d.Tc.GetTestData(d.Env, "ServerProfileName").(string)
data, err := c.GetProfileByName(testname)
assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, data))
Expand All @@ -114,7 +114,7 @@ func TestGetConnectionByName(t *testing.T) {
testname string
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
d, c = getTestDriverA()
d, c = getTestDriverA("dev")
testname = d.Tc.GetTestData(d.Env, "ServerProfileName").(string)
pubcname := d.Tc.GetTestData(d.Env, "FreePublicConnection").(string)
expectsmac := d.Tc.GetExpectsData(d.Env, "MACAddress").(string)
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestGetProfileBySN(t *testing.T) {
testSerial string
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
d, c = getTestDriverA()
d, c = getTestDriverA("dev")
testSerial = d.Tc.GetTestData(d.Env, "SerialNumber").(string)
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
Expand All @@ -160,7 +160,7 @@ func TestGetProfileBySN(t *testing.T) {
assert.Equal(t, "null", data.SerialNumber.String())

} else {
d, c = getTestDriverU()
d, c = getTestDriverU("dev")
testSerial = d.Tc.GetTestData(d.Env, "SerialNumber").(string)
data, err := c.GetProfileBySN(testSerial)
assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, data))
Expand All @@ -174,7 +174,7 @@ func TestGetProfiles(t *testing.T) {
c *OVClient
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
_, c = getTestDriverA()
_, c = getTestDriverA("dev")
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
Expand All @@ -185,7 +185,7 @@ func TestGetProfiles(t *testing.T) {
assert.NoError(t, err, "GetProfiles name:asc error -> %s, %+v", err, data)

} else {
_, c = getTestDriverU()
_, c = getTestDriverU("dev")
data, err := c.GetProfiles("", "")
assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, data))
}
Expand All @@ -200,7 +200,7 @@ func TestDeleteProfileNotFound(t *testing.T) {
testProfile ServerProfile
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
_, c = getTestDriverA()
_, c = getTestDriverA("dev")
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
Expand All @@ -212,7 +212,7 @@ func TestDeleteProfileNotFound(t *testing.T) {
assert.NoError(t, err, "GetProfileByName with deleted profile -> %+v", err)
assert.Equal(t, "", testProfile.Name, fmt.Sprintf("Problem getting template name, %+v", testProfile))
} else {
_, c = getTestDriverU()
_, c = getTestDriverU("dev")
err := c.DeleteProfile(testProfileName)
assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, testProfile))
}
Expand All @@ -227,7 +227,7 @@ func TestDeleteProfile(t *testing.T) {
testProfile ServerProfile
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
d, c = getTestDriverA()
d, c = getTestDriverA("dev")
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
Expand All @@ -240,7 +240,7 @@ func TestDeleteProfile(t *testing.T) {
assert.NoError(t, err, "GetProfileByName with deleted profile -> %+v", err)
assert.Equal(t, "", testProfile.Name, fmt.Sprintf("Problem getting template name, %+v", testProfile))
} else {
_, c = getTestDriverU()
_, c = getTestDriverU("dev")
err := c.DeleteProfile("footest")
assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, testProfile))
}
Expand Down
6 changes: 3 additions & 3 deletions ov/server_hardware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestServerHardware(t *testing.T) {
expectsData string
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
d, c = getTestDriverA()
d, c = getTestDriverA("dev")
testData = utils.Nstring(d.Tc.GetTestData(d.Env, "ServerHardwareURI").(string))
expectsData = d.Tc.GetExpectsData(d.Env, "SerialNumber").(string)
if c == nil {
Expand All @@ -42,7 +42,7 @@ func TestGetAvailableHardware(t *testing.T) {
testHWGroup_URI utils.Nstring
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
d, c = getTestDriverA()
d, c = getTestDriverA("dev")
testHwType_URI = utils.Nstring(d.Tc.GetTestData(d.Env, "HardwareTypeURI").(string))
testHWGroup_URI = utils.Nstring(d.Tc.GetTestData(d.Env, "GroupURI").(string))
if c == nil {
Expand All @@ -68,7 +68,7 @@ func TestGetIloIPAddress(t *testing.T) {
expectsData string
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
d, c = getTestDriverA()
d, c = getTestDriverA("dev")
testData = utils.Nstring(d.Tc.GetTestData(d.Env, "ServerHardwareURI").(string))
expectsData = d.Tc.GetExpectsData(d.Env, "IloIPAddress").(string)
if c == nil {
Expand Down