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

Commit

Permalink
Merge pull request #41 from stealthrocket/fix-timecraft-run-from-defa…
Browse files Browse the repository at this point in the history
…ult-config

timecraft: fix run from default config
  • Loading branch information
achille-roussel committed Jun 1, 2023
2 parents 7a024d9 + fe2fa21 commit 4807cf0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
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, "")
},
}

0 comments on commit 4807cf0

Please sign in to comment.