adding new attach test

This commit is contained in:
Roland Osborne 2022-01-16 23:00:08 -08:00
parent 860d0fd5a6
commit c5cf72000f
3 changed files with 42 additions and 2 deletions

View File

@ -7,7 +7,7 @@ import (
"encoding/json"
)
func TestAccount(t *testing.T) {
func TestAddAccount(t *testing.T) {
// acquire new token for creating accounts
auth := base64.StdEncoding.EncodeToString([]byte("admin:pass"))

View File

@ -0,0 +1,10 @@
package databag
import (
"testing"
)
func TestAttachAccount(t *testing.T) {
// attach app to test:pass
}

View File

@ -18,7 +18,8 @@ func TestMain(m *testing.M) {
Claim();
SetConfig();
GetConfig();
token := SetToken()
SetAccount(token)
m.Run()
}
@ -88,3 +89,32 @@ func GetConfig() {
panic("failed to set account storage");
}
}
func SetToken() string {
auth := base64.StdEncoding.EncodeToString([]byte("admin:pass"))
r := httptest.NewRequest("POST", "/admin/accounts", nil)
r.Header.Add("Authorization","Basic " + auth)
w := httptest.NewRecorder()
AddNodeAccount(w, r)
resp := w.Result()
dec := json.NewDecoder(resp.Body)
var token string
dec.Decode(&token)
if resp.StatusCode != 200 {
panic("failed to create token")
}
return token
}
func SetAccount(token string) {
auth := base64.StdEncoding.EncodeToString([]byte("test:pass"))
r := httptest.NewRequest("GET", "/account/profile", nil)
r.Header.Add("Credentials","Basic " + auth)
r.Header.Add("Authorization","Bearer " + token)
w := httptest.NewRecorder()
AddAccount(w, r)
resp := w.Result()
if resp.StatusCode != 200 {
panic("failed to create account")
}
}