Skip to content

Commit

Permalink
add system tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reubenmiller committed Jun 9, 2024
1 parent 4617dfa commit 9fa5959
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/cmd/sessions/login/login.manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ func NewCmdLogin(f *cmdutil.Factory) *CmdLogin {
}

func (n *CmdLogin) FromStdin(format string, args []string) (*c8ysession.CumulocitySession, error) {
return n.FromReader(bufio.NewReader(os.Stdin), format)
session, err := n.FromReader(bufio.NewReader(os.Stdin), format)

if session.SessionUri == "" {
session.SessionUri = "stdin://host"
}
return session, err
}

func (n *CmdLogin) FromEnv() (*c8ysession.CumulocitySession, error) {
Expand Down Expand Up @@ -149,6 +154,10 @@ func (n *CmdLogin) FromEnv() (*c8ysession.CumulocitySession, error) {
}
}

if session.SessionUri == "" {
session.SessionUri = "env://host"
}

return session, nil
}

Expand Down
28 changes: 28 additions & 0 deletions tests/manual/sessions/login/session_login.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/reubenmiller/commander/feat/handle-nested-files/schema.json

tests:
It reads a session from a command:
command: |
env -i PATH="$PATH" C8Y_HOST="$C8Y_HOST" C8Y_USERNAME="$C8Y_USERNAME" C8Y_PASSWORD="$C8Y_PASSWORD" \
c8y sessions login --from-cmd "c8y sessions login --from-env --output-format json --no-banner" --output-format json
exit-code: 0
stdout:
json:
host: r/^.+$
tenant: r/^.+$
version: r/^.+$
username: r/^.+$
token: r/^.+$

It reads a session from environment variables:
command: |
env -i PATH="$PATH" C8Y_HOST="$C8Y_HOST" C8Y_USERNAME="$C8Y_USERNAME" C8Y_PASSWORD="$C8Y_PASSWORD" \
c8y sessions login --from-env --output-format json
exit-code: 0
stdout:
json:
host: r/^.+$
tenant: r/^.+$
version: r/^.+$
username: r/^.+$
token: r/^.+$

0 comments on commit 9fa5959

Please sign in to comment.