-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from kool-dev/kub
kool deploy exec + refactoring to Kool Deploy API usage/lib client
- Loading branch information
Showing
12 changed files
with
1,011 additions
and
131 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,11 @@ | ||
package api | ||
|
||
import ( | ||
"kool-dev/kool/environment" | ||
"net/http" | ||
) | ||
|
||
var ( | ||
apiBaseURL string = "https://kool.dev/api" | ||
envStorage = environment.NewEnvStorage() | ||
) | ||
|
||
// SetBaseURL defines the target Kool API URL to be used | ||
// when reaching out endpoints. | ||
func SetBaseURL(url string) { | ||
apiBaseURL = url | ||
} | ||
|
||
func doRequest(request *http.Request) (resp *http.Response, err error) { | ||
var apiToken string = envStorage.Get("KOOL_API_TOKEN") | ||
|
||
if apiToken == "" { | ||
err = ErrMissingToken | ||
return | ||
} | ||
|
||
request.Header.Add("Accept", "application/json") | ||
request.Header.Add("Authorization", "Bearer "+apiToken) | ||
|
||
resp, err = http.DefaultClient.Do(request) | ||
|
||
return | ||
} |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package api | ||
|
||
import ( | ||
"kool-dev/kool/environment" | ||
"testing" | ||
) | ||
|
||
func TestNewDeploy(t *testing.T) { | ||
var tarball = "tarball" | ||
d := NewDeploy(tarball) | ||
|
||
if _, ok := d.env.(*environment.DefaultEnvStorage); !ok { | ||
t.Error("unexpected default environment.EnvStorage") | ||
} | ||
|
||
if _, ok := d.Endpoint.(*DefaultEndpoint); !ok { | ||
t.Error("unexpected default Endpoint") | ||
} | ||
|
||
if tarball != d.tarballPath { | ||
t.Error("failed setting tarballPath") | ||
} | ||
|
||
var id = "id" | ||
d.id = id | ||
|
||
if id != d.GetID() { | ||
t.Error("failed setting id") | ||
} | ||
|
||
var url = "url" | ||
d.Status = &StatusResponse{Status: "success", URL: url} | ||
|
||
if !d.IsSuccessful() { | ||
t.Error("failed asserting success") | ||
} | ||
|
||
if url != d.GetURL() { | ||
t.Error("failed getting URL") | ||
} | ||
|
||
// still in need of testing | ||
// d.FetchLatestStatus() | ||
// d.SendFile() | ||
// d.getPayload() | ||
} |
Oops, something went wrong.