-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75cafee
commit beff581
Showing
9 changed files
with
185 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
package formats_test | ||
|
||
import ( | ||
"slices" | ||
"testing" | ||
|
||
"github.com/drewstinnett/gout/v2/formats" | ||
_ "github.com/drewstinnett/gout/v2/formats/builtin" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBuiltinRegistry(t *testing.T) { | ||
require.Equal( | ||
t, | ||
[]string{"gotemplate", "json", "plain", "xml", "yaml"}, | ||
formats.Names(), | ||
) | ||
got := formats.Names() | ||
formats := []string{"gotemplate", "json", "plain", "xml", "yaml"} | ||
for _, expect := range formats { | ||
if len(got) != len(formats) { | ||
t.Fatalf("expected len to be %v but got %v", len(formats), len(got)) | ||
} | ||
if !slices.Contains(got, expect) { | ||
t.Fatalf("expected %v to be in %v", expect, got) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,22 @@ | ||
package yaml | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type Opts struct { | ||
items map[string]interface{} | ||
} | ||
|
||
func (o *Opts) Set(s string, v interface{}) error { | ||
o.items[s] = v | ||
return nil | ||
} | ||
|
||
func (o *Opts) Get(s string) (interface{}, error) { | ||
if _, ok := o.items[s]; ok { | ||
return nil, fmt.Errorf("Could not find config item '%s'", s) | ||
} | ||
return o.items[s], nil | ||
} | ||
|
||
func TestYAMLFormatter(t *testing.T) { | ||
f := Formatter{} | ||
got, err := f.Format(struct { | ||
Foo string | ||
}{ | ||
Foo: "bar", | ||
}) | ||
require.NoError(t, err) | ||
require.IsType(t, []byte{}, got) | ||
require.Equal(t, string("foo: bar\n"), string(got)) | ||
} | ||
|
||
/* | ||
func TestYAMLFormatterWithOpts(t *testing.T) { | ||
f := Formatter{} | ||
got, err := f.FormatWithContext(context.Background(), []struct { | ||
Foo string | ||
}{ | ||
{Foo: "bar"}, | ||
{Foo: "baz"}, | ||
}) | ||
require.NoError(t, err) | ||
require.IsType(t, []byte{}, got) | ||
require.Equal(t, string("- foo: bar\n- foo: baz\n"), string(got)) | ||
} | ||
*/ | ||
|
||
/* | ||
func TestYAMLFormatterWithOpts(t *testing.T) { | ||
f := Formatter{} | ||
opts := config.FormatterOpts{ | ||
"indent": 10, // TODO: This does not work yet...y?? | ||
"header": true, | ||
if err != nil { | ||
t.Fatalf("got unexpected error: %v", err) | ||
} | ||
expect := "foo: bar\n" | ||
gotS := string(got) | ||
if expect != gotS { | ||
t.Fatalf("expected %v but got %v", expect, got) | ||
} | ||
got, err := f.FormatWithOpts([]struct { | ||
Foo string | ||
}{ | ||
{Foo: "bar"}, | ||
{Foo: "baz"}, | ||
}, opts) | ||
require.NoError(t, err) | ||
require.IsType(t, []byte{}, got) | ||
require.Equal(t, string("---\n- foo: bar\n- foo: baz\n"), string(got)) | ||
} | ||
*/ |
Oops, something went wrong.