Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/kernel/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// kernel is the CLI for the Kernel platform — it deploys apps, manages
// sandboxed browser sessions, handles authentication, and invokes actions.
package main

import (
Expand Down
90 changes: 90 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package cmd

import (
"bytes"
"fmt"
"testing"

"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestIsAuthExempt(t *testing.T) {
Expand Down Expand Up @@ -77,3 +80,90 @@
})
}
}

func TestRootCommandSubcommands(t *testing.T) {
expected := []string{
"app",
"browser-pools",
"browsers",
"create",
"credentials",
"deploy",
"extensions",
"invoke",
"login",
"logout",
"profiles",
"proxies",
}

registered := make(map[string]bool)
for _, sub := range rootCmd.Commands() {
registered[sub.Name()] = true
}

for _, name := range expected {
assert.True(t, registered[name], "expected subcommand %q to be registered on rootCmd", name)
}
}

func TestRootCommandHelpOutput(t *testing.T) {
var buf bytes.Buffer
rootCmd.SetOut(&buf)
rootCmd.SetErr(&buf)
rootCmd.SetArgs([]string{"--help"})

err := rootCmd.Execute()
require.NoError(t, err)

output := buf.String()
assert.Contains(t, output, "kernel")
assert.Contains(t, output, "deploy")
assert.Contains(t, output, "invoke")
assert.Contains(t, output, "browsers")
}

func TestLogLevelToPterm(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"trace", "trace"},
{"debug", "debug"},
{"info", "info"},
{"warn", "warn"},
{"error", "error"},
{"fatal", "fatal"},
{"print", "print"},
{"garbage", "info"},
{"", "info"},
}

for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
got := logLevelToPterm(tt.input)
expected := logLevelToPterm(tt.expected)
assert.Equal(t, expected, got)
})
}
}

func TestIsUsageError(t *testing.T) {
tests := []struct {
name string
err string
expected bool
}{
{"unknown flag", "unknown flag: --foo", true},
{"unknown command", "unknown command \"bogus\"", true},
{"invalid argument", "invalid argument \"x\" for \"--count\"", true},
{"random error", "connection refused", false},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := fmt.Errorf(tt.err)

Check failure on line 165 in cmd/root_test.go

View workflow job for this annotation

GitHub Actions / test

non-constant format string in call to fmt.Errorf
assert.Equal(t, tt.expected, isUsageError(err))
})
}
}
Loading