Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

timecraft: fix run from default config #41

Merged
merged 1 commit into from
Jun 1, 2023
Merged
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
6 changes: 3 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,18 @@ func value[T any](v T) nullable[T] {
return nullable[T]{value: v, exist: true}
}

func (v *nullable[T]) Value() (T, bool) {
func (v nullable[T]) Value() (T, bool) {
return v.value, v.exist
}

func (v *nullable[T]) MarshalJSON() ([]byte, error) {
func (v nullable[T]) MarshalJSON() ([]byte, error) {
if !v.exist {
return []byte("null"), nil
}
return json.Marshal(v.value)
}

func (v *nullable[T]) MarshalYAML() (any, error) {
func (v nullable[T]) MarshalYAML() (any, error) {
if !v.exist {
return nil, nil
}
Expand Down
1 change: 1 addition & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestTimecraft(t *testing.T) {
t.Run("get", get.run)
t.Run("help", help.run)
t.Run("root", root.run)
t.Run("run", run.run)
t.Run("unknown", unknown.run)
t.Run("version", version.run)
}
Expand Down
33 changes: 33 additions & 0 deletions run_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main_test

import (
"path/filepath"
"testing"

"github.com/stealthrocket/timecraft/internal/assert"
)

var run = tests{
"show the run command help with the short option": func(t *testing.T) {
stdout, stderr, err := timecraft(t, "run", "-h")
assert.OK(t, err)
assert.HasPrefix(t, stdout, "Usage:\ttimecraft run ")
assert.Equal(t, stderr, "")
},

"show the run command help with the long option": func(t *testing.T) {
stdout, stderr, err := timecraft(t, "run", "--help")
assert.OK(t, err)
assert.HasPrefix(t, stdout, "Usage:\ttimecraft run ")
assert.Equal(t, stderr, "")
},

"running with a configuration file which does not exist uses the default location": func(t *testing.T) {
t.Setenv("TIMECRAFTCONFIG", filepath.Join(t.TempDir(), "path", "to", "nowehere.yaml"))

stdout, stderr, err := timecraft(t, "run", "./testdata/go/sleep.wasm", "0")
assert.OK(t, err)
assert.Equal(t, stdout, "sleeping for 0s\n")
assert.NotEqual(t, stderr, "")
},
}
Loading