Skip to content

Commit

Permalink
add unit test for determineUserAddr
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuchard committed Sep 27, 2024
1 parent ebd986f commit 8c72644
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
31 changes: 30 additions & 1 deletion provisioner/testinfra_communication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,36 @@ func TestProvisionerDetermineCommunication(test *testing.T) {
}
}

// test provisioner determineSSHAuth properly determines ssh private key file location
// test provisioner determineUserAddr properly determines user and instance address
func TestDetermineUserAddr(test *testing.T) {
var provisioner Provisioner

// dummy up fake user and address data
generatedData := map[string]interface{}{
"User": "me",
"Host": "192.168.0.1",
"Port": int64(22),
}

provisioner.generatedData = generatedData

user, httpAddr, err := provisioner.determineUserAddr()
if err != nil {
test.Error("determineUserAddr failed to determine user and address")
test.Error(err)
}
if user != generatedData["User"] {
test.Error("user was incorrectly determined")
test.Errorf("expected: %s, actual: %s", generatedData["User"], user)
}
expectedHttpAddr := fmt.Sprintf("%s:%d", generatedData["Host"], generatedData["Port"])
if httpAddr != expectedHttpAddr {
test.Error("address was incorrectly determined")
test.Errorf("expected: %s, actual: %s", expectedHttpAddr, httpAddr)
}
}

// test provisioner determineSSHAuth properly determines authentication information
func TestProvisionerDetermineSSHAuth(test *testing.T) {
var provisioner Provisioner

Expand Down
4 changes: 2 additions & 2 deletions provisioner/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (provisioner *Provisioner) uploadFiles(comm packer.Communicator, files []st
}
}

// return most recent error
// the logger displays the relevant debugging information, and this return is useful only in a nil comparable context, and not for specific error types
// return collection of errors
// the logger displays the relevant debugging information, and this return is useful only in a nil comparable context, and not for specific error types UNLESS only one error is returned
return err
}

0 comments on commit 8c72644

Please sign in to comment.