Skip to content

Commit

Permalink
fixed test conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Bill Hamilton <[email protected]>
  • Loading branch information
pacificcode committed May 10, 2024
1 parent 7ae9456 commit c8895f6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
test_config.json

.DS_Store
bh_test.go
bh_example.go
4 changes: 2 additions & 2 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package server

import (
"fmt"
"io"
"io/ioutil"
"net/http"
)

Expand All @@ -14,7 +14,7 @@ func handleResponse(res *http.Response, err error) ([]byte, *http.Response, erro
return nil, res, err
}

data, err := io.ReadAll(res.Body)
data, err := ioutil.ReadAll(res.Body)

if err != nil {
return nil, res, err
Expand Down
27 changes: 10 additions & 17 deletions server/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func GetSecret(t *testing.T, tss *Server) {
s, err := tss.Secret(id)

if err != nil {
t.Error("calling server.Secret:", err)
t.Errorf("calling server.Secret: err = %+v, config = %+v, secretID = %d", err, tss, id)
return
}

Expand Down Expand Up @@ -231,13 +231,8 @@ func SecretCRUD(t *testing.T, tss *Server) {

// Test read of the deleted secret fails
s, err := tss.Secret(sc.ID)
<<<<<<< HEAD
if s.Active || err != nil {
t.Errorf("deleted secret with id '%d' returned from read. S = %+v", sc.ID, s)
=======
if s != nil && s.Active {
t.Errorf("deleted secret with id '%d' returned from read", sc.ID)
>>>>>>> main
if s != nil && s.Active || err != nil {
t.Errorf("deleted secret with id '%d' returned from read, err = %+v", sc.ID, err)
}
}

Expand Down Expand Up @@ -618,13 +613,8 @@ func SecretCRUDForSSHTemplate(t *testing.T, tss *Server) {

// Test read of the deleted secret fails
s, err := tss.Secret(sc.ID)
<<<<<<< HEAD
if s.Active || err != nil {
t.Errorf("deleted secret with id '%d' returned from read. error = %+v", sc.ID, err)
=======
if s != nil && s.Active {
t.Errorf("deleted secret with id '%d' returned from read", sc.ID)
>>>>>>> main
if s != nil && s.Active || err != nil {
t.Errorf("deleted secret with id '%d' returned from read. err = %+v", sc.ID, err)
}
}

Expand Down Expand Up @@ -729,10 +719,13 @@ func initServer() (*Server, error) {
func initPlatformServer() (*Server, error) {
var config *Configuration

if cj, err := ioutil.ReadFile("../test_config.json"); err == nil {
if cj, err := os.ReadFile("../test_config.json"); err == nil {

Check failure on line 722 in server/secret_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: os.ReadFile
config = new(Configuration)

json.Unmarshal(cj, &config)
err := json.Unmarshal(cj, &config)
if err != nil {
return nil, err
}
} else {
config = &Configuration{
Credentials: UserCredential{
Expand Down
40 changes: 6 additions & 34 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,14 @@ func (s Server) accessResource(method, resource, path, version string, input int
}
}

s.apiVersion = version
req, err := http.NewRequest(method, s.urlFor(resource, path), body)

if err != nil {
log.Printf("[ERROR] creating req: %s /%s/%s: %s", method, resource, path, err)
return nil, err
}

accessToken, err := s.getAccessToken()

if err != nil {
log.Print("[ERROR] error getting accessToken:", err)
return nil, err
}

req, err = http.NewRequest(method, s.urlFor(resource, path), body)

s.apiVersion = version
req, err := http.NewRequest(method, s.urlFor(resource, path), body)
if err != nil {
log.Printf("[ERROR] creating req: %s /%s/%s: %s", method, resource, path, err)
return nil, err
Expand Down Expand Up @@ -186,25 +177,17 @@ func (s Server) searchResources(resource, searchText, field, apiVersion string)
return nil, fmt.Errorf(message)
}

method := "GET"
body := bytes.NewBuffer([]byte{})

s.apiVersion = apiVersion
req, err := http.NewRequest(method, s.urlForSearch(resource, searchText, field), body)

if err != nil {
log.Printf("[ERROR] creating req: %s /%s/%s/%s: %s", method, resource, searchText, field, err)
return nil, err
}

accessToken, err := s.getAccessToken()

if err != nil {
log.Print("[ERROR] error getting accessToken:", err)
return nil, err
}

req, err = http.NewRequest(method, s.urlForSearch(resource, searchText, field), body)
method := "GET"
body := bytes.NewBuffer([]byte{})
s.apiVersion = apiVersion
req, err := http.NewRequest(method, s.urlForSearch(resource, searchText, field), body)

if err != nil {
log.Printf("[ERROR] creating req: %s /%s/%s/%s: %s", method, resource, searchText, field, err)
Expand Down Expand Up @@ -277,18 +260,7 @@ func (s *Server) getAccessToken() (string, error) {
if s.Credentials.Token != "" {
return s.Credentials.Token, nil
}
if s.Credentials.Domain != "" {
values["domain"] = []string{s.Credentials.Domain}
}

s.apiVersion = "v2/"

body := strings.NewReader(values.Encode())
requestUrl := s.urlFor("token", "")
_, _, err := handleResponse(http.Post(requestUrl, "application/x-www-form-urlencoded", body))

response, err := s.checkPlatformDetails()

if err != nil {
log.Print("Error while checking server details:", err)
return "", err
Expand Down

0 comments on commit c8895f6

Please sign in to comment.