mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
adding new attach test
This commit is contained in:
parent
860d0fd5a6
commit
c5cf72000f
@ -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"))
|
||||
|
10
net/server/internal/attachApp_test.go
Normal file
10
net/server/internal/attachApp_test.go
Normal file
@ -0,0 +1,10 @@
|
||||
package databag
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAttachAccount(t *testing.T) {
|
||||
// attach app to test:pass
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user