Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
henrybarreto committed Mar 13, 2024
1 parent a90a093 commit e259d89
Showing 1 changed file with 15 additions and 43 deletions.
58 changes: 15 additions & 43 deletions tests/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package main
import (
"bytes"
"context"
"crypto/rand"
"crypto/rsa"
"fmt"
"io"
"os"
Expand All @@ -14,7 +12,6 @@ import (
"github.com/bramvdbogaerde/go-scp"
"github.com/go-resty/resty/v2"
"github.com/pkg/sftp"
"github.com/shellhub-io/shellhub/pkg/api/requests"
"github.com/shellhub-io/shellhub/pkg/models"
"github.com/shellhub-io/shellhub/tests/environment"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -119,26 +116,25 @@ func TestAgent(t *testing.T) {
NewAgentContainerWithIdentity("test"),
},
run: func(t *testing.T, requester *resty.Request, environment *Environment, device *models.Device) {
config := &ssh.ClientConfig{
User: fmt.Sprintf("%s@%s.%s", LinuxUsername, ShellHubNamespaceName, device.Name),
Auth: []ssh.AuthMethod{
ssh.Password(LinuxPassword),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}
ctx := context.Background()

conn, err := ssh.Dial("tcp", fmt.Sprintf("0.0.0.0:%s", environment.services.GetEnv("SHELLHUB_SSH_PORT")), config)
err := environment.agent.Stop(ctx, nil)
assert.NoError(t, err)

defer conn.Close()

sess, err := conn.NewSession()
err = environment.agent.Start(ctx)
assert.NoError(t, err)

defer sess.Close()
model := models.Device{}

err = sess.Run(`echo -n ""`)
assert.NoError(t, err)
assert.EventuallyWithT(t, func(tt *assert.CollectT) {
resp, err := requester.
SetResult(&model).
Get(fmt.Sprintf("/api/devices/%s", device.UID))
assert.Equal(tt, 200, resp.StatusCode())
assert.NoError(tt, err)

assert.True(tt, model.Online)
}, 30*time.Second, 1*time.Second)
},
},
{
Expand All @@ -156,14 +152,6 @@ func TestAgent(t *testing.T) {
assert.NoError(t, err)

defer conn.Close()

sess, err := conn.NewSession()
assert.NoError(t, err)

defer sess.Close()

err = sess.Run(`echo -n ""`)
assert.NoError(t, err)
},
},
{
Expand All @@ -184,14 +172,6 @@ func TestAgent(t *testing.T) {
assert.NoError(t, err)

defer conn.Close()

sess, err := conn.NewSession()
assert.NoError(t, err)

defer sess.Close()

err = sess.Run(`echo -n ""`)
assert.NoError(t, err)
},
},
{
Expand Down Expand Up @@ -233,14 +213,6 @@ func TestAgent(t *testing.T) {
assert.NoError(t, err)

defer conn.Close()

sess, err := conn.NewSession()
assert.NoError(t, err)

defer sess.Close()

err = sess.Run(`echo -n ""`)
assert.NoError(t, err)
},
},
{
Expand Down Expand Up @@ -459,7 +431,7 @@ func TestAgent(t *testing.T) {
assert.Equal(t, io.EOF, err)
},
},
/*{
{
name: "connection SCP to download file",
options: []NewAgentContainerOption{},
run: func(t *testing.T, requester *resty.Request, environment *Environment, device *models.Device) {
Expand Down Expand Up @@ -492,7 +464,7 @@ func TestAgent(t *testing.T) {
// strconv.Atoi: parsing "scp:": invalid syntax
assert.Equal(t, io.EOF, err)
},
},*/
},
}

env := environment.New(t)
Expand Down

0 comments on commit e259d89

Please sign in to comment.